GitHub行动:如何针对除master之外的所有分支? [英] GitHub Actions: how to target all branches EXCEPT master?

查看:114
本文介绍了GitHub行动:如何针对除master之外的所有分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to be able to let an action run on any given branch except master. I am aware that there is a prebuilt filter action, but I want the exact opposite.

更像GitLab的except关键字. 由于这不在官方文档中,因此有人准备过不错的解决方法吗?

More like GitLab's except keyword. Since this is not inside the official docs, has anyone prepared a decent workaround?

非常感谢您.

推荐答案

更新: 萨米的答案中描述了一个更新的过滤器,它提供了一种更简洁的方法来实现这一目标.

Update: There is a newer filter described in Samy's answer that provides a more succinct way of achieving this.

文档已更新为现在更多信息:

The documentation has been updated with more information now:

当您指定branchestags过滤器时,仅当至少一个模式匹配时,工作流才会运行.与定义的模式不匹配的分支或标签的任何更改都不会触发工作流程.定义模式的顺序很重要:

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:

  • 正匹配之后匹配的负模式将排除 再次引用.
  • 否定匹配后匹配的肯定模式将 再次添加裁判.
    • 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.
    • 因此,要排除master,您需要确保首先包含与所有内容匹配的模式:

      So in order to exclude master, you need to ensure that a pattern matching everything is included first:

      on:
        push:
          branches:    
            - '*'         # matches every branch that doesn't contain a '/'
            - '*/*'       # matches every branch containing a single '/'
            - '**'        # matches every branch
            - '!master'   # excludes master
      

      这篇关于GitHub行动:如何针对除master之外的所有分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆