[英]GitHub Actions: how to target all branches EXCEPT master?
I want to be able to let an action run on any given branch except master.我希望能够让操作在除 master 之外的任何给定分支上运行。 I am aware that there is a prebuilt
filter
action, but I want the exact opposite.我知道有一个预先构建的
filter
操作,但我想要的是完全相反的。
More like GitLab's except
keyword.更像是 GitLab 的
except
关键字。 Since this is not inside the official docs, has anyone prepared a decent workaround?由于这不在官方文档中,是否有人准备了一个像样的解决方法?
Thank you very much.非常感谢。
Update : There is a newer filter described in Samy's answer that provides a more succinct way of achieving this.更新:在Samy 的回答中描述了一个更新的过滤器,它提供了一种更简洁的方法来实现这一点。
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 .当您指定
branches
或tags
过滤器时,工作流仅在至少一个模式匹配时运行。 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:因此,为了排除
master
,您需要确保首先包含匹配所有内容的模式:
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:现在有一个
branches-ignore
选项:
on:
push:
branches-ignore:
- master
https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#onpushpull_requestbranchestags https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#onpushpull_requestbranchestags
I want to be able to let an action run on any given branch except master.我希望能够让操作在除 master 之外的任何给定分支上运行。 I am aware that there is a prebuilt
filter
action, but I want the exact opposite.我知道有一个预先构建的
filter
操作,但我想要的是完全相反的。
More like GitLab's except
keyword.更像是 GitLab 的
except
关键字。 Since this is not inside the official docs, has anyone prepared a decent workaround?由于这不在官方文档中,是否有人准备了一个像样的解决方法?
Thank you very much.非常感谢你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.