Skip to content

Commit 5be29c8

Browse files
authored
Update sync-merge.yml
1 parent 74b24c2 commit 5be29c8

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

.github/workflows/sync-merge.yml

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Sync Shared Files to Datapack Branches
33
on:
44
push:
55
branches:
6-
- sync # Runs only when pushing to the sync branch
6+
- sync # Runs when pushing to the "sync" branch
77
workflow_dispatch: # Allows manual execution from GitHub
88

99
jobs:
@@ -22,25 +22,32 @@ jobs:
2222
git config --global user.name "github-actions"
2323
git config --global user.email "github-actions@github.com"
2424
25-
- name: Fetch Branch List & Merge Sync
25+
- name: Fetch all branches and sync
2626
run: |
27-
git fetch origin # Ensure all branches are visible
27+
git fetch --all # Ensures all branches are fetched from origin
2828
29-
# Get all branches EXCEPT `main` and `sync`
29+
# List of all remote branches excluding `main` and `sync`
3030
BRANCHES=$(git branch -r | grep -Eo "origin/[^/]+" | sed 's/origin\///' | grep -vE '^(main|sync)$')
3131
32+
# Loop through each branch
3233
for branch in $BRANCHES; do
3334
echo "Merging sync into $branch..."
34-
35-
# Checkout each branch
35+
36+
# Checkout the branch
3637
git checkout $branch
37-
38-
# Pull latest changes for the current branch
39-
git pull origin $branch
40-
38+
39+
# Pull the latest changes from the remote branch
40+
git pull origin $branch --rebase # Using rebase to avoid merge commits
41+
4142
# Merge the sync branch into the current branch
42-
git merge --no-edit origin/sync || echo "No new changes to merge"
43-
44-
# Push the updated branch
43+
git merge --no-edit origin/sync || echo "No new changes to merge or merge conflict detected"
44+
45+
# If there's a conflict, handle it automatically (you can also choose to exit early if conflicts are too complex)
46+
if [ $? -ne 0 ]; then
47+
echo "Merge conflict detected, skipping the branch: $branch"
48+
continue
49+
fi
50+
51+
# Push the updated branch back to origin
4552
git push origin $branch
4653
done

0 commit comments

Comments
 (0)