从GH Rest API 文档来看,我们似乎能够创建一个repository_dispatch事件,但没有workflow_dispatch创建事件。在GH GraphQL API中,我找不到如何调度事件。
是否可以workflow_dispatch使用 API 触发事件?
我有一个托管在 GitHub 组织中的私有 GitHub 存储库。\n该存储库包含带有选项的 GitHub 操作workflow_dispatch\n(参见GitHub 文档)。
操作 YAML 文件摘录:
\non:\n # Allows you to run this workflow manually from the Actions tab\n workflow_dispatch:\n\njobs:\n build:\n runs-on: ubuntu-latest\nRun Code Online (Sandbox Code Playgroud)\n我可以从 GitHub Actions 选项卡成功触发此操作。
\n不过,我希望能够通过POST对 GitHub API 的请求来触发此操作。\n这应该可以使用 GitHub API 实现。\n相关的 API 端点似乎如\n文档/repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches中所述。
该文件进一步指出:
\n\n\n您必须使用具有存储库范围的访问令牌进行身份验证才能使用此端点。
\n
因此,在我的个人帐户设置中的“开发人员设置”\xe2\x86\x92“个人访问令牌”下,\n我创建了一个令牌并授予对所有“存储库”项以及“工作流”项的访问权限。
\n我已测试通过使用PostmanPOST发出请求来触发 GitHub Action 。\n为此,我根据\n GitHub 文档使用以下参数:curl
accept:(application/vnd.github.v3+json根据 …我使用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的正确请求?