Github Actions: 在非草稿PR上运行工作流程

3

我有一个工作流文件,希望它在非草稿PR和每次新提交到PR时运行。

到目前为止,我尝试了两种方法:

  1. 使用if语句
name: Test

on:
  pull_request:
    branches:
      - master

jobs:
  test:
    if: github.event.pull_request.draft == false
    runs-on: ubuntu-latest

当 PR 转换为准备好进行审核时,这不会触发工作流。

  1. 使用类型声明
name: Test

on:
  pull_request:
    branches:
      - master
    types:
      - ready_for_review

jobs:
  test:
    runs-on: ubuntu-latest

当新的提交推送到PR时,这不会触发工作流程。

我该如何添加条件,以便我的工作流在非草稿PR和所有新提交上运行?


这个回答解决了你的问题吗?仅在非草稿拉取请求上运行操作 - Michael Freidgeim
2个回答

7
在你的第一个代码块中,你将 types 保留为默认值(openedsynchronizereopened)。 在第二个代码块中,你只使用了 ready_for_review 类型。
你可以将它们合并起来:
name: Test

on:
  pull_request:
    types:
      - opened
      - synchronize
      - reopened
      - ready_for_review

jobs:
  test:
    if: github.event.pull_request.draft == false
    # You could have ths version too - note the  single quotes:
    # if: '! github.event.pull_request.draft'
    name: Check PR is not a Draft
    runs-on: ubuntu-latest
    steps:
      - run: |
          echo "Non-draft Pull request change detected"

1

这与另一个问题类似。

其他问题中的答案建议使用

if: ! github.event.pull_request.draft

为了检查PR是否是草稿,因为在GitHub Actions中可能会出现布尔类型混淆。


不,这不是另一个问题的副本,因为我的提供的语句也很好用。但是,它没有涵盖当PR类型更改为READY_FOR_REVIEW时的情况。我测试了打开一个非草稿PR并将另一个PR从草稿转换为准备好进行审查。 - Harun Sasmaz
好的,抱歉。我看到这不是重复的。让我编辑我的答案。 - Marc Leibold

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