Search code examples
gitgithubautomationgithub-actionsgit-merge

Automatic merge after tests pass using Actions?


I was wondering whether it's possible to automate merging of branches after tests pass using GitHub Actions.

We have two branches, 'test' and 'main'. After every merge or push to 'test', we have a Workflow set up to run tests.

Is it possible to make GitHub automatically merge 'test' -> 'main' after the tests complete, and only if they complete successfully?


Solution

  • Yes, it is possible. You have to do the following:

    1. Enable auto-merge for your repository, see the Github documentation here
    2. Go to the branch protection rules of your repository. To get there:
      1. Go to your repos settings
      2. Go to "branches" in the section "Code and automation"
    3. Add or edit the branch protection rules for the branch you want to merge your pull requests into, so e.g. main or master
    4. Activate "Require status checks to pass before merging"
    5. Type each name of your (Github Actions) workflows into the free text field with the description "Search for status checks in the last week of this repository"

    Then auto-merging should be possible. I just did it today e.g. here.