Skip to content

Commit cf395e9

Browse files
committed
ci: improve back-merge handling in release workflow
- Add proper error handling for merge conflicts - Create PR automatically if conflicts occur - Use proper git fetch and checkout commands - Add GH_TOKEN for PR creation
1 parent 7c8ed46 commit cf395e9

1 file changed

Lines changed: 42 additions & 11 deletions

File tree

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

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,49 @@ jobs:
147147
148148
# Step 11: Back-merge to develop
149149
- name: Back-merge to develop
150+
env:
151+
GH_TOKEN: ${{ secrets.GH_PAT || secrets.GITHUB_TOKEN }}
150152
run: |
151-
# Fetch latest develop
152-
git fetch origin develop:develop
153-
153+
# Fetch latest branches
154+
git fetch origin develop:refs/remotes/origin/develop
155+
git fetch origin main:refs/remotes/origin/main
156+
154157
# Checkout develop
155-
git checkout develop
156-
157-
# Merge main
158-
git merge main -m "chore: back-merge main to develop after v${{ steps.get-version.outputs.version }} release"
159-
160-
# Push to develop
161-
git push origin develop
158+
git checkout -B develop origin/develop
159+
160+
# Try to merge main
161+
if git merge origin/main -m "chore: back-merge main to develop after v${{ steps.get-version.outputs.version }} release" --no-edit; then
162+
echo "✅ Merge successful"
163+
# Push to develop
164+
git push origin develop
165+
else
166+
echo "⚠️ Merge conflicts detected. Creating a PR for manual resolution."
167+
168+
# Create a branch for the back-merge
169+
BACKMERGE_BRANCH="backmerge/v${{ steps.get-version.outputs.version }}-to-develop"
170+
git checkout -b "$BACKMERGE_BRANCH"
171+
172+
# Stage any resolved files (in case of partial auto-resolution)
173+
git add -A
174+
175+
# Commit with conflicts markers if any
176+
git commit -m "chore: back-merge main to develop after v${{ steps.get-version.outputs.version }} release (with conflicts)" || true
177+
178+
# Push the branch
179+
git push origin "$BACKMERGE_BRANCH"
180+
181+
# Create a PR for manual resolution
182+
gh pr create \
183+
--title "Back-merge: v${{ steps.get-version.outputs.version }} from main to develop" \
184+
--body "This PR back-merges the changes from the v${{ steps.get-version.outputs.version }} release into develop.
185+
186+
⚠️ **Merge conflicts were detected and need manual resolution.**
187+
188+
Please review and resolve any conflicts before merging." \
189+
--base develop \
190+
--head "$BACKMERGE_BRANCH" \
191+
--repo ${{ github.repository }} || echo "PR creation failed, please create manually"
192+
fi
162193
163194
# Step 12: Summary
164195
- name: Release Summary
@@ -168,7 +199,7 @@ jobs:
168199
echo "- **Version**: ${{ steps.get-version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
169200
echo "- **npm Published**: ${{ steps.npm-publish.outputs.published }}" >> $GITHUB_STEP_SUMMARY
170201
echo "- **GitHub Release**: ✅" >> $GITHUB_STEP_SUMMARY
171-
echo "- **Back-merged to develop**: " >> $GITHUB_STEP_SUMMARY
202+
echo "- **Back-merge Status**: Check workflow logs" >> $GITHUB_STEP_SUMMARY
172203
echo "" >> $GITHUB_STEP_SUMMARY
173204
echo "### 📋 Release Assets" >> $GITHUB_STEP_SUMMARY
174205
echo '```' >> $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)