Skip to content

Commit ca6a0ce

Browse files
authored
Fix race condition in remove-backport-pending (#2967)
Made-with: Cursor
1 parent 57c70c2 commit ca6a0ce

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

.github/workflows/backport.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
env:
2121
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2222
PR_TITLE: ${{ github.event.pull_request.title }}
23+
PR_NUMBER: ${{ github.event.pull_request.number }}
2324
REPO: ${{ github.repository }}
2425
run: |
2526
# Backport PR titles follow the pattern: [9.2] Original title (#1234)
@@ -29,6 +30,7 @@ jobs:
2930
exit 0
3031
fi
3132
echo "Original PR: #$ORIGINAL_PR"
33+
echo "Just-merged backport PR: #$PR_NUMBER"
3234
3335
HAS_LABEL=$(gh pr view "$ORIGINAL_PR" --repo "$REPO" --json labels \
3436
--jq '[.labels[].name] | if index("backport-pending") then "true" else "false" end')
@@ -37,9 +39,10 @@ jobs:
3739
exit 0
3840
fi
3941
42+
# Count open backport PRs, excluding the just-merged PR (API eventual consistency).
4043
OPEN_BACKPORTS=$(gh pr list --repo "$REPO" --label backport --state open \
4144
--json number,title \
42-
--jq "[.[] | select(.title | test(\"\\\\(#${ORIGINAL_PR}\\\\)\"))] | length")
45+
--jq "[.[] | select(.number != ${PR_NUMBER}) | select(.title | test(\"\\\\(#${ORIGINAL_PR}\\\\)\"))] | length")
4346
echo "Open backport PRs remaining: $OPEN_BACKPORTS"
4447
4548
if [ "$OPEN_BACKPORTS" -eq 0 ]; then

0 commit comments

Comments
 (0)