From ba1e8d8eb62c1e565985afb89a31d213509564b1 Mon Sep 17 00:00:00 2001 From: Marijn Doeve Date: Wed, 8 Jul 2026 10:00:37 +0200 Subject: [PATCH] ci: auto-trigger main CI when tagging a Dependabot commit (#188) * ci: auto-trigger main CI run when tagging a Dependabot commit Dependabot auto-merges use GITHUB_TOKEN which GitHub intentionally does not re-trigger other workflows on. This means tagging those commits immediately fails the verify-prior-run gate. Instead of hard-failing, trigger ci.yml on main and wait for it to succeed before proceeding with the deploy. Only triggers once; detects and surfaces failures from the triggered run. Bumps actions permission from read to write to allow workflow dispatch. * ci: address CodeRabbit feedback on verify-prior-run job Reduce max_attempts from 40 to 30 so worst-case runtime (15m) fits within the 20-minute job timeout with margin. Trigger the fallback workflow run on the tag ref instead of main so the dispatched run's head_sha matches the tagged commit SHA that the polling loop is checking for. --- .github/workflows/ci.yml | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 38870df..88c4bc7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -166,7 +166,7 @@ jobs: timeout-minutes: 20 if: startsWith(github.ref, 'refs/tags/') permissions: - actions: read + actions: write steps: - name: Wait for and verify successful CI run on this commit env: @@ -174,6 +174,8 @@ jobs: run: | max_attempts=30 attempt=0 + triggered=false + while [[ $attempt -lt $max_attempts ]]; do attempt=$((attempt + 1)) @@ -191,12 +193,32 @@ jobs: --jq "[.workflow_runs[] | select(.id != ${{ github.run_id }}) | select(.status == \"in_progress\" or .status == \"queued\" or .status == \"waiting\" or .status == \"requested\" or .status == \"pending\")] | length") if [[ "$in_progress_count" -gt 0 ]]; then - echo "CI still in progress (attempt $attempt/$max_attempts), waiting 30s..." + echo "CI in progress (attempt $attempt/$max_attempts), waiting 30s..." sleep 30 - else - echo "::error::No prior successful CI run found for ${{ github.sha }}. Only tag commits that have passed CI on main." + continue + fi + + if [[ "$triggered" == "false" ]]; then + echo "No prior CI run found for ${{ github.sha }}. Triggering CI on ${{ github.ref }}..." + gh workflow run ci.yml --repo "${{ github.repository }}" --ref "${{ github.ref }}" + triggered=true + echo "Triggered. Waiting 20s for run to register..." + sleep 20 + continue + fi + + failed_conclusion=$(gh api \ + "repos/${{ github.repository }}/actions/workflows/ci.yml/runs?head_sha=${{ github.sha }}&per_page=10" \ + --jq "[.workflow_runs[] | select(.id != ${{ github.run_id }}) | select(.status == \"completed\") | select(.conclusion != \"success\")] | first | .conclusion // empty" \ + --raw-output) + + if [[ -n "$failed_conclusion" ]]; then + echo "::error::Triggered CI run on main failed with conclusion: $failed_conclusion. Fix the issue before re-tagging." exit 1 fi + + echo "Waiting for triggered run to register (attempt $attempt/$max_attempts)..." + sleep 20 done echo "::error::Timed out waiting for CI run to complete for ${{ github.sha }}."