-
-
Notifications
You must be signed in to change notification settings - Fork 1
feat(cli): improve ci self package times by allowing build tree and env caching #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mikonse
wants to merge
1
commit into
main
Choose a base branch
from
milo/faster-ci-self-packaging
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| .git | ||
| target |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Pre-baked build environment for the package_ourself CI job: debmagic's base | ||
| # tooling plus this repo's Build-Depends, so the in-container | ||
| # `apt-get build-dep` only tops up archive drift. Rebuilt whenever | ||
| # debian/control, this file, or the weekly freshness bucket changes | ||
| # (see the tag key in .github/workflows/ci.yaml). | ||
| ARG BASE_IMAGE | ||
| FROM ${BASE_IMAGE} | ||
| WORKDIR /src | ||
| COPY debian /src/debian | ||
| RUN apt-get update \ | ||
| && apt-get install -y dpkg-dev python3 \ | ||
| && apt-get -y build-dep . \ | ||
| && rm -rf /var/lib/apt/lists/* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -137,25 +137,55 @@ jobs: | |
| # integration / self packaging tests | ||
| package_ourself: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| # Push of the pre-built CI image is additionally gated to main below. | ||
| packages: write | ||
| steps: | ||
| - uses: actions/checkout@v5 | ||
| - name: Set up Python | ||
| uses: actions/setup-python@v6 | ||
| with: | ||
| python-version: "3.12" | ||
| - name: Install uv | ||
| uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 | ||
| with: | ||
| enable-cache: true | ||
| - uses: Swatinem/rust-cache@v2 | ||
| with: | ||
| save-if: ${{ github.ref == 'refs/heads/main' }} | ||
| - name: Install the project | ||
| run: uv sync --locked --all-extras --dev | ||
| - name: Install debmagic (cli) | ||
| run: uv pip install packages/debmagic | ||
| - name: Cache the debmagic build tree | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: /tmp/debmagic | ||
| key: debmagic-build-${{ hashFiles('Cargo.lock', 'debian/changelog', 'debian/control', 'debian/rules') }} | ||
| restore-keys: debmagic-build- | ||
| - name: Prune stale build trees from the restored cache | ||
| run: | | ||
| mkdir -p /tmp/debmagic | ||
| current="$(head -n1 debian/changelog | sed 's/^\([^ ]*\) (\([^)]*\)).*/\1-\2/')" | ||
| find /tmp/debmagic -mindepth 1 -maxdepth 1 -type d ! -name "$current" -exec rm -rf {} + | ||
| - name: Resolve CI image tag | ||
| id: image | ||
| run: | | ||
| codename="$(sed -n 's/^[^(]*([^)]*) \([^;]*\);.*/\1/p' debian/changelog | head -n1)" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we could use the proper changelog reading tool dpkg-parsechangelog |
||
| key="$(cat debian/control .github/ci/Dockerfile.build-deps | sha256sum | cut -c1-12)-$(date -u +%G-W%V)" | ||
| echo "tag=ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/debmagic-ci:${codename}-${key}" >> "$GITHUB_OUTPUT" | ||
| echo "codename=${codename}" >> "$GITHUB_OUTPUT" | ||
| - name: Pull or build the CI image | ||
| run: | | ||
| if ! docker pull "${{ steps.image.outputs.tag }}"; then | ||
| docker build \ | ||
| --build-arg "BASE_IMAGE=docker.io/debian:${{ steps.image.outputs.codename }}" \ | ||
| --tag "${{ steps.image.outputs.tag }}" \ | ||
| --file .github/ci/Dockerfile.build-deps \ | ||
| . | ||
| echo "image_built=true" >> "$GITHUB_ENV" | ||
| fi | ||
| - name: Run Debmagic build on ourself | ||
| run: uv run debmagic build binary --driver=docker | ||
| run: | | ||
| cargo run --locked -p debmagic -- build binary \ | ||
| --driver=docker \ | ||
| --persistent \ | ||
| --incremental \ | ||
| --driver-docker-base-image="${{ steps.image.outputs.tag }}" | ||
| - name: Push the CI image | ||
| if: github.ref == 'refs/heads/main' && env.image_built == 'true' | ||
| run: | | ||
| echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io --username "${{ github.actor }}" --password-stdin | ||
| docker push "${{ steps.image.outputs.tag }}" | ||
|
|
||
| # TODO: integration tests currently don't work in the CI since they require running apt source on debian trixie -> CI runs on ubuntu | ||
| # integration-tests: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uuh