I want to be able to let an action run on any given branch except master. I am aware that there is a prebuilt filter
action, but I want the exact opposite.
More like GitLab's except
keyword. Since this is not inside the official docs, has anyone prepared a decent workaround?
Thank you very much.
Github actions can only trigger on master or the default branch.
To run jobs sequentially, you can define dependencies on other jobs using the jobs. <job_id>. needs keyword. Each job runs in a runner environment specified by runs-on .
A matrix strategy lets you use variables in a single job definition to automatically create multiple job runs that are based on the combinations of the variables. For example, you can use a matrix strategy to test your code in multiple versions of a language or on multiple operating systems.
Update: There is a newer filter described in Samy's answer that provides a more succinct way of achieving this.
The documentation has been updated with more information now:
When you specify a
branches
ortags
filter, the workflow only runs if at least one pattern matches. Any changes to branches or tags that don't match a defined pattern will not trigger a workflow. The order that you define patterns matters:
So in order to exclude master
, you need to ensure that a pattern matching everything is included first:
on: push: branches: - '*' # matches every branch that doesn't contain a '/' - '*/*' # matches every branch containing a single '/' - '**' # matches every branch - '!master' # excludes master
There is now a branches-ignore
option:
on: push: branches-ignore: - master
https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#onpushpull_requestbranchestags
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With