GitHub 操作 : how to target all branches EXCEPT master?

标签 git github github-actions

我希望能够让一个 Action 在除 master 之外的任何给定分支上运行。 我知道有一个预建的 filter 操作,但我想要完全相反的操作。

更像是 GitLab 的 except 关键字。 由于这不在官方文档中,是否有人准备了一个不错的解决方法?

非常感谢。

最佳答案

更新: Samy's answer 中描述了一个更新的过滤器这提供了一种更简洁的方法来实现这一目标。


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

关于GitHub 操作 : how to target all branches EXCEPT master?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57699839/

相关文章:

php - Composer Github 私有(private)存储库不适用于给定 key

image - 将图像添加到可通过 github 在私有(private) repo 中查看的 jupyter notebook

github-actions - 在github Action 工作流中,是否有办法让多个作业重复使用相同的设置?

docker - github 操作 : run multiple jobs in the same docker

github - Docker 容器卷未安装在 GitHub Actions 中

git - 将 GIT 与 Eclipse 和 repos 的备份一起使用

git - git push origin HEAD 是什么意思?

Git:如何从远程存储库检索注释引用?

Android Studio Git .gitignore 与项目 > 设置 > 版本控制 > 忽略文件

git - 如何将远程开发分支重置为 master