Reputation: 1011
I'm setting up Github actions for a few of my projects. The flow I'd like to achieve is:
The reason for this kind of flow, is I wouldn't like the tests to run on each commit pushed to the branch. I want the flow to run only when trying to merge.
My question is: Is there a way to manually execute a workflow only when trying / wanting to merge, and making sure the branch can be merged into master if and only if the tests have passed?
Upvotes: 18
Views: 20724
Reputation: 329
Github now has merge queues in beta, which allow you to trigger a workflow when a PR is added to a merge group. Using that functionality you should be able to trigger a workflow when the PR is added to the merge queue. You can also specify that the merge should fail if the tests fail.
Upvotes: 12
Reputation: 9889
Unfortunately, there's no merged
or merge_attempt
activity type on the pull request event (yet). Even if there was, I don't believe GitHub has a way to block merges on the completion of a workflow (yet).
What I would suggest as a workaround here is to run your test 1. after the fact on pushes to the master
branch, and 2. on pull_request
events with certain activity types which indicate that the user is likely to attempt a merge soon. For example, ready_for_review
or review_requested
.
Something like this:
name: tests
on:
push:
branches:
- master
pull_request:
branches:
- master
types:
- ready_for_review
- review_requested
Upvotes: 6