Skip to content

Commit 1ca8ac1

Browse files
committed
Fix sync-dependencies infinite PR loop
The previous workflow tried fast-forward master into dependencies and fell back to a deps-sync branch + PR on failure. Under squash merges (used for both dependencies -> master and deps-sync -> dependencies), the branches diverge permanently after the first sync, so FF never succeeds and every push to master creates a fresh deps-sync PR. Open the PR with head=master directly and gate creation on a tree diff against dependencies. When trees already match (typical after a dependencies -> master merge) no PR is opened. This breaks the loop and drops the deps-sync branch from the design.
1 parent 3b07603 commit 1ca8ac1

2 files changed

Lines changed: 10 additions & 29 deletions

File tree

.github/workflows/ci-deps.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ name: CI (deps)
33
on:
44
workflow_dispatch:
55
push:
6-
branches:
7-
- dependencies
8-
- deps-sync
6+
branches: [dependencies]
97
pull_request:
108
branches: [dependencies]
119

.github/workflows/sync-dependencies.yml

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,43 +22,26 @@ jobs:
2222
fetch-depth: 0
2323
token: ${{ secrets.RELEASE_TOKEN }}
2424

25-
- name: Configure git
26-
run: |
27-
git config user.name "nerjs"
28-
git config user.email "nerjs.stap@gmail.com"
29-
30-
- name: Sync or prepare deps-sync
31-
id: sync
25+
- name: Ensure dependencies branch and open PR if drift
26+
env:
27+
GH_TOKEN: ${{ secrets.RELEASE_TOKEN }}
3228
run: |
3329
set -euo pipefail
3430
if ! git ls-remote --heads origin dependencies | grep -q dependencies; then
3531
git push origin master:dependencies
36-
echo "result=created" >> "$GITHUB_OUTPUT"
3732
exit 0
3833
fi
39-
git fetch origin dependencies:dependencies
40-
git checkout dependencies
41-
if git merge --ff-only origin/master; then
42-
git push origin dependencies
43-
echo "result=ff" >> "$GITHUB_OUTPUT"
34+
git fetch origin dependencies
35+
if git diff --quiet origin/master origin/dependencies; then
36+
echo "master and dependencies trees match; nothing to sync"
4437
exit 0
4538
fi
46-
git checkout -B deps-sync origin/master
47-
git push --force-with-lease origin deps-sync
48-
echo "result=needs-pr" >> "$GITHUB_OUTPUT"
49-
50-
- name: Ensure PR deps-sync -> dependencies
51-
if: steps.sync.outputs.result == 'needs-pr'
52-
env:
53-
GH_TOKEN: ${{ secrets.RELEASE_TOKEN }}
54-
run: |
55-
set -euo pipefail
56-
existing=$(gh pr list --base dependencies --head deps-sync --state open --json number --jq '.[0].number // empty')
39+
existing=$(gh pr list --base dependencies --head master --state open --json number --jq '.[0].number // empty')
5740
if [ -z "$existing" ]; then
5841
gh pr create \
59-
--base dependencies --head deps-sync \
42+
--base dependencies --head master \
6043
--title "Sync master into dependencies" \
61-
--body "Auto-generated by sync-dependencies.yml. Resolve conflicts on deps-sync, then merge into dependencies."
44+
--body "Auto-generated by sync-dependencies.yml. Merge to bring master changes into dependencies."
6245
else
6346
echo "PR #$existing already open"
6447
fi

0 commit comments

Comments
 (0)