|
| 1 | +--- |
| 2 | +name: CI Gate |
| 3 | + |
| 4 | +# This workflow waits for all other checks to complete. |
| 5 | +# Use "All Checks Pass" as the single required status check in branch protection. |
| 6 | +# This solves the issue where workflows with path filters don't always run. |
| 7 | + |
| 8 | +# yamllint disable-line rule:truthy |
| 9 | +on: |
| 10 | + pull_request: |
| 11 | + push: |
| 12 | + branches: [main] |
| 13 | + |
| 14 | +permissions: |
| 15 | + checks: read |
| 16 | + pull-requests: read |
| 17 | + |
| 18 | +jobs: |
| 19 | + gate: |
| 20 | + name: All Checks Pass |
| 21 | + runs-on: ubuntu-latest |
| 22 | + steps: |
| 23 | + - name: Wait for all checks to complete |
| 24 | + env: |
| 25 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 26 | + REPO: ${{ github.repository }} |
| 27 | + SHA: ${{ github.event.pull_request.head.sha || github.sha }} |
| 28 | + CURRENT_JOB: All Checks Pass |
| 29 | + run: | |
| 30 | + echo "Waiting for all checks on $SHA to complete..." |
| 31 | +
|
| 32 | + while true; do |
| 33 | + # Get all check runs for this commit |
| 34 | + CHECKS=$(gh api "repos/$REPO/commits/$SHA/check-runs" \ |
| 35 | + --jq '.check_runs | map({name: .name, status: .status, conclusion: .conclusion})') |
| 36 | +
|
| 37 | + # Count checks still in progress (excluding this job) |
| 38 | + IN_PROGRESS=$(echo "$CHECKS" | jq --arg current "$CURRENT_JOB" \ |
| 39 | + '[.[] | select(.name != $current and .status != "completed")] | length') |
| 40 | +
|
| 41 | + # Check for any failures (excluding this job) |
| 42 | + # Conclusion must be success, skipped, or neutral to pass |
| 43 | + FAILED=$(echo "$CHECKS" | jq --arg current "$CURRENT_JOB" ' |
| 44 | + [.[] | select( |
| 45 | + .name != $current and |
| 46 | + .status == "completed" and |
| 47 | + .conclusion != "success" and |
| 48 | + .conclusion != "skipped" and |
| 49 | + .conclusion != "neutral" |
| 50 | + )] | length') |
| 51 | +
|
| 52 | + echo "In progress: $IN_PROGRESS, Failed: $FAILED" |
| 53 | +
|
| 54 | + if [ "$FAILED" -gt 0 ]; then |
| 55 | + echo "::error::One or more checks failed" |
| 56 | + echo "$CHECKS" | jq --arg current "$CURRENT_JOB" ' |
| 57 | + .[] | select( |
| 58 | + .name != $current and |
| 59 | + .status == "completed" and |
| 60 | + .conclusion != "success" and |
| 61 | + .conclusion != "skipped" and |
| 62 | + .conclusion != "neutral" |
| 63 | + )' |
| 64 | + exit 1 |
| 65 | + fi |
| 66 | +
|
| 67 | + if [ "$IN_PROGRESS" -eq 0 ]; then |
| 68 | + echo "All checks completed successfully!" |
| 69 | + break |
| 70 | + fi |
| 71 | +
|
| 72 | + echo "Waiting 30 seconds..." |
| 73 | + sleep 30 |
| 74 | + done |
0 commit comments