【问题标题】:github actions exclude pull requests from a branchgithub 操作排除来自分支的拉取请求
【发布时间】:2021-09-24 01:07:56
【问题描述】:

假设我有一个在每个 PR 上运行的工作流,以掌握它的开头:

on:
  pull_request:
    branches:
      - master

如果 PR 来自 depbot 分支,我想跳过所有工作。比如:

on:
  pull_request:
    branches:
      - master
    head_ref-ignore:
      - depbot

我认为您可以使用

跳过所有步骤(一次一个)
 if: startsWith(github.head_ref, 'depbot') == false

但这不是我想要的,因为它仍然会启动这项工作。我怎样才能在发布阶段实现这一目标?

【问题讨论】:

    标签: github github-actions pull-request


    【解决方案1】:

    但这不是我想要的,因为它仍然会启动这项工作。

    这意味着您将需要一个“看门人”作业,该作业将被启动(并检查 github.head_ref),并且通过job dependency,只有在满足正确条件时才会调用第二个作业。

    但重点是:您至少需要开始一项工作,才能检查条件。

    【讨论】:

      【解决方案2】:

      根据the documentation,在工作流级别至少有两种方法:

      on:
        pull_request:
          branches:    
            - 'master'    # matches refs/heads/master
            - '!depbot'   # excludes refs/heads/depbot
      

      或者

      on:
        pull_request:
          branches-ignore:    
            - 'depbot'   # ignore refs/heads/depbot
      

      并不是说您不能对工作流中的同一事件同时使用 branchesbranches-ignore 过滤器。当您需要过滤分支以获得正匹配并排除分支时,请使用分支过滤器。当您只需要排除分支名称时,请使用分支忽略过滤器。

      【讨论】:

      • 这适用于指定的基本分支。我正在寻找一种方法来忽略“来自”特定分支的 PR。
      猜你喜欢
      • 2020-06-25
      • 2020-01-30
      • 2022-08-13
      • 1970-01-01
      • 1970-01-01
      • 2014-11-30
      • 1970-01-01
      • 1970-01-01
      • 2023-02-24
      相关资源
      最近更新 更多