【问题标题】:GitHub Actions: how to target all branches EXCEPT master?GitHub Actions:如何定位除 master 之外的所有分支?
【发布时间】:2020-01-02 02:53:07
【问题描述】:

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

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

非常感谢。

【问题讨论】:

  • 他们的文档似乎暗示你可以使用类似的东西来做到这一点:on: push: branches: - '!master'help.github.com/en/articles/… 但我无法让类似的否定模式起作用。
  • 谢谢你,Ollie,遗憾的是这似乎并没有触发管道......

标签: git github github-actions


【解决方案1】:

更新Samy's answer 中描述了一个更新的过滤器,它提供了一种更简洁的方式来实现这一点。


The documentation 现已更新更多信息:

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

  • 正匹配后的匹配负模式将排除 再次参考。
  • 否定匹配后的匹配肯定模式将 再次包含 ref。

所以为了排除master,您需要确保首先包含匹配所有内容的模式:

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

【讨论】:

  • */* 只匹配包含一个/的分支
  • @wrymug 谢谢,这就是我的意思 - 我将编辑答案以使其更清晰。
  • 感谢更新。可惜 GitHub Actions 似乎没有提供真正的通配符模式。
  • @wrymug 和其他人不确定这是否是新功能,但'**' 将匹配每个分支。请参阅the docs 了解更多信息。
【解决方案2】:

现在有一个branches-ignore 选项:

on:
  push:
    branches-ignore:
      - master

https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#onpushpull_requestbranchestags

【讨论】:

  • branches-ignore 对我不起作用。 on: push: branches: - main - release pull_request: branches-ignore: - release
  • @Vaulstein branches-ignorebranches 不能在一个事件中同时使用。
猜你喜欢
  • 1970-01-01
  • 2022-10-18
  • 1970-01-01
  • 2013-02-05
  • 2022-01-08
  • 2021-11-10
  • 2020-12-08
  • 2020-05-06
  • 2021-05-11
相关资源
最近更新 更多