|
53 | 53 | - |
54 | 54 | name: Auto-approve all bot-go-openapi PRs |
55 | 55 | run: gh pr review --approve "$PR_URL" |
| 56 | + - |
| 57 | + name: Wait for all workflow runs to complete |
| 58 | + run: | |
| 59 | + PR_NUMBER=$(echo "$PR_URL" | grep -oP '\d+$') |
| 60 | + echo "Waiting for all workflow runs to complete on PR #${PR_NUMBER}..." |
| 61 | +
|
| 62 | + # Get the PR's head SHA |
| 63 | + HEAD_SHA=$(gh pr view "$PR_NUMBER" --json headRefOid --jq '.headRefOid') |
| 64 | + echo "Head SHA: ${HEAD_SHA}" |
| 65 | +
|
| 66 | + MAX_WAIT=600 # 10 minutes max wait |
| 67 | + ELAPSED=0 |
| 68 | + SLEEP_INTERVAL=10 |
| 69 | +
|
| 70 | + while [ $ELAPSED -lt $MAX_WAIT ]; do |
| 71 | + # Get all workflow runs for this SHA using the GitHub API |
| 72 | + RUNS=$(gh api "/repos/${{ github.repository }}/actions/runs?head_sha=${HEAD_SHA}&per_page=100" --jq '.workflow_runs') |
| 73 | +
|
| 74 | + # Count how many are still in progress, queued, or waiting |
| 75 | + IN_PROGRESS=$(echo "$RUNS" | jq '[.[] | select(.status == "in_progress" or .status == "queued" or .status == "waiting")] | length') |
| 76 | +
|
| 77 | + if [ "$IN_PROGRESS" -eq 0 ]; then |
| 78 | + echo "::notice::All workflow runs completed for SHA ${HEAD_SHA}" |
| 79 | + TOTAL_RUNS=$(echo "$RUNS" | jq 'length') |
| 80 | + echo "Total workflow runs: ${TOTAL_RUNS}" |
| 81 | + break |
| 82 | + fi |
| 83 | +
|
| 84 | + # Show which workflows are still running |
| 85 | + RUNNING=$(echo "$RUNS" | jq -r '.[] | select(.status == "in_progress" or .status == "queued" or .status == "waiting") | .name' | tr '\n' ', ' | sed 's/,$//') |
| 86 | + echo "Still waiting for ${IN_PROGRESS} workflow run(s): ${RUNNING}" |
| 87 | +
|
| 88 | + sleep $SLEEP_INTERVAL |
| 89 | + ELAPSED=$((ELAPSED + SLEEP_INTERVAL)) |
| 90 | + done |
| 91 | +
|
| 92 | + if [ $ELAPSED -ge $MAX_WAIT ]; then |
| 93 | + echo "::warning::Timeout waiting for all workflow runs to complete, proceeding anyway" |
| 94 | + fi |
56 | 95 | - |
57 | 96 | name: Auto-merge bot-go-openapi PRs |
58 | 97 | run: gh pr merge --auto --rebase "$PR_URL" |
0 commit comments