Skip to content

Commit c686688

Browse files
authored
Merge pull request #1 from kentwelcome/feature/add-flag-to-disable-auto-merge
[Feature] DRC-869 Alert users if the base is outdated
2 parents e847963 + bcb9d52 commit c686688

2 files changed

Lines changed: 37 additions & 5 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ To use the "Merge Base Branch into PR" action in your GitHub workflows, follow t
2121
The action requires the following input:
2222

2323
- `baseBranch` (required): The base branch to compare and merge with the pull request branch.
24+
- `autoMerge` (optional): A flag to enable or disable the automatic merge of the base branch into the pull request branch. Default is `true`.
25+
- `descriptionMerged` (optional): Customized the merge commit message.
26+
- `descriptionReminder` (optional): Customized the reminder message posted on the PR comment if autoMerge is disabled.
2427

2528
### Example Workflow
2629

action.yml

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@ inputs:
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+
924
runs:
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+
5483
branding:
5584
icon: 'git-pull-request'
5685
color: 'blue'

0 commit comments

Comments
 (0)