From 4d9961b094cb16323248c6f3ddc29ee395287312 Mon Sep 17 00:00:00 2001 From: Kent Huang Date: Tue, 5 Nov 2024 22:19:23 +0800 Subject: [PATCH 1/2] [Feature] Add flag to disable auto merge - Once the auto merge is disabled, will command on the PR to remind users this PR branch is not up to date. Signed-off-by: Kent Huang --- action.yml | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/action.yml b/action.yml index 56224ac..626fc67 100644 --- a/action.yml +++ b/action.yml @@ -6,6 +6,21 @@ inputs: required: true description: 'The base branch to compare and merge.' + autoMerge: + required: false + description: 'Automatically merge the base branch into the pull request branch if necessary.' + default: 'true' + + descriptionMerged: + required: false + description: 'Description of the merge commit.' + default: 'Merge ${{ github.event.pull_request.base.ref }} into ${{ github.event.pull_request.head.ref }}' + + descriptionReminder: + required: false + description: 'Description of the PR comment if 'autoMerge' is false.' + default: 'Please merge `${{ github.event.pull_request.base.ref }}` into `${{ github.event.pull_request.head.ref }}`.' + runs: using: 'composite' steps: @@ -28,29 +43,43 @@ runs: BASE=$(git merge-base origin/${{ github.event.pull_request.base.ref }} HEAD) if [ $BASE = $(git rev-parse origin/${{ github.event.pull_request.base.ref }}) ]; then echo "Branches are up to date, skipping merge." - echo "::set-output name=mergeRequired::false" + echo "mergeRequired=false" >> $GITHUB_OUTPUT else echo "Branches are not up to date, merge is required." - echo "::set-output name=mergeRequired::true" + echo "mergeRequired=true" >> $GITHUB_OUTPUT fi - name: Merge base branch into PR branch shell: bash - if: steps.checkBranches.outputs.mergeRequired == 'true' + if: steps.checkBranches.outputs.mergeRequired == 'true' && inputs.autoMerge == 'true' run: | git merge --no-edit --no-commit origin/${{ github.event.pull_request.base.ref }} if [ $? -ne 0 ]; then echo "Merge conflict detected. Please resolve conflicts before merging." exit 1 fi - git commit -m "Merge ${{ github.event.pull_request.base.ref }} into ${{ github.event.pull_request.head.ref }}" + git commit -m "${{ inputs.descriptionMerged }}" - name: Push changes shell: bash - if: steps.checkBranches.outputs.mergeRequired == 'true' + if: steps.checkBranches.outputs.mergeRequired == 'true' && inputs.autoMerge == 'true' run: | git push origin ${{ github.event.pull_request.head.ref }} + - name: Command on PR to remind the PR branch is not up to date + if: steps.checkBranches.outputs.mergeRequired == 'true' && inputs.autoMerge == 'false' + uses: thollander/actions-comment-pull-request@v3.0.1 + with: + message: | + ## This branch is out-of-date with the base branch + ${{ inputs.descriptionReminder }} + comment-tag: pr-up-to-date + + - name: Block the workflow if the PR branch is not up to date + shell: bash + if: steps.checkBranches.outputs.mergeRequired == 'true' && inputs.autoMerge == 'false' + run: exit 1 + branding: icon: 'git-pull-request' color: 'blue' \ No newline at end of file From 0c3d7d4e63877af994bd16a8e0254c8323e492f7 Mon Sep 17 00:00:00 2001 From: Kent Huang Date: Wed, 6 Nov 2024 11:25:40 +0800 Subject: [PATCH 2/2] Update README.md Signed-off-by: Kent Huang --- README.md | 3 +++ action.yml | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8bc3a36..58e9df5 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,9 @@ To use the "Merge Base Branch into PR" action in your GitHub workflows, follow t The action requires the following input: - `baseBranch` (required): The base branch to compare and merge with the pull request branch. +- `autoMerge` (optional): A flag to enable or disable the automatic merge of the base branch into the pull request branch. Default is `true`. +- `descriptionMerged` (optional): Customized the merge commit message. +- `descriptionReminder` (optional): Customized the reminder message posted on the PR comment if autoMerge is disabled. ### Example Workflow diff --git a/action.yml b/action.yml index 626fc67..223d083 100644 --- a/action.yml +++ b/action.yml @@ -18,7 +18,7 @@ inputs: descriptionReminder: required: false - description: 'Description of the PR comment if 'autoMerge' is false.' + description: 'Description of the PR comment if "autoMerge" is false.' default: 'Please merge `${{ github.event.pull_request.base.ref }}` into `${{ github.event.pull_request.head.ref }}`.' runs: