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

Har*_*maz 3 yaml github-actions

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

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

  1. 使用 if 语句
name: Test

on:
  pull_request:
    branches:
      - master

jobs:
  test:
    if: github.event.pull_request.draft == false
    runs-on: ubuntu-latest
Run Code Online (Sandbox Code Playgroud)

当 PR 转换为可供审核时,这不会触发工作流程。

  1. 使用类型声明
name: Test

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

jobs:
  test:
    runs-on: ubuntu-latest
Run Code Online (Sandbox Code Playgroud)

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

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

小智 7

在第一个代码块中,将 保留types为默认值(opened, synchronize& reopened)。在第二个代码块中,您仅使用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"
Run Code Online (Sandbox Code Playgroud)