66 required : true
77 description : ' The base branch to compare and merge.'
88
9+ autoMerge :
10+ required : false
11+ description : ' Automatically merge the base branch into the pull request branch if necessary.'
12+ default : ' true'
13+
14+ descriptionMerged :
15+ required : false
16+ description : ' Description of the merge commit.'
17+ default : ' Merge ${{ github.event.pull_request.base.ref }} into ${{ github.event.pull_request.head.ref }}'
18+
19+ descriptionReminder :
20+ required : false
21+ description : ' Description of the PR comment if ' autoMerge' is false.'
22+ default : ' Please merge `${{ github.event.pull_request.base.ref }}` into `${{ github.event.pull_request.head.ref }}`.'
23+
924runs :
1025 using : ' composite'
1126 steps :
@@ -28,29 +43,43 @@ runs:
2843 BASE=$(git merge-base origin/${{ github.event.pull_request.base.ref }} HEAD)
2944 if [ $BASE = $(git rev-parse origin/${{ github.event.pull_request.base.ref }}) ]; then
3045 echo "Branches are up to date, skipping merge."
31- echo "::set-output name= mergeRequired:: false"
46+ echo "mergeRequired= false" >> $GITHUB_OUTPUT
3247 else
3348 echo "Branches are not up to date, merge is required."
34- echo "::set-output name= mergeRequired:: true"
49+ echo "mergeRequired= true" >> $GITHUB_OUTPUT
3550 fi
3651
3752 - name : Merge base branch into PR branch
3853 shell : bash
39- if : steps.checkBranches.outputs.mergeRequired == 'true'
54+ if : steps.checkBranches.outputs.mergeRequired == 'true' && inputs.autoMerge == 'true'
4055 run : |
4156 git merge --no-edit --no-commit origin/${{ github.event.pull_request.base.ref }}
4257 if [ $? -ne 0 ]; then
4358 echo "Merge conflict detected. Please resolve conflicts before merging."
4459 exit 1
4560 fi
46- git commit -m "Merge ${{ github.event.pull_request.base.ref }} into ${{ github.event.pull_request.head.ref }}"
61+ git commit -m "${{ inputs.descriptionMerged }}"
4762
4863 - name : Push changes
4964 shell : bash
50- if : steps.checkBranches.outputs.mergeRequired == 'true'
65+ if : steps.checkBranches.outputs.mergeRequired == 'true' && inputs.autoMerge == 'true'
5166 run : |
5267 git push origin ${{ github.event.pull_request.head.ref }}
5368
69+ - name : Command on PR to remind the PR branch is not up to date
70+ if : steps.checkBranches.outputs.mergeRequired == 'true' && inputs.autoMerge == 'false'
71+ uses : thollander/actions-comment-pull-request@v3.0.1
72+ with :
73+ message : |
74+ ## This branch is out-of-date with the base branch
75+ ${{ inputs.descriptionReminder }}
76+ comment-tag : pr-up-to-date
77+
78+ - name : Block the workflow if the PR branch is not up to date
79+ shell : bash
80+ if : steps.checkBranches.outputs.mergeRequired == 'true' && inputs.autoMerge == 'false'
81+ run : exit 1
82+
5483branding :
5584 icon : ' git-pull-request'
5685 color : ' blue'
0 commit comments