Skip to content

Commit 43bf198

Browse files
committed
fix: add a delay before the contributors workflow sets auto-merge
Problem: when auto-merge is set, the PR merges as soon as the required check status is okay, meaning that the next job that uploads test coverage always fails (branch is deleted). This is not blocking but kind of untidy. Solution: introduced a loop that waits for all PR jobs to complete before auto-merge is enabled. Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
1 parent 56a1aea commit 43bf198

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

.github/workflows/contributors.yml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,36 @@ jobs:
8181
name: Auto-approve PR
8282
run: gh pr review --approve "$PR_URL"
8383
-
84-
# TODO: should wait for all workflows to complete before merging
84+
name: Wait for all workflow runs to complete
85+
run: |
86+
PR_NUMBER=$(echo "$PR_URL" | grep -oP '\d+$')
87+
echo "Waiting for all checks to complete on PR #${PR_NUMBER}..."
88+
89+
MAX_WAIT=600 # 10 minutes max wait
90+
ELAPSED=0
91+
SLEEP_INTERVAL=10
92+
93+
while [ $ELAPSED -lt $MAX_WAIT ]; do
94+
# Get all workflow runs for this PR's head SHA
95+
PR_DATA=$(gh pr view "$PR_NUMBER" --json headRefOid,statusCheckRollup)
96+
HEAD_SHA=$(echo "$PR_DATA" | jq -r '.headRefOid')
97+
98+
# Check if any workflows are still in progress
99+
IN_PROGRESS=$(echo "$PR_DATA" | jq -r '.statusCheckRollup[] | select(.status == "IN_PROGRESS" or .status == "QUEUED" or .status == "PENDING") | .name' | wc -l)
100+
101+
if [ "$IN_PROGRESS" -eq 0 ]; then
102+
echo "::notice::All workflow runs completed for SHA ${HEAD_SHA}"
103+
break
104+
fi
105+
106+
echo "Still waiting for $IN_PROGRESS check(s) to complete..."
107+
sleep $SLEEP_INTERVAL
108+
ELAPSED=$((ELAPSED + SLEEP_INTERVAL))
109+
done
110+
111+
if [ $ELAPSED -ge $MAX_WAIT ]; then
112+
echo "::warning::Timeout waiting for all checks to complete, proceeding anyway"
113+
fi
114+
-
85115
name: Auto-merge PR
86116
run: gh pr merge --auto --rebase "$PR_URL"

0 commit comments

Comments
 (0)