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 56224ac..223d083 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