检查套件完成后如何触发 Github 工作流程?

How to trigger Github Workflow after a check suite finishes?

我只想在特定工作流完成时触发工作流...有人知道该怎么做吗?

一些上下文:

还有事件 check_suite 它应该触发工作流:https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows#check-suite-event-check_suite

我试过这个例子:

on:
  check_suite:
    types: [rerequested, completed]

但我的工作流程从未触发,有什么想法是为什么?或者关于如何实现上述目标的任何其他想法?

通常你会使用steps。 "build" 步骤只有在前面的 "Test" 步骤成功时才会执行。

如果您真的需要通过作业对其进行建模,那么您可以使用 needs

示例:

jobs:
  job1:
  job2:
    needs: job1
  job3:
    needs: [job1, job2]

check_suite 事件仅由(外部)集成触发,例如 Netlify 构建。注意:如果您的工作流已经合并到您的默认分支(master),该事件也只会被触发。

更新的答案:

事实证明,您可以使用 on: status 事件实现该目的,但您需要使用非 the one from the Github Actions.

的令牌手动触发状态

您需要添加类似这样的内容才能在工作流完成后触发状态事件:

      - name: Trigger status event
        run: >-
          curl -L -X POST 
          -H "Content-Type: application/json"
          -H "Authorization: token ${{ secrets.GITHUB_PAT}}"
          -d '{
            "state": "success",
            "target_url": "https://you-can-add-a.url/",
            "description": "All tests passed", "context": "your-custom/status-event"
          }'
          "https://api.github.com/repos/${GITHUB_REPOSITORY}/statuses/${GITHUB_SHA}"

并且在您的其他工作流程中,您可以添加一个 if 条件,以防您有多个状态事件可以触发该工作流程,如下所示:

on: status

...

jobs:

...

  if: github.event.context == 'your-custom/status-event'

就是这样...这就是您可以链接工作流的方式。



旧答案:

好吧,在 github.community 论坛上提问后我得到了答案。

Events raised from the Actions app do not trigger workflows. This restriction is currently in place in order to prevent a circular workflow execution.

相关链接:

编辑: 这同样适用于 check 事件。