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

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

问题描述

阅读 触发工作流的事件,我想知道是否可以使用给定标签名称(如 RFR 或 WIP)运行工作流.

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: [labeled],则不需要这样做>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 操作文档 关于条件表达式是 这里.

GitHub actions documentation regarding conditional expressions is here.

这篇关于当拉取请求具有特定标签时运行 Github Actions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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