GitHub 操作:如何针对除 master 之外的所有分支?
GitHub Actions: how to target all branches EXCEPT master?
我希望能够在除 master 之外的任何给定分支上执行操作 运行。
我知道有一个预建的 filter
操作,但我想要完全相反的操作。
更像是 GitLab 的 except
关键字。
由于这不在官方文档中,是否有人准备了一个不错的解决方法?
非常感谢。
更新:
中描述了一个更新的过滤器,它提供了一种更简洁的方法来实现这一点。
The documentation 现在更新了更多信息:
When you specify a branches
or tags
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
现在有一个 branches-ignore
选项:
on:
push:
branches-ignore:
- master
我希望能够在除 master 之外的任何给定分支上执行操作 运行。
我知道有一个预建的 filter
操作,但我想要完全相反的操作。
更像是 GitLab 的 except
关键字。
由于这不在官方文档中,是否有人准备了一个不错的解决方法?
非常感谢。
更新:
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
现在有一个 branches-ignore
选项:
on:
push:
branches-ignore:
- master