简体   繁体   English

github 操作排除来自分支的拉取请求

[英]github actions exclude pull requests from a branch

Say I have a workflow that runs on every PR to master which starts with:假设我有一个在每个 PR 上运行以掌握的工作流程,其开头为:

on:
  pull_request:
    branches:
      - master

I'd like to skip all jobs if the PR is coming from the depbot branch.如果 PR 来自depbot分支,我想跳过所有工作。 Something like:就像是:

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

I think you can skip all the steps (one at a time) using我认为您可以使用以下方法跳过所有步骤(一次一个)

 if: startsWith(github.head_ref, 'depbot') == false

But it is not what I want, as it would still initiate the job.但这不是我想要的,因为它仍然会启动工作。 How can I achieve that at the launch level?我如何才能在发布级别实现这一目标?

But it is not what I want, as it would still initiate the job.但这不是我想要的,因为它仍然会启动工作。

That means you would need a "gatekeeper" job which would be initiated (and check github.head_ref), and, through job dependency , would call the second one only if the right condition is fulfilled.这意味着您需要一个“看门人”作业,该作业将被启动(并检查 github.head_ref),并且通过作业依赖项,只有在满足正确条件时才会调用第二个作业

But the point is: you need at least one job to start, in order to check a condition.但关键是:您至少需要启动一项工作,以检查条件。

According to the documentation , there are at least 2 ways of doing it at the workflow level:根据文档,在工作流级别至少有两种方法:

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

Or或者

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

Not that you cannot use both the branches and branches-ignore filters for the same event in a workflow.并不是说您不能对工作流中的同一事件同时使用branchesbranches-ignore过滤器。 Use the branches filter when you need to filter branches for positive matches and exclude branches.当您需要过滤分支以获得正匹配并排除分支时,请使用分支过滤器。 Use the branches-ignore filter when you only need to exclude branch names.当您只需要排除分支名称时,请使用分支忽略过滤器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM