From b49da065d41c1034afbb4c9614c4d5c4188980cc Mon Sep 17 00:00:00 2001 From: Xenolphthalein <21215869+Xenolphthalein@users.noreply.github.com> Date: Sat, 14 Nov 2026 08:41:45 +0100 Subject: [PATCH] ci: each variant is built once per content of image/ and the tested build is what a tag publishes; pushes run on main and tags only --- .github/workflows/image.yml | 41 ++++++++++++++++++++++++++++++------- README.md | 8 +++++--- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/.github/workflows/image.yml b/.github/workflows/image.yml index c5b7eb2..d20128e 100644 --- a/.github/workflows/image.yml +++ b/.github/workflows/image.yml @@ -1,13 +1,15 @@ # SPDX-License-Identifier: Unlicense -# Every push: the image built on amd64 and arm64, its tools checked and its scripts' tests run in it. -# A tag (YYYY.MM.DD, or YYYY.MM.DD.N for a second one that day) publishes both as one multi-arch -# image, ghcr.io/overpressure/builder:TAG, and a release naming its digest, with each variant's -# packages and versions. +# Every pull request, push to main and tag: the image on amd64 and arm64, its tools checked and its +# scripts' tests run in it. Each variant is built once per content of image/: the build is kept as +# ghcr.io/overpressure/builder:ci--, and a later run (main after the merge, the tag) +# pulls it instead of building it again. A tag (YYYY.MM.DD, or YYYY.MM.DD.N for a second one that day) +# publishes the tested variants as one multi-arch image, ghcr.io/overpressure/builder:TAG, and a release +# naming its digest, with each variant's packages and versions. name: Image on: push: - branches: ["**"] + branches: [main] tags: ["[0-9][0-9][0-9][0-9].[0-9][0-9].[0-9][0-9]*"] pull_request: workflow_dispatch: @@ -39,7 +41,26 @@ jobs: packages: write # a tag's variant steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - name: The variant's content + id: content + run: echo "candidate=$IMAGE:ci-$(git rev-parse HEAD:image)-${{ matrix.arch }}" >> "$GITHUB_OUTPUT" + - name: The registry + id: registry + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository + run: | + echo "${{ github.token }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin + echo "push=true" >> "$GITHUB_OUTPUT" + - name: An earlier build of the same content + id: earlier + env: + CANDIDATE: ${{ steps.content.outputs.candidate }} + run: | + if docker pull "$CANDIDATE"; then + docker tag "$CANDIDATE" builder:test + echo "found=true" >> "$GITHUB_OUTPUT" + fi - name: The image + if: steps.earlier.outputs.found != 'true' run: docker build --pull -t builder:test image - name: Its tools run: | @@ -68,10 +89,16 @@ jobs: python3 -m unittest -v' - name: Its packages run: docker run --rm --entrypoint cat builder:test /usr/share/overpressure-packages.txt > packages-${{ matrix.arch }}.txt + - name: Kept for the next run + if: steps.earlier.outputs.found != 'true' && steps.registry.outputs.push == 'true' + env: + CANDIDATE: ${{ steps.content.outputs.candidate }} + run: | + docker tag builder:test "$CANDIDATE" + docker push "$CANDIDATE" - name: The variant if: startsWith(github.ref, 'refs/tags/') run: | - echo "${{ github.token }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin docker tag builder:test "$IMAGE:$GITHUB_REF_NAME-${{ matrix.arch }}" docker push "$IMAGE:$GITHUB_REF_NAME-${{ matrix.arch }}" - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 @@ -114,7 +141,7 @@ jobs: echo "$IMAGE:$GITHUB_REF_NAME@$DIGEST" echo '```' echo - echo "Built from ${GITHUB_SHA}; the packages of each variant are attached." + echo "Built from image/ as of ${GITHUB_SHA}, tested and published as it was built; the packages of each variant are attached." } > notes.md gh release create "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" --verify-tag \ --title "$GITHUB_REF_NAME" --notes-file notes.md packages-amd64.txt packages-arm64.txt diff --git a/README.md b/README.md index abe5b2b..f3b25e7 100644 --- a/README.md +++ b/README.md @@ -52,9 +52,11 @@ consumers pin on purpose. ## Publishing -Every push builds both variants, checks their tools and runs the scripts' tests in them -([image.yml](.github/workflows/image.yml)). A tag `YYYY.MM.DD` (or `YYYY.MM.DD.N`) publishes them as one -multi-arch image under that tag, with a release that names its digest and lists each variant's packages. +Every pull request, push to `main` and tag checks both variants' tools and runs the scripts' tests in them +([image.yml](.github/workflows/image.yml)). Each variant is built once per content of `image/` and kept as +`ghcr.io/overpressure/builder:ci--`; later runs pull it instead of building it again. A tag +`YYYY.MM.DD` (or `YYYY.MM.DD.N`) publishes the tested variants as one multi-arch image under that tag, with a +release that names its digest and lists each variant's packages. `main` changes only by pull request. Published images are kept: an old pin keeps working. ```sh