简体   繁体   English

GitHub Actions:如何定位除 master 之外的所有分支?

[英]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 or tags filter, the workflow only runs if at least one pattern matches .当您指定branchestags过滤器时,工作流仅在至少一个模式匹配时运行 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:您定义模式的顺序很重要:

  • A matching negative pattern after a positive match will exclude the ref again.正匹配后匹配的负模式将再次排除引用。
  • A matching positive pattern after a negative match will include the ref again.否定匹配后匹配的肯定模式将再次包含 ref。

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

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.

相关问题 如何删除除master之外的所有Git远程分支? - How to delete all Git remote branches except master? Git:如何删除所有本地分支(合并与否),除了master和develop - Git : How to delete all local branches (merged or not), except master and develop Git 尺寸太大,无法上传到 github。 除master外的所有分支都被删除,所有文件都被清除 - Git size too large to upload to github. All branches except master were deleted, all files cleared 如何对所有分支机构使用 github 操作工作流文件? - How to use github actions workflow file for all branches? 了解如何使用Github处理2个分支(主节点,临时节点)? - Understanding how to work with 2 branches (master, staging) with Github? 如何删除除master之外的所有本地分支并在一个没有别名的命令中开发? - How to delete all local branches except master and develop in one command without aliases? 只有在除master以外的所有分支都有TAG推送的情况下,Gitlab才会触发Pipeline - Gitlab trigger Pipeline only if there is a pushed TAG for all branches except master 如何将所有分支与主分支合并? - How to merge all branches with the master branch? GitHub:“master”在分支列表中不可见 - GitHub: 'master' not visible in List of branches 如何正确同步来自 github 的分叉仓库上的 master 和分支 - How to correctly sync the master and branches on a forked repo from github
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM