如何在 github 操作条件中检查标签



假设我有一个这样的github操作:

name: My Action
on:
pull_request:
types:
- closed
jobs:
myjob:
runs-on: ubuntu-latest
name: Test
if: github.event.pull_request.merged && XXX

我想在这里有一个条件来测试标签的存在。

从文档中看,使用contains( github.event.pull_request.labels, 'my_label')似乎不合适,因为它是字典而不是数组。

有什么办法吗?

终于找到了:

contains( github.event.pull_request.labels.*.name, 'My Label')

我从上面Denis Rouzaud的答案中汲取灵感,并将其应用于问题。它工作得很好,可以帮助我管理由外部系统(使用 API(创建的问题的项目自动化:

jobs:
issue_opened:
name: issue_opened
runs-on: ubuntu-latest
if: |
contains(github.event.issue.labels.*.name, '<My first label>') ||
contains(github.event.issue.labels.*.name, '<My second label>')

最新更新