如何使用 gh cli 通过调度触发 github 操作

How to trigger github actions with dispatch using gh cli

我有一个包含以下 yaml 的操作:

on:
  workflow_dispatch:
    inputs:
      BuildTarget:
        description: "Targets to rebuild. Set to all to rebuild everything."
        required: false
        default: ""

我可以触发的是:

gh api /repos/:owner/:repo/actions/workflows/build_dev.yml/dispatches -F ref=":branch"

但我似乎无法弄清楚如何将输入从 cli 传递到操作中。

我试过:

gh api /repos/:owner/:repo/actions/workflows/build_dev.yml/dispatches -F ref=":branch" -F BuildTarget=all

这告诉 "BuildTarget" is not a permitted key. (HTTP 422)

并尝试这样做:

gh api /repos/:owner/:repo/actions/workflows/build_dev.yml/dispatches -F ref=":branch" -F inputs='{ "BuildTarget": "all" }'

给我 For 'properties/inputs', "{ \"BuildTarget\": \"all\" }" is not an object. (HTTP 422)

知道如何从 cli 中调用这个 api 并将输入属性传递给工作流吗?

您可以直接使用 --input - 发送原始正文以从标准输入读取:

gh api /repos/:owner/:repo/actions/workflows/build_dev.yml/dispatches \
   --input - <<< '{"ref":"master","inputs":{"BuildTarget":"all"}}'

结帐this documentation