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 }}."