@@ -27,13 +27,21 @@ jobs:
2727 - name : Sync with ${{ matrix.branch }}
2828 run : |
2929 TARGET_BRANCH="${{ matrix.branch }}"
30- git checkout $TARGET_BRANCH
31- git pull origin $TARGET_BRANCH || echo "No changes to pull for $TARGET_BRANCH"
32- git reset --hard origin/main
33- git merge --squash origin/main || echo "No changes to merge for $TARGET_BRANCH"
34- if [ -n "$(git status --porcelain)" ]; then
35- git commit -m "Squash merge changes from main into $TARGET_BRANCH"
36- git push origin $TARGET_BRANCH || echo "Failed to push $TARGET_BRANCH"
30+ git fetch --all --prune
31+ # Checkout the target branch and ensure it's up-to-date with origin
32+ git checkout ${TARGET_BRANCH}
33+ git pull --no-rebase origin ${TARGET_BRANCH} || true
34+
35+ # Merge origin/main into the target branch (automatic merge).
36+ # Use --no-ff to create an explicit merge commit when required and
37+ # --no-edit to avoid interactive editor for the merge message.
38+ if git merge --no-ff --no-edit origin/main; then
39+ git push origin ${TARGET_BRANCH}
40+ else
41+ # On merge conflict, abort and push a backup branch so nothing is lost.
42+ git merge --abort || true
43+ BACKUP_BRANCH="backup/${TARGET_BRANCH}-merge-failed-$(date +%s)"
44+ git push origin HEAD:refs/heads/${BACKUP_BRANCH}
45+ echo "Merge failed. Backup pushed to ${BACKUP_BRANCH}. Exiting with failure."
46+ exit 1
3747 fi
38- git reset --hard main
39- git push origin $TARGET_BRANCH --force || echo "Failed to force push $TARGET_BRANCH"
0 commit comments