diff --git a/.github/workflows/contributors.yml b/.github/workflows/contributors.yml index 1fc8f53..668efbf 100644 --- a/.github/workflows/contributors.yml +++ b/.github/workflows/contributors.yml @@ -81,6 +81,36 @@ jobs: name: Auto-approve PR run: gh pr review --approve "$PR_URL" - - # TODO: should wait for all workflows to complete before merging + name: Wait for all workflow runs to complete + run: | + PR_NUMBER=$(echo "$PR_URL" | grep -oP '\d+$') + echo "Waiting for all checks to complete on PR #${PR_NUMBER}..." + + MAX_WAIT=600 # 10 minutes max wait + ELAPSED=0 + SLEEP_INTERVAL=10 + + while [ $ELAPSED -lt $MAX_WAIT ]; do + # Get all workflow runs for this PR's head SHA + PR_DATA=$(gh pr view "$PR_NUMBER" --json headRefOid,statusCheckRollup) + HEAD_SHA=$(echo "$PR_DATA" | jq -r '.headRefOid') + + # Check if any workflows are still in progress + IN_PROGRESS=$(echo "$PR_DATA" | jq -r '.statusCheckRollup[] | select(.status == "IN_PROGRESS" or .status == "QUEUED" or .status == "PENDING") | .name' | wc -l) + + if [ "$IN_PROGRESS" -eq 0 ]; then + echo "::notice::All workflow runs completed for SHA ${HEAD_SHA}" + break + fi + + echo "Still waiting for $IN_PROGRESS check(s) to complete..." + sleep $SLEEP_INTERVAL + ELAPSED=$((ELAPSED + SLEEP_INTERVAL)) + done + + if [ $ELAPSED -ge $MAX_WAIT ]; then + echo "::warning::Timeout waiting for all checks to complete, proceeding anyway" + fi + - name: Auto-merge PR run: gh pr merge --auto --rebase "$PR_URL"