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

Xot*_*otl 3 continuous-integration github continuous-deployment devops github-actions

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

一些背景:

  • 我有一个工作流程Tests,另一个称为Build-feature.
  • Tests我在每个 PR 到分支上运行我的工作流程feature
  • 如果某些内容被推送/合并到分支feature,那么我想运行工作流程Tests,并且只有当成功时我才想运行Build-feature工作流程。

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

我尝试了这个例子:

on:
  check_suite:
    types: [rerequested, completed]
Run Code Online (Sandbox Code Playgroud)

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

Xot*_*otl 5

更新的答案:

事实证明,您可以使用on: status事件来实现这一目标,但您需要使用不是来自 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}"
Run Code Online (Sandbox Code Playgroud)

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

on: status

...

jobs:

...

  if: github.event.context == 'your-custom/status-event'
Run Code Online (Sandbox Code Playgroud)

就是这样...这就是您如何链接工作流程。



旧答案:

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

从操作应用程序引发的事件不会触发工作流程。当前存在此限制是为了防止循环工作流程执行。

相关链接:

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