Skip to content

Commit a74223c

Browse files
committed
fix(ci): handle existing upstream sync conflict PR
1 parent 533d375 commit a74223c

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

.github/workflows/sync-upstream.yml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,18 @@ jobs:
230230
git commit -m "WIP: Merge upstream $TAG (has conflicts)" --no-verify || true
231231
git push origin "$BRANCH" --force
232232
233+
EXISTING_PR=$(gh pr list \
234+
--repo "${GITHUB_REPOSITORY}" \
235+
--head "$BRANCH" \
236+
--base main \
237+
--state open \
238+
--json url \
239+
--jq '.[0].url // empty')
240+
if [ -n "$EXISTING_PR" ]; then
241+
echo "::notice::Conflict PR already exists: $EXISTING_PR"
242+
exit 0
243+
fi
244+
233245
# GitHub's GraphQL createPullRequest replica lags behind the REST
234246
# branches endpoint. Even after the branch is visible via REST, the
235247
# GraphQL mutation can return: "No commits between main and BRANCH".
@@ -258,16 +270,15 @@ jobs:
258270
# longer replication lag against new branches (>30s observed).
259271
PR_TITLE="Sync upstream $TAG (merge conflicts)"
260272
for attempt in 1 2 3 4 5 6; do
261-
HTTP_CODE=$(jq -n --arg t "$PR_TITLE" --arg b "$PR_BODY" --arg h "$BRANCH" \
273+
if PR_URL=$(jq -n --arg t "$PR_TITLE" --arg b "$PR_BODY" --arg h "$BRANCH" \
262274
'{title:$t, body:$b, head:$h, base:"main"}' | \
263275
gh api -X POST "repos/${GITHUB_REPOSITORY}/pulls" \
264276
--input - \
265-
--silent 2>&1)
266-
if [ $? -eq 0 ]; then
267-
echo "PR created successfully on attempt $attempt"
277+
--jq '.html_url' 2>&1); then
278+
echo "PR created successfully on attempt $attempt: $PR_URL"
268279
exit 0
269280
fi
270-
echo "PR creation failed (attempt $attempt): $HTTP_CODE"
281+
echo "PR creation failed (attempt $attempt): $PR_URL"
271282
echo "Retrying in 5s..."
272283
sleep 5
273284
done

0 commit comments

Comments
 (0)