How to merge to a protected branch when Github Action passes?

Viewed 1083

My current workflow is to push to my master branch on GitHub, which then triggers a Github Action that runs my unit tests, stress tests etc.

I now want to make sure that no commits land on master that fail the tests. For that, I want to:

  1. introduce a testing branch for pushing instead, which then runs the GitHub action and finally automatically merges to master when passing.
  2. protect the master branch in a way that I cannot accidentally push to it directly.

How can I achieve this?

Additional info:

  • I prefer not to use Pull Requests for this, as I'm currently the only developer in this project.
1 Answers

I prefer not to use Pull Requests for this

Yet they are a good option to consider.
Combined with the right tools, a PR with a label "automerge" can then be automatically accepted/merged.

For instance:

  • mergery, GitHub application (so it needs a dedicated server)
  • automerge-action (so its does not need its own server, and is executed directly on GitHub side)

The latter includes:

MERGE_LABELS: The labels that need to be present for a pull request to be merged (using MERGE_METHOD). The default value is automerge.

All you need to do is create a PR with an automerge label.

Related