Automate sync PR merges (#490)
Wait for sync PR checks to register and pass, then squash-merge the PR pinned to the pushed head SHA. Co-authored-by: jmservera <jmservera@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Juan Manuel Servera committed
Jun 15, 2026 at 19:01 UTC
0ccf75319ec80615acb3339441f8f1814516f31a
1 file changed
+23
-3
.github/workflows/sync-publish-to-main.yml
+23
-3
@@ -84,9 +84,9 @@ jobs:
84
git push -f origin "$SYNC_BRANCH"
85
86
# Create or update PR
87
- EXISTING_PR=$(gh pr list --head "$SYNC_BRANCH" --base main --json number --jq '.[0].number // empty')
88
- if [ -n "$EXISTING_PR" ]; then
89
- echo "Updated existing PR #${EXISTING_PR}"
87
+ PR_NUMBER=$(gh pr list --head "$SYNC_BRANCH" --base main --json number --jq '.[0].number // empty')
88
+ if [ -n "$PR_NUMBER" ]; then
89
+ echo "Updated existing PR #${PR_NUMBER}"
90
else
91
gh pr create \
92
--base main \
@@ -111,4 +111,24 @@ jobs:
111
112
Safe to merge — contains only generated data, no code changes." \
113
--label "squad"
114
+ PR_NUMBER=$(gh pr list --head "$SYNC_BRANCH" --base main --json number --jq '.[0].number')
115
fi
116
+
117
+ HEAD_SHA=$(git rev-parse HEAD)
118
+ CHECK_COUNT=0
119
+ for _ in $(seq 1 30); do
120
+ CHECK_COUNT=$(gh pr checks "$PR_NUMBER" --json name --jq 'length')
121
+ if [ "$CHECK_COUNT" -gt 0 ]; then
122
+ break
123
+ fi
124
+ echo "Waiting for PR #${PR_NUMBER} checks to register..."
125
+ sleep 10
126
+ done
127
+
128
+ if [ "$CHECK_COUNT" -eq 0 ]; then
129
+ echo "::error::No status checks registered for PR #${PR_NUMBER}; refusing to merge without validation."
130
+ exit 1
131
+ fi
132
+
133
+ gh pr checks "$PR_NUMBER" --watch --fail-fast
134
+ gh pr merge "$PR_NUMBER" --squash --match-head-commit "$HEAD_SHA"