如何查明触发当前工作流程的 Github Actions 事件是否是新的拉取请求?

gvl*_*sov 12 github-actions building-github-actions github-actions-workflows

我有一个启动的 Github Actions 工作流程:

on:
  pull_request:
    types:
      - synchronize
      - opened
Run Code Online (Sandbox Code Playgroud)

运行我的自定义操作:

jobs:
  my_job:
    uses: "org/repo/.github/workflows/main.yml@master"
Run Code Online (Sandbox Code Playgroud)

在操作中org/repo,我想在打开拉取请求时执行额外的操作,但不在同步时执行。所以我这样org/repo/.github/workflows/main.yml做:

- if: ${{ condition }}
  name: Do that additional thing
Run Code Online (Sandbox Code Playgroud)

应该如何condition区分新打开的拉取请求事件和“同步”事件(推送新提交等)?我想这将涉及检查一些内容,但我在文档${{ github.event.pull_request }}中找不到它。

gvl*_*sov 18

条件是:

- if: ${{ github.event_name == 'pull_request' && github.event.action == 'opened' }}
Run Code Online (Sandbox Code Playgroud)

  • 通过添加更多有关代码的作用以及它如何帮助操作员的信息,可以改进您的答案。 (3认同)