From 7c92d4b359827c0f539df3ea053c35e7bd2b7e43 Mon Sep 17 00:00:00 2001 From: Lucas Rayan Date: Sun, 15 Nov 2026 22:47:18 -0300 Subject: [PATCH] ci: build and test each tree once The release ran per ref, so main and a tag pushed together both planned before any image existed and built everything twice; it also re-ran the whole CI that the pull request had already passed on the same commit, and the PR CI built the images a third time. Now: one release queue (the tag waits for main and only re-points tags), the release skips CI when the pull request already passed for this commit, and the PR CI no longer builds images (the release builds once per input hash and smoke-tests before publishing). Co-Authored-By: Claude Opus 5.5 --- .gitea/workflows/ci.yml | 19 ++----------------- .gitea/workflows/release.yml | 26 +++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index aee765a..8d27d51 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -80,20 +80,5 @@ jobs: export PATH="$PATH:$(go env GOPATH)/bin" govulncheck ./... - image: - name: Docker images (build and smoke test) - if: ${{ gitea.event_name == 'pull_request' }} - runs-on: linux-arm64 - steps: - - uses: actions/checkout@v7 - - name: Build hub - run: docker build --target hub -t "urutau-ci:${{ gitea.run_id }}" . - - name: Build probe - run: docker build --target probe -t "urutau-probe-ci:${{ gitea.run_id }}" . - - name: Smoke test (hub) - run: scripts/smoke-image.sh "urutau-ci:${{ gitea.run_id }}" - - name: Smoke test (probe, under 15 MB) - run: scripts/smoke-probe.sh "urutau-probe-ci:${{ gitea.run_id }}" - - name: Clean up - if: always() - run: docker rmi -f "urutau-ci:${{ gitea.run_id }}" "urutau-probe-ci:${{ gitea.run_id }}" >/dev/null 2>&1 || true + # No image build here: the release builds each image once per input hash, + # natively per architecture, and smoke-tests it before publishing any tag. diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml index da12cef..519354c 100644 --- a/.gitea/workflows/release.yml +++ b/.gitea/workflows/release.yml @@ -12,8 +12,11 @@ on: tags: ['v*'] workflow_dispatch: +# One queue for main and tags: a tag pushed together with main waits for the +# main run, then finds the images already published and only re-points tags. +# (A per-ref group let both runs plan at once, see nothing, and build twice.) concurrency: - group: release-${{ gitea.ref }} + group: release cancel-in-progress: false env: @@ -29,6 +32,7 @@ jobs: outputs: inputs: ${{ steps.plan.outputs.inputs }} reuse: ${{ steps.plan.outputs.reuse }} + tested: ${{ steps.tested.outputs.tested }} image: ${{ steps.plan.outputs.image }} probe_image: ${{ steps.plan.outputs.probe_image }} steps: @@ -56,10 +60,25 @@ jobs: echo "reuse=$reuse" >> "$GITHUB_OUTPUT" echo "image=$REGISTRY/$ns" >> "$GITHUB_OUTPUT" echo "probe_image=$REGISTRY/$ns-probe" >> "$GITHUB_OUTPUT" + # The pull request already ran the whole CI on this exact commit (the + # merge is a fast-forward): do not run the same tests again here. + - id: tested + env: + REPO: ${{ gitea.repository }} + SHA: ${{ gitea.sha }} + # The job token reads this repository's runs; on any error the answer + # is false and the CI simply runs (never skips tests by mistake). + TOKEN: ${{ gitea.token }} + run: | + tested=$(curl -fsS -H "Authorization: token $TOKEN" "https://$REGISTRY/api/v1/repos/$REPO/actions/runs?limit=50" \ + | jq -r --arg sha "$SHA" '[.workflow_runs[] | select(.head_sha == $sha and (.path | startswith("ci.yml")) and .conclusion == "success")] | length > 0' 2>/dev/null) || tested=false + [ "$tested" = true ] || tested=false + echo "CI already passed for $SHA: $tested" + echo "tested=$tested" >> "$GITHUB_OUTPUT" ci: needs: plan - if: ${{ needs.plan.outputs.reuse != 'true' }} + if: ${{ needs.plan.outputs.reuse != 'true' && needs.plan.outputs.tested != 'true' }} uses: ./.gitea/workflows/ci.yml # Each architecture of each image is built on a native runner (no QEMU) and @@ -67,7 +86,8 @@ jobs: build: name: Build ${{ matrix.target }} image (${{ matrix.arch }}) needs: [plan, ci] - if: ${{ needs.plan.outputs.reuse != 'true' }} + # ci is skipped (not failed) when the pull request already tested this commit. + if: ${{ !cancelled() && needs.plan.result == 'success' && needs.plan.outputs.reuse != 'true' && (needs.ci.result == 'success' || needs.ci.result == 'skipped') }} runs-on: ${{ matrix.runner }} strategy: fail-fast: false