拉取请求具有特定标签时运行Github Actions [英] Run Github Actions when pull requests have a specific label

查看:59
本文介绍了拉取请求具有特定标签时运行Github Actions的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读

After reading the documentation of the Events that trigger workflows, I wonder if it's possible to run a workflow with a given label name, like RFR or WIP.

我知道在标记了拉取请求后,我们可以运行工作流程,但是对于特定的标签名称,仅此而已:

I know we can run a workflow when the pull request is labeled, but there is nothing more for a specifc label name :

on:
  pull_request:
    types: [labeled]

有人做过吗?

推荐答案

您可以使用

if: ${{ github.event.label.name == 'label_name' }}

因此,如果您具有如下所示的GitHub操作配置

So if you have your GitHub action config as below

name: CI

on:
  pull_request:
    types: [ labeled ]

jobs:
  build:
    if: ${{ github.event.label.name == 'bug' }}
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Run a one-line script
      run: echo Hello, world!

只要标有PR,它将触发工作流程,并且仅当标签为 bug 运行作业,如果标签为其他任何内容,则跳过.您还可以使用 github.event.action =='labeled'作为额外的检查,但是如果您只有 types:[标为] ,则不需要这样做> pull_request ,如上面的配置所示.

It would trigger the workflow whenever a PR is labeled and run the job only if the label is bug and would skip if the label is anything else. You can also use github.event.action == 'labeled' as an extra check but that is not required if you have only types: [ labeled ] for the pull_request as shown in the config above.

注意:仅为您提供信息,在标记PR的情况下,github事件具有以下有关该标签的信息(为简便起见,删除了无关的数据)

Note: Just for your information, the github event has the following info (removed the irrelevant data for brevity) regarding the label in case of labelling a PR

"event": {
    "action": "labeled",
    "label": {
      "color": "d73a4a",
      "default": true,
      "description": "Something isn't working",
      "id": 1519136641,
      "name": "bug",
      "node_id": "abcd",
      "url": "https://api.github.com/repos/owner/repo/labels/bug"
    }
}

关于条件表达式的

GitHub行为文档 查看全文

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