fix(ci): handle merge race in js-autofix poll loop (#65231)
When the bot PR auto-merges, main moves — which the poll loop detects as 'main moved' and tries to close the PR. But the PR is already merged, so gh pr close fails with an error. Fix: when main moves, re-check PR state before closing. If it's already MERGED, exit cleanly. Also make gh pr close non-fatal (|| true) as a belt-and-suspenders guard against the same race on the other close paths.
This commit is contained in:
parent
75f45a0692
commit
0c1adb4877
1 changed files with 8 additions and 3 deletions
11
.github/workflows/js-autofix.yml
vendored
11
.github/workflows/js-autofix.yml
vendored
|
|
@ -207,12 +207,17 @@ jobs:
|
|||
exit 0
|
||||
fi
|
||||
|
||||
# If main moved, close the PR — the next workflow run re-applies
|
||||
# on the current state.
|
||||
# If main moved, the PR may have already merged (which moves
|
||||
# main) or another commit landed. Re-check state first.
|
||||
CURRENT_SHA=$(gh api "repos/${{ github.repository }}/branches/main" --jq '.commit.sha')
|
||||
if [ "$CURRENT_SHA" != "$START_SHA" ]; then
|
||||
STATE=$(gh pr view "$PR_NUM" --json state --jq '.state')
|
||||
if [ "$STATE" = "MERGED" ]; then
|
||||
echo "PR #$PR_NUM merged (main moved to $CURRENT_SHA)."
|
||||
exit 0
|
||||
fi
|
||||
echo "Main moved ($START_SHA → $CURRENT_SHA). Closing stale PR."
|
||||
gh pr close "$PR_NUM" --delete-branch
|
||||
gh pr close "$PR_NUM" --delete-branch || true
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue