我希望能够在除主分支(master)以外的任何分支上运行某个操作。
我知道有一个预构建的 filter
操作,但我想要完全相反的操作。
更像是GitLab中的 except
关键字。
由于它不在官方文档中,有人准备了一个不错的解决方法吗?
非常感谢。
我希望能够在除主分支(master)以外的任何分支上运行某个操作。
我知道有一个预构建的 filter
操作,但我想要完全相反的操作。
更像是GitLab中的 except
关键字。
由于它不在官方文档中,有人准备了一个不错的解决方法吗?
非常感谢。
更新:现在有一种新的过滤器,Samy 的回答中有更简洁的实现方法。
文档已经更新并提供了更多信息:
当你指定
branches
或者tags
过滤器时,只有至少有一个模式匹配成功,工作流才会运行。任何不符合定义模式的分支或标签的更改都不会触发工作流程。你定义模式的顺序很重要:
因此,为了排除 master
,你需要确保首先包含匹配所有内容的模式:
on:
push:
branches:
- '*' # matches every branch that doesn't contain a '/'
- '*/*' # matches every branch containing a single '/'
- '**' # matches every branch
- '!master' # excludes master
'**'
将匹配每个分支。有关更多信息,请参阅[文档](https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet)。 - Dylan Nissleybranches-ignore
选项:on:
push:
branches-ignore:
- master
在同一个工作流中,您不能同时使用branches-ignore
和branches
。
on:
push:
branches:
- main
- release
pull_request:
branches-ignore:
- release
- Vaulsteinbranches-ignore
和branches
。@Vaulstein - JSKIMbranches
用于push
,而branches-ignore
用于pull_request
。这样应该可以工作,对吗? - undefined
on: push: branches: - '!master'
https://help.github.com/en/articles/workflow-syntax-for-github-actions#on但我尝试了类似的否定模式却无法生效。 - Electric Sheep