1- name : 🔄 Sync Patches [disabled]
1+ name : 🔄 Sync stable → main
22
33on :
4- # Disabled to stop automatic PRs syncing stable/*.x back to main.
4+ push :
5+ branches :
6+ - stable
57 workflow_dispatch :
68
79permissions :
@@ -10,9 +12,9 @@ permissions:
1012
1113jobs :
1214 sync-to-main :
13- # Short-circuit to fully disable the workflow.
14- if : ${{ false }}
1515 runs-on : ubuntu-latest
16+ # Skip release commits (chore(release): ... [skip ci]) to avoid noisy no-op PRs
17+ if : " !contains(github.event.head_commit.message, '[skip ci]') || github.event_name == 'workflow_dispatch'"
1618
1719 steps :
1820 - name : Generate token
@@ -27,31 +29,73 @@ jobs:
2729 fetch-depth : 0
2830 token : ${{ steps.generate_token.outputs.token }}
2931
30- - name : Create sync PR
32+ - name : Sync stable into main
3133 env :
3234 GH_TOKEN : ${{ steps.generate_token.outputs.token }}
3335 run : |
3436 git config user.name "github-actions[bot]"
3537 git config user.email "github-actions[bot]@users.noreply.github.com"
3638
37- # Create patch branch
38- PATCH_BRANCH="sync-patch-${{ github.sha }}"
39- git checkout -b "$PATCH_BRANCH" origin/main
39+ SYNC_BRANCH="sync/stable-to-main-$(date +%Y%m%d-%H%M%S)"
40+ git checkout -b "$SYNC_BRANCH" origin/main
41+
42+ # Merge stable into the branch
43+ if git merge origin/stable --no-edit -m "chore: merge stable into main"; then
44+ # Check if there are actually new commits to sync
45+ if git diff --quiet origin/main; then
46+ echo "No changes to sync — stable and main are already in sync."
47+ exit 0
48+ fi
49+
50+ git push origin "$SYNC_BRANCH"
51+
52+ # Check for existing open sync PR
53+ EXISTING=$(gh pr list --base main --head "$SYNC_BRANCH" --state open --json number -q '.[0].number' 2>/dev/null || true)
54+ if [ -n "$EXISTING" ]; then
55+ echo "Sync PR #$EXISTING already exists."
56+ exit 0
57+ fi
4058
41- # Cherry-pick the commit
42- if git cherry-pick "${{ github.sha }}"; then
43- git push origin "$PATCH_BRANCH"
44-
45- # Create PR
4659 gh pr create \
4760 --base main \
48- --head "$PATCH_BRANCH" \
49- --title "🔄 Sync: ${{ github.event.head_commit.message }}" \
50- --body "Auto-sync patch from ${{ github.ref_name }}
51-
52- Commit: ${{ github.sha }}
53-
54- ---
55- _This PR was automatically created to sync a patch to main._" \
61+ --head "$SYNC_BRANCH" \
62+ --title "🔄 Sync stable → main" \
63+ --body "$(cat <<'EOF'
64+ ## Summary
65+ Merges latest stable patches into main to keep branches in sync.
66+
67+ This ensures `@next` prereleases stay ahead of `@latest` releases.
68+
69+ ---
70+ _Auto-created by sync-patches workflow._
71+ EOF
72+ )" \
5673 --label "patch-sync"
74+
75+ echo "✅ Created sync PR"
76+ else
77+ echo "⚠️ Merge conflict — creating PR with conflict markers for manual resolution."
78+
79+ # Abort the failed merge and try again with conflict markers
80+ git merge --abort
81+ git merge origin/stable --no-edit --no-commit || true
82+ git add -A
83+ git commit -m "chore: merge stable into main (conflicts need resolution)"
84+ git push origin "$SYNC_BRANCH"
85+
86+ gh pr create \
87+ --base main \
88+ --head "$SYNC_BRANCH" \
89+ --title "🔄 Sync stable → main (conflicts)" \
90+ --body "$(cat <<'EOF'
91+ ## Summary
92+ Merges latest stable patches into main. **Has merge conflicts that need manual resolution.**
93+
94+ ---
95+ _Auto-created by sync-patches workflow._
96+ EOF
97+ )" \
98+ --label "patch-sync"
99+
100+ echo "⚠️ Created sync PR with conflicts"
57101 fi
0 commit comments