Skip to content

Speed up your workflows by automatically enabling Auto-Merge in your Github pull-requests, so you can release when ready.

License

Notifications You must be signed in to change notification settings

alexwilson/enable-github-automerge-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

Enable Github Auto-Merge Action

Speed up your workflows by automatically enabling Auto-Merge in your Github pull-requests, so you can release when ready.

Public workflows that use this action CI status

Name: alexwilson/enable-github-automerge-action

1) What is this?

To speed up some of your workflows, this action allows you to automatically enable Auto-Merge in your Github pull-requests.

When enabled, auto-merge will merge pull-requests automatically as soon as all requirements are met (i.e. approvals, passing tests).

You can use this, for example, to automatically merge Dependabot pull-requests.

This action pairs well with hmarr/auto-approve-action.

2) Usage

Add as a step inside a GitHub workflow, e.g. .github/workflows/auto-merge.yml. You can see an example of this in this repository.

⚠️ GitHub have recently improved the security model of actions reducing the risk of unknown code accessing secrets, so we recommend running this in an isolated workflow within the pull_request_target scope, on a trusted event (e.g. labeled).

name: Auto-Merge
on:
  pull_request_target:
    types: [labeled]

jobs:
  enable-auto-merge:
    runs-on: ubuntu-latest

    # Specifically check that dependabot (or another trusted party) created this pull-request, and that it has been labelled correctly.
    if: github.event.pull_request.user.login == 'dependabot[bot]' && contains(github.event.pull_request.labels.*.name, 'dependencies')
    steps:
    - uses: alexwilson/enable-github-automerge-action@main
      with:
        github-token: "${{ secrets.GITHUB_TOKEN }}"

Note: You will probably want to add some restrictions so this doesn't auto-merge every PR: these are handled fairly well by GitHub Workflow syntax, you can read more about this here.

2.1) Additional Options

    - uses: alexwilson/enable-github-automerge-action@1.0.0
      with:
        github-token: "${{ secrets.GITHUB_TOKEN }}"
        merge-method: "SQUASH"
  • github-token: The Github Token to use for this action. By default this variable is set to run as github-actions, however you can replace this with another user/actor's Github Token (make sure it has, at minimum, repo scope).
  • merge-method: Override the merge method. By default this action attempts to select your repository's default merge method, and falls back to merge. One of MERGE, SQUASH or REBASE. Read more here.

3) Developing Locally

Github Action developer-experience isn't fantastic, so for now we mimic the Github Action environment in ./src/local.ts.

This file sets environment variables locally to enable action inputs, and points to a sample pull-request webhook event in ./stub/example-pull-request.json.

  1. Make sure you're running a recent version of Node (the correct version will always be in .nvmrc and action.yml)
  2. Set GITHUB_TOKEN locally. (You can do this via $ export GITHUB_TOKEN=blah)
  3. Optionally(!) set MERGE_METHOD locally. (You can do this via $ export MERGE_METHOD=MERGE)
  4. Run with npm run local.
  5. Important: Avoid committing anything to dist/* — this is automatically regenerated and manually adjusting this will make rebasing harder!