我希望能够让一个 Action 在除 master 之外的任何给定分支上运行。
我知道有一个预建的 filter
操作,但我想要完全相反的操作。
更像是 GitLab 的 except
关键字。
由于这不在官方文档中,是否有人准备了一个不错的解决方法?
非常感谢。
最佳答案
更新: Samy's answer 中描述了一个更新的过滤器这提供了一种更简洁的方法来实现这一目标。
The documentation现在已经更新了更多信息:
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:
- 正匹配后的匹配负模式将排除 再次引用。
- 负匹配之后的匹配正模式将 再次包含引用。
因此,为了排除master
,您需要确保首先包含匹配所有内容的模式:
on:
push:
branches:
- '*' # matches every branch that doesn't contain a '/'
- '*/*' # matches every branch containing a single '/'
- '**' # matches every branch
- '!master' # excludes master
关于GitHub 操作 : how to target all branches EXCEPT master?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57699839/