|
10 | 10 | NODE_VERSION: '22' |
11 | 11 |
|
12 | 12 | jobs: |
| 13 | + verify-ci: |
| 14 | + name: Verify exact-SHA CI before release |
| 15 | + runs-on: ubuntu-latest |
| 16 | + if: github.ref == 'refs/heads/main' |
| 17 | + timeout-minutes: 31 |
| 18 | + permissions: |
| 19 | + actions: read |
| 20 | + contents: read |
| 21 | + |
| 22 | + steps: |
| 23 | + - name: Wait for successful CI on this commit |
| 24 | + shell: bash |
| 25 | + env: |
| 26 | + GH_TOKEN: ${{ github.token }} |
| 27 | + run: | |
| 28 | + set -euo pipefail |
| 29 | + deadline=$((SECONDS + 1800)) |
| 30 | + ci_workflow_id=$(gh api "repos/${GITHUB_REPOSITORY}/actions/workflows" \ |
| 31 | + --jq '[.workflows[] | select(.path == ".github/workflows/ci.yml")][0].id // empty') |
| 32 | + if [[ -z "$ci_workflow_id" ]]; then |
| 33 | + echo "Could not resolve this repository's CI workflow; release publication is blocked." |
| 34 | + exit 1 |
| 35 | + fi |
| 36 | +
|
| 37 | + while (( SECONDS < deadline )); do |
| 38 | + run=$(gh api "repos/${GITHUB_REPOSITORY}/actions/runs" \ |
| 39 | + -f head_sha="$GITHUB_SHA" \ |
| 40 | + -F per_page=100 \ |
| 41 | + --jq "[.workflow_runs[] | select(.workflow_id == $ci_workflow_id and .head_sha == \"$GITHUB_SHA\" and .head_branch == \"main\" and .event == \"push\")] | sort_by(.created_at) | last // empty") |
| 42 | +
|
| 43 | + if [[ -z "$run" ]]; then |
| 44 | + echo "Waiting for the CI run for this exact commit to appear." |
| 45 | + else |
| 46 | + status=$(jq -r '.status' <<<"$run") |
| 47 | + conclusion=$(jq -r '.conclusion // ""' <<<"$run") |
| 48 | + echo "Exact-SHA CI status: $status; conclusion: ${conclusion:-pending}." |
| 49 | +
|
| 50 | + if [[ "$status" == "completed" ]]; then |
| 51 | + if [[ "$conclusion" == "success" ]]; then |
| 52 | + exit 0 |
| 53 | + fi |
| 54 | +
|
| 55 | + echo "Exact-SHA CI did not succeed; release publication is blocked." |
| 56 | + exit 1 |
| 57 | + fi |
| 58 | + fi |
| 59 | +
|
| 60 | + sleep 15 |
| 61 | + done |
| 62 | +
|
| 63 | + echo "Timed out waiting for successful exact-SHA CI; release publication is blocked." |
| 64 | + exit 1 |
| 65 | +
|
13 | 66 | build: |
14 | 67 | name: Build and Test |
15 | 68 | runs-on: ubuntu-latest |
|
91 | 144 |
|
92 | 145 | publish-nuget: |
93 | 146 | name: Publish to NuGet |
94 | | - needs: build |
| 147 | + needs: [build, verify-ci] |
95 | 148 | runs-on: ubuntu-latest |
96 | 149 | if: github.ref == 'refs/heads/main' |
97 | 150 |
|
|
0 commit comments