Optimize Your CI/CD Pipeline
Get instant insights into your CI/CD performance and costs. Reduce build times by up to 45% and save on infrastructure costs.
name: 'Usage of automerge-action GitHub Action'
on:
pull_request:
types:
- labeled
- unlabeled
- synchronize
- opened
- edited
- ready_for_review
- reopened
- unlocked
pull_request_review:
types:
- submitted
check_suite:
types:
- completed
status: {}
jobs:
automerge:
runs-on: ubuntu-latest
steps:
- id: automerge
name: automerge
uses: "pascalgn/[email protected]"
permissions:
contents: write
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
Automerge Action
GitHub action to automatically merge pull requests that are ready
What is the Automerge GitHub Action?
The Automerge GitHub Action is designed to automatically merge pull requests when they are ready. This action helps streamline the process of integrating changes by merging pull requests that meet specific criteria.
Merge Options
The Automerge GitHub Action supports various options for merging and updating pull requests. Below are explanations and examples for each configuration option.
How to Specify Merge Labels
Labels required for a pull request to be merged. Labels prefixed with !
will block a pull request from being merged if present.
env:
MERGE_LABELS: "automerge,!work in progress"
How to Specify Labels to Remove After Merge
Labels to automatically remove from a pull request once it has been merged.
env:
MERGE_REMOVE_LABELS: "automerge"
How to Specify Merge Method
The method to use when merging the pull request. Possible values are merge
, rebase
, or squash
.
env:
MERGE_METHOD: "squash"
How to Specify Merge Method Labels
Labels that determine the merge method. For example, automerge=merge,autosquash=squash
.
env:
MERGE_METHOD_LABELS: "automerge=merge,autosquash=squash"
How to Require Merge Method Label
Require one of the MERGE_METHOD_LABELS
to be set.
env:
MERGE_METHOD_LABEL_REQUIRED: "true"
How to Specify Commit Message
The commit message to use when merging the pull request.
env:
MERGE_COMMIT_MESSAGE: "pull-request-description"
How to Specify Commit Message Regex
Regex to filter the commit message when using the PR's body.
env:
MERGE_COMMIT_MESSAGE_REGEX: "(.*)^---"
How to Filter by Author
Only merge pull requests raised by this author.
env:
MERGE_FILTER_AUTHOR: "author-username"
How to Control Fork Merging
Enable or disable merging from external repositories.
env:
MERGE_FORKS: "false"
How to Specify Merge Retries and Sleep
Set the number of retries and the time to sleep between retries.
env:
MERGE_RETRIES: "6"
MERGE_RETRY_SLEEP: "10000"
How to Specify Required Approvals
Set the number of required approvals.
env:
MERGE_REQUIRED_APPROVALS: "2"
How to Delete Branches After Merge
Automatically delete branches after they have been merged.
env:
MERGE_DELETE_BRANCH: "true"
How to Filter Branches for Deletion
A list of branches that will not be deleted.
env:
MERGE_DELETE_BRANCH_FILTER: "main,dev"
How to Fail on Merge Error
Exit with error code 1 if the pull request could not be merged successfully.
env:
MERGE_ERROR_FAIL: "true"
How to Specify Ready State
The states of a pull request to attempt a merge.
env:
MERGE_READY_STATE: "clean,has_hooks"
Update Options
How to Specify Update Labels
Labels required for a pull request to be updated.
env:
UPDATE_LABELS: "automerge"
How to Specify Update Method
The method to use when updating the pull request to the base branch. Possible values are merge
or rebase
.
env:
UPDATE_METHOD: "rebase"
How to Specify Update Retries and Sleep
Set the number of retries and the time to sleep between retries.
env:
UPDATE_RETRIES: "1"
UPDATE_RETRY_SLEEP: "5000"
General Options
How to Specify GitHub Token
GitHub token for authentication. Typically ${{ secrets.GITHUB_TOKEN }}
.
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
How to Specify Pull Request
Specify a pull request to merge. Defaults to the pull request in the GitHub context.
env:
PULL_REQUEST: "1234"
How to Restrict Base Branches
Restrict the action to specific base branches.
env:
BASE_BRANCHES: "main,dev"