We a two branches: main and prod. Both branches are used as refrence to build a website. Now I wanted a workflow that reacts to a certain commit message to be triggered. It should then auto merge main into prod.
I tried a lot. I dont even know if thats the right approach. I get Errors for merge conflicts but if I run the command locally with the same settings it won’t work.
name: Merge main into prod
on:
push:
branches:
- main
jobs:
merge-main-into-prod:
name: Merge main into prod
runs-on: ubuntu-latest
steps:
- name: Checkout main branch
uses: actions/checkout@v3
with:
ref: main
- name: Set up Git user
run: |
git config user.name "GitHub Action"
git config user.email "[email protected]"
- name: Get last commit message
id: get_message
run: |
last_commit_message=$(git log -1 --pretty=format:%s)
echo "Last commit message: $last_commit_message"
echo "message=$last_commit_message" >> $GITHUB_ENV
- name: Check commit message pattern
id: check_pattern
run: |
if echo "${{ env.message }}" | grep -qE '^Merge pull request #[0-9]+ from *****/cms/Changelog/index$'; then
echo "Pattern matched"
echo "match=true" >> $GITHUB_ENV
else
echo "Pattern did not match"
echo "match=false" >> $GITHUB_ENV
fi
- name: Checkout prod branch
if: env.match == 'true'
uses: actions/checkout@v3
with:
ref: prod
- name: Fetch main branch
if: env.match == 'true'
run: |
git fetch origin main:main
- name: Merge main into prod
if: env.match == 'true'
run: |
git merge main --no-ff --allow-unrelated-histories -m "Merging changes from main to prod"
git push origin prod
2