-
Notifications
You must be signed in to change notification settings - Fork 513
68 lines (57 loc) · 1.95 KB
/
sync-main-to-dev.yml
File metadata and controls
68 lines (57 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
name: Sync Main to Dev
on:
push:
branches:
- main
jobs:
sync-commits:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Sync main commits to dev
run: |
# Fetch all branches
git fetch origin dev:dev
# Switch to dev branch
git checkout dev
# Find commits on main that are not on dev
COMMITS_TO_CHERRY_PICK=$(git rev-list --reverse main ^dev)
if [ -z "$COMMITS_TO_CHERRY_PICK" ]; then
echo "No commits to sync from main to dev"
exit 0
fi
echo "Found commits to cherry-pick:"
echo "$COMMITS_TO_CHERRY_PICK"
# Cherry-pick each commit
SUCCESS=true
for COMMIT in $COMMITS_TO_CHERRY_PICK; do
echo "Cherry-picking commit: $COMMIT"
if ! git cherry-pick $COMMIT; then
echo "Cherry-pick failed for commit $COMMIT"
# Try to continue with --allow-empty in case it's already applied
if ! git cherry-pick --continue --allow-empty 2>/dev/null; then
echo "Failed to cherry-pick $COMMIT, aborting"
git cherry-pick --abort
SUCCESS=false
break
fi
fi
done
if [ "$SUCCESS" = true ]; then
# Push changes to dev
git push origin dev
echo "Successfully synced commits from main to dev"
else
echo "Failed to sync some commits"
exit 1
fi