使用客户端有效负载正确请求在 github 操作中运行工作流程_调度

Ant*_*sev 2 github-actions

我使用workflow_dispatch 创建简单的github 操作。

name: Run Workflow Dispatch

on: 
  workflow_dispatch:
    inputs:
      version:
        description: 'version'     
        required: true
        default: 'latest'

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout
      uses: actions/checkout@v2

    - run: |
        echo "version: ${{ github.event.inputs.version }}"
Run Code Online (Sandbox Code Playgroud)

我通过curl 创建请求。

curl -X POST \
  -H "Accept: application/vnd.github.everest-preview+json" \
  -H "Authorization: token xxxxxxxxx" \
  https://api.github.com/repos/patsevanton/workflow-dispatch-client-payload/actions/workflows/workflow_dispatch.yml/dispatches \
  --data '{"event_type": "my-dispatch", "client_payload": {"ref": "main"}}'
Run Code Online (Sandbox Code Playgroud)

但我收到错误:

{
  "message": "Invalid request.\n\n\"client_payload\", \"event_type\" are not permitted keys.\n\"ref\" wasn't supplied.",
  "documentation_url": "https://docs.github.com/rest/reference/actions#create-a-workflow-dispatch-event"
}
Run Code Online (Sandbox Code Playgroud)

如何在github操作中创建正确的workflow_dispatch?如何在github操作中创建对workflow_dispatch的正确请求?

Gui*_*urd 6

您似乎混淆了 Github Actions 上提供的 2 个工作流触发事件。

workflow_dispatch事件repository_dispatch


创建工作流调度事件

要远程触发workflow_dispatch事件,您需要使用以下端点:

https://api.github.com/repos/{owner}/{repository}/actions/workflows/{workflow_id}/dispatches
Run Code Online (Sandbox Code Playgroud)

这是Github上的相关文档

请注意,您可以将主体与此 POST 服务一起使用,通知最终的inputs


创建存储库调度事件

要远程触发repository_dispatch事件,您需要使用以下端点:

https://api.github.com/repos/{owner}/{repository}/dispatches
Run Code Online (Sandbox Code Playgroud)

这是Github上的相关文档

在这种情况下,您可以使用client_payload参数以及event_type参数。


结论

在您的情况下,您似乎希望使用工作流调度端点存储库调度事件client_payload(这不是此端点上的可用参数)的混合来触发工作流调度事件。

因此,如果您想触发工作流,第一个选项是使用存储库调度事件来触发您的工作流,更新工作流文件中的工作流触发器以使用repository_dispatch而不是workflow_dispatch使用curl 命令调用的端点。

另一种选择是使用curl 命令调用另一个端点(与 相关的命令workflow dispatch而不是与 相关的命令repository dispatch,通知inputs参数而不是client_payload参数。