如何通过标签跳过 GitHub Actions 作业

3
以下是我在 GitHub Actions 中的一个 yml 文件。
name: "Labeler"
on:
  issues:
    types: [ opened, edited, reopened ]

jobs:
  triage:
    runs-on: ubuntu-latest
    name: Label issues
    steps:
      - name: check out
        uses: actions/checkout@v3

      - name: labeler
        uses: jbinda/super-labeler-action@develop
        with:
          GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

从代码中可以看出这是一个关于问题的CI。我的要求是,当问题有标签时,CI将不会被执行,或者CI中的作业或步骤可以被跳过。
希望有人能回答,谢谢。
1个回答

0

如果您想在已包含标签的问题上触发 GitHub Actions 执行工作流程时跳过它,可以使用 if 语法 检查 label 事件上下文变量

name: "Labeler"
on:
  issues:
    types: [ opened, edited, reopened ]
jobs:
  triage:
    # check if the issue has no label set 
    if: github.event.issue.labels.length == 0
    runs-on: ubuntu-latest
    name: Label issues
    steps:
      - name: check out
        uses: actions/checkout@v3
      - name: labeler
        uses: jbinda/super-labeler-action@develop
        with:
          GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

如果你只想跳过特定的标签,那么在if语句中使用contains()表达式

if: !contains(github.event.issue.labels.*.name, 'skip')

如果触发问题被标记为skip标签,则此工作流将被跳过。

顺便提一下: 我不建议使用第三方jbinda/super-labeler-action操作,因为我们在GH市场上有一个官方的super-labeler-action


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接