相关疑难解决方法(0)

如何从 Github API 触发“workflow_dispatch”?

GH Rest API 文档来看,我们似乎能够创建一个repository_dispatch事件,但没有workflow_dispatch创建事件。在GH GraphQL API中,我找不到如何调度事件。

是否可以workflow_dispatch使用 API 触发事件?

github github-api github-actions

18
推荐指数
2
解决办法
2万
查看次数

使用 POST 请求触发 Github 操作(Github REST API)

我有一个托管在 GitHub 组织中的私有 GitHub 存储库。\n该存储库包含带有选项的 GitHub 操作workflow_dispatch\n(参见GitHub 文档)。

\n

操作 YAML 文件摘录:

\n
on:\n  # Allows you to run this workflow manually from the Actions tab\n  workflow_dispatch:\n\njobs:\n  build:\n    runs-on: ubuntu-latest\n
Run 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
\n

因此,在我的个人帐户设置中的“开发人员设置”\xe2\x86\x92“个人访问令牌”下,\n我创建了一个令牌并授予对所有“存储库”项以及“工作流”项的访问权限。

\n

我已测试通过使用PostmanPOST发出请求来触发 GitHub Action 。\n为此,我根据\n GitHub 文档使用以下参数:curl

\n
    \n
  • accept:(application/vnd.github.v3+json根据 …

rest curl github github-actions

9
推荐指数
1
解决办法
2万
查看次数

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

我使用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的正确请求?

github-actions

2
推荐指数
1
解决办法
4958
查看次数

标签 统计

github-actions ×3

github ×2

curl ×1

github-api ×1

rest ×1