Merge head into child branch #19
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: Merge head into child branch | |
on: | |
workflow_dispatch: | |
inputs: | |
head: | |
description: 'Branch to merge from' | |
required: true | |
type: choice | |
options: | |
- stable | |
- minor-next | |
base: | |
description: 'Branch to merge into' | |
required: true | |
type: choice | |
options: | |
- minor-next | |
- major-next | |
jobs: | |
merge: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Check if head and base are the same | |
id: check-branches | |
run: | | |
if [ "${{ github.event.inputs.head }}" == "${{ github.event.inputs.base }}" ]; then | |
echo "::error::Head and base branches cannot be the same" | |
exit 1 | |
fi | |
- name: Fetch all branches | |
run: git fetch --all | |
- name: Checkout base branch | |
run: git checkout ${{ github.event.inputs.base }} | |
- name: Set Git config | |
run: | | |
git config user.name github-actions | |
git config user.email [email protected] | |
- name: Attempt to merge head into base | |
id: merge | |
run: | | |
git merge --no-ff --no-commit ${{ github.event.inputs.head }} --allow-unrelated-histories || echo "Merge conflict detected" > conflict.txt | |
- name: Check for merge conflicts | |
id: check-conflict | |
run: | | |
if [ -f conflict.txt ]; then | |
echo "::error::Merge conflict detected" | |
exit 1 | |
fi | |
- name: Commit the merge | |
if: steps.check-conflict.outcome == 'success' | |
run: | | |
git commit -m "Merge '${{ github.event.inputs.head }}' into ${{ github.event.inputs.base }}" | |
git push origin ${{ github.event.inputs.base }} |