如何在设置特定标签时不运行 GitHub Action?

问题描述 投票:0回答:3

我有一个 GitHub Action 工作流程,在打开 Pull 请求时始终运行以部署 React-Native Expo 应用程序的预览。但是,我不希望它在 dependentabot 打开 Pull 请求时运行。

如何过滤 dependentabot Pull 请求?我看到有一个标签

dependencies
,但我无法让标签被过滤。

我尝试过的一些尝试:

name: Preview
on:
  pull_request:
    types: [opened, synchronize]
jobs:
  preview:
    if: ${{ !contains(github.event.pull_request.labels.*.name, '0 diff dependencies') }}
name: Preview
on:
  pull_request:
    types: [opened, synchronize]
jobs:
  preview:
    if: "!contains(github.event.pull_request.labels.*.name, '0 diff dependencies')"
name: Preview
on:
  pull_request:
    types: [opened, synchronize]
jobs:
  preview:
    if: "!contains(github.event.pull_request.labels.*.name, '0 dependencies')"
name: Preview
on:
  pull_request:
    types: [opened, synchronize]
jobs:
  preview:
    if: github.event.label.name != 'dependencies'
name: Preview
on:
  pull_request:
    types: [opened, synchronize]
jobs:
  preview:
    if: ${{ github.event.label.name != 'dependencies' }}

如果需要,您可以在这里找到存储库。

label github-actions workflow pull-request dependabot
3个回答
4
投票

github.event.pull_request.labels
是一个数组,因此您可以为其第一个元素建立索引。假设 dependentabot 只会分配一个标签,这应该没问题:

name: Preview
on:
  pull_request:
    types: [opened, synchronize]
jobs:
  preview:
    if: github.event.pull_request.labels[0].name != 'dependencies'

我刚刚在虚拟存储库上测试了它,当 PR 标签匹配时它跳过了我的操作。


2
投票

嗯,实际上,有一个问题。有时,dependabot 在创建拉取请求后添加标签。

但是,要解决这个问题,可以按用户过滤:

name: Verification
on:
  push:
    branches:
      - main
  pull_request:
    types: [opened, synchronize, reopened]

jobs:
  verification:
    if: contains(github.actor, 'dependabot') == false

0
投票

如果第一次提交的作者姓名是 dependentabot,我最终会忽略作业

on:
  push:
    branches:
    - master

jobs:
  publish:
    runs-on: ubuntu-latest
    if: ${{ github.event.commits[0].author.name != 'dependabot[bot]' }}
    ...
© www.soinside.com 2019 - 2024. All rights reserved.