How to suppress push triggers when a pull request is open?


I am working on a branch of code that has a draft pull request open against it. Every time I make a new commit to this branch, my workflow runs twice – once because it has a PR open against it and once because of the push trigger, i.e.:

on: [push, pull_request]

Is there a way to suppress the push trigger when the branch has an open PR against it?


You cannot really suppress it as far as I know, but you could have one of the workflows query the GitHub API to determine whether there’s another run and then skip it. Maybe combine that with an environment where you enable the wait timer, simply to ensure that the other run is already started.

Another idea would be to utilize the rather new concurrency feature to make the workflows run after one another and abort one of them with cancel-in-progress: true. You will need to find a concurrency group key that is equal for both, but not unrelated other runs - which could actually be tricky.