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?
CodePudding user response:
Yes, it is possible. You have to do the following:
- Enable auto-merge for your repository, see the Github documentation here
- Go to the branch protection rules of your repository. To get there:
- Go to your repos settings
- Go to "branches" in the section "Code and automation"
- Add or edit the branch protection rules for the branch you want to merge your pull requests into, so e.g.
main
ormaster
- Activate "Require status checks to pass before merging"
- 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.