This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Auto Merge Individual Commits from Release to Development | |
on: | |
push: | |
branches: | |
- release | |
jobs: | |
merge-individual-commits: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # Fetch all history for merge operations | |
- name: Configure Git | |
run: | | |
git config --global user.name 'GitHub Action' | |
git config --global user.email '[email protected]' | |
- name: Fetch and checkout development | |
run: | | |
git fetch origin | |
git checkout development | |
git pull | |
- name: Get list of commits from release not in development | |
id: commits | |
run: | | |
COMMITS=$(git log origin/development..origin/release --format="%H") | |
echo "::set-output name=commits_list::$COMMITS" | |
- name: Attempt to merge each commit individually | |
run: | | |
for COMMIT_HASH in ${{ steps.commits.outputs.commits_list }} | |
do | |
git cherry-pick $COMMIT_HASH | |
if [ $? -ne 0 ]; then # Check if cherry-pick failed | |
echo "Conflicts detected for commit $COMMIT_HASH. Attempting to resolve and create a pull request." | |
git cherry-pick --abort | |
BRANCH_NAME="conflict-${COMMIT_HASH}" | |
git checkout -b $BRANCH_NAME | |
git cherry-pick $COMMIT_HASH | |
if [ $? -ne 0 ]; then # Check again if cherry-pick fails | |
git status | |
# Assuming you will manually resolve conflicts or add further automation here | |
echo "Manually resolve conflicts now or update this script to handle conflict resolution." | |
git cherry-pick --continue | |
fi | |
git commit -m "Resolve conflicts for commit $COMMIT_HASH" | |
git push origin $BRANCH_NAME | |
gh pr create --base development --head $BRANCH_NAME --title "Resolve Conflict for Commit $COMMIT_HASH" --body "This PR is created to resolve conflicts for commit $COMMIT_HASH." | |
git checkout development | |
else | |
git push origin development | |
fi | |
done | |
- name: Install GitHub CLI | |
uses: actions/setup-go@v2 | |
with: | |
go-version: '^1.18' | |
- name: GitHub CLI login | |
run: echo "${{secrets.GITHUB_TOKEN}}" | gh auth login --with-token |