Skip to content

Commit a067764

Browse files
committed
[ci] post alpha branch sync
1 parent e22d2dc commit a067764

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# This workflow automatically syncs merged PRs from 4.10.x to next branch
2+
name: Sync 4.10.x to next
3+
4+
on:
5+
pull_request:
6+
types: [closed]
7+
branches: [4.10.x]
8+
9+
env:
10+
TARGET_BRANCH: next
11+
12+
jobs:
13+
sync:
14+
if: github.event.pull_request.merged == true
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: write
18+
pull-requests: write
19+
steps:
20+
- name: Checkout repository
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
token: ${{ secrets.GITHUB_TOKEN }}
25+
26+
- name: Configure Git
27+
run: |
28+
git config user.name "github-actions[bot]"
29+
git config user.email "github-actions[bot]@users.noreply.github.com"
30+
- name: Create sync branch and cherry-pick commits
31+
run: |
32+
SYNC_BRANCH="sync-to-${{ env.TARGET_BRANCH }}-${{ github.run_id }}"
33+
PR_NUMBER=${{ github.event.pull_request.number }}
34+
35+
# Fetch all branches including remote branches
36+
git fetch --all
37+
38+
# Check if target branch exists
39+
if ! git ls-remote --exit-code origin "${{ env.TARGET_BRANCH }}" > /dev/null 2>&1; then
40+
echo "::error::Target branch '${{ env.TARGET_BRANCH }}' does not exist"
41+
exit 1
42+
fi
43+
44+
# Create sync branch from target branch
45+
git checkout -b "$SYNC_BRANCH" "origin/${{ env.TARGET_BRANCH }}"
46+
47+
# Get PR commits (excluding merge commits)
48+
COMMITS=$(gh pr view $PR_NUMBER --json commits --jq '.commits[].oid' | tac)
49+
50+
# Cherry-pick each commit
51+
echo "Cherry-picking commits..."
52+
for commit in $COMMITS; do
53+
if git show --no-patch --format=%p "$commit" | grep -q " "; then
54+
echo "Skipping merge commit: $commit"
55+
continue
56+
fi
57+
echo "Cherry-picking: $commit"
58+
if ! git cherry-pick "$commit"; then
59+
echo "::error::Cherry-pick failed for $commit. Manual intervention required."
60+
exit 1
61+
fi
62+
done
63+
64+
# Push sync branch
65+
git push origin "$SYNC_BRANCH"
66+
67+
# Create PR
68+
gh pr create \
69+
--base "${{ env.TARGET_BRANCH }}" \
70+
--head "$SYNC_BRANCH" \
71+
--title "[Sync][\`${{ env.TARGET_BRANCH }}\` <- \`${{ github.event.pull_request.base.ref }}\`][#${{ github.event.pull_request.number }}]: ${{ github.event.pull_request.title }}" \
72+
--body "🤖 **Auto-sync from ${{ github.event.pull_request.base.ref }}**
73+
This PR automatically syncs the changes from #${{ github.event.pull_request.number }} to the \`${{ env.TARGET_BRANCH }}\` branch.
74+
75+
**Original PR:** ${{ github.event.pull_request.html_url }}
76+
**Author:** @${{ github.event.pull_request.user.login }}
77+
**Workflow:** ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
78+
79+
---
80+
81+
${{ github.event.pull_request.body }}" \
82+
--reviewer "${{ github.event.pull_request.user.login }}"
83+
env:
84+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)