Skip to content

Commit aa0c042

Browse files
committed
ci: improve back-merge strategy from main to develop
Update the back-merge process in CI to use the "theirs" merge strategy, automatically resolving conflicts by favoring changes from the main branch during merges into develop. Add a fallback force-resolution approach that resets develop and force-pushes a merge result when automatic conflict resolution still fails, improving merge reliability and reducing manual intervention. This ensures smoother synchronization after releases and minimizes blocked workflows.
1 parent 13b5721 commit aa0c042

1 file changed

Lines changed: 27 additions & 29 deletions

File tree

.github/workflows/ci-semantic-release.yml

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -191,38 +191,36 @@ jobs:
191191
# Checkout develop
192192
git checkout -B develop origin/develop
193193
194-
# Try to merge main
195-
if git merge origin/main -m "chore: back-merge main to develop after v${{ steps.get-version.outputs.version }} release" --no-edit; then
196-
echo "✅ Merge successful"
194+
# Try to merge main with strategy to automatically resolve conflicts
195+
# Using -X theirs to always take changes from main when conflicts occur
196+
echo "🔄 Attempting to merge main into develop..."
197+
198+
if git merge origin/main -X theirs -m "chore: back-merge main to develop after v${{ steps.get-version.outputs.version }} release" --no-edit; then
199+
echo "✅ Merge successful (conflicts auto-resolved using main's version)"
197200
# Push to develop
198201
git push origin develop
202+
echo "✅ Successfully pushed merged changes to develop"
199203
else
200-
echo "⚠️ Merge conflicts detected. Creating a PR for manual resolution."
201-
202-
# Create a branch for the back-merge
203-
BACKMERGE_BRANCH="backmerge/v${{ steps.get-version.outputs.version }}-to-develop"
204-
git checkout -b "$BACKMERGE_BRANCH"
205-
206-
# Stage any resolved files (in case of partial auto-resolution)
207-
git add -A
208-
209-
# Commit with conflicts markers if any
210-
git commit -m "chore: back-merge main to develop after v${{ steps.get-version.outputs.version }} release (with conflicts)" || true
211-
212-
# Push the branch
213-
git push origin "$BACKMERGE_BRANCH"
214-
215-
# Create a PR for manual resolution
216-
gh pr create \
217-
--title "Back-merge: v${{ steps.get-version.outputs.version }} from main to develop" \
218-
--body "This PR back-merges the changes from the v${{ steps.get-version.outputs.version }} release into develop.
219-
220-
⚠️ **Merge conflicts were detected and need manual resolution.**
221-
222-
Please review and resolve any conflicts before merging." \
223-
--base develop \
224-
--head "$BACKMERGE_BRANCH" \
225-
--repo ${{ github.repository }} || echo "PR creation failed, please create manually"
204+
# This should rarely happen with -X theirs, but handle it just in case
205+
echo "⚠️ Unexpected merge failure even with auto-resolution. Attempting force resolution..."
206+
207+
# Reset to develop and try a different approach
208+
git reset --hard origin/develop
209+
210+
# Create a temporary branch from main
211+
git checkout -B temp-main origin/main
212+
213+
# Merge develop into this branch (reverse merge) and take all from main
214+
git merge origin/develop --strategy=ours -m "chore: back-merge main to develop after v${{ steps.get-version.outputs.version }} release (force resolved)"
215+
216+
# Now force push this as the new develop
217+
git branch -f develop HEAD
218+
git checkout develop
219+
220+
# Push the resolved develop branch
221+
git push origin develop --force-with-lease
222+
223+
echo "✅ Force-resolved conflicts by taking all changes from main"
226224
fi
227225
228226
# Step 12: Summary

0 commit comments

Comments
 (0)