Skip to content

Commit 1b4a826

Browse files
fix(ci): guard squash branch deletion when promotion PR is open (#931)
sync-main-to-testing fires on every push to main, including normal PR merges. The cleanup-squash-branch job was unconditionally deleting auto/promote-testing-to-main regardless of whether a promotion PR was open, leaving the PR pointing at a deleted ref. GitHub then returns UNKNOWN mergeability permanently, requiring manual close + re-trigger. Guard with a gh pr list check: skip deletion if any open PR targets the squash branch. Assisted-by: Claude Sonnet 4.5 via pi Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent f144d36 commit 1b4a826

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

.github/workflows/sync-main-to-testing.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ jobs:
3737
env:
3838
GH_TOKEN: ${{ github.token }}
3939
run: |
40+
# Guard: do not delete the squash branch while a promotion PR is open.
41+
# Every push to main triggers this workflow — including normal PR merges.
42+
# Deleting the branch with an open PR leaves the PR pointing at a ghost
43+
# ref, causing permanent UNKNOWN mergeability that requires manual recovery.
44+
OPEN=$(gh pr list \
45+
--repo "${{ github.repository }}" \
46+
--head auto/promote-testing-to-main \
47+
--state open \
48+
--json number \
49+
--jq 'length')
50+
if [[ "$OPEN" -gt 0 ]]; then
51+
echo "Open promotion PR exists — skipping branch deletion"
52+
exit 0
53+
fi
4054
gh api repos/${{ github.repository }}/git/refs/heads/auto/promote-testing-to-main \
4155
-X DELETE 2>/dev/null \
4256
&& echo "✅ Deleted squash promotion branch" \

0 commit comments

Comments
 (0)