【问题标题】:How to trigger a `workflow_dispatch` from Github API?如何从 Github API 触发“workflow_dispatch”?
【发布时间】:2022-01-06 02:56:37
【问题描述】:

GH API v3 (REST) docs,似乎我们能够创建repository_dispatch 事件,但没有workflow_dispatch 事件。在GH API v4 (GraphQL),我找不到如何调度事件。

甚至可以使用 API 触发 workflow_dispatch 事件吗?

【问题讨论】:

    标签: github github-actions github-api


    【解决方案1】:

    是的,可以通过手动通过 Github API

    手动(通过您的存储库上的 Actions 选项卡。)

    Here is an official documentation about it

    基本上,一旦您在选项卡上选择了工作流,如果工作流实现有 workflow_dispatch 触发器,则选项Run workflow 将出现在窗口的右侧,如下所示:

    使用 Github API

    在Github官方文档上有服务create a workflow dispatch event

    这是一个 curl 示例:

    curl \
      -X POST \
      -H "Accept: application/vnd.github.v3+json" \
      https://api.github.com/repos/octocat/hello-world/actions/workflows/42/dispatches \
      -d '{"ref":"main"}'
    

    请注意,您也可以通过此 API 发送工作流 inputs

    您还可以找到有关此in this article 的更多参考资料。

    还有另一个 Github API 服务来触发repository_dispatch events

    奖金

    如果您希望通过终端命令行触发workflow_dispatch 事件(和repository_dispatch 事件),您可以使用this automation in Python。可以在in this class找到实现。

    【讨论】:

    • 感谢您展示了如何使用 UI 来触发工作流。不过,问题是如何使用 API 来实现。
    • 我的错。这也是可能的!我编辑了答案。
    猜你喜欢
    • 2022-08-18
    • 2022-11-10
    • 2020-11-12
    • 2022-01-17
    • 2022-06-10
    • 1970-01-01
    • 2021-08-24
    • 1970-01-01
    • 2020-10-24
    相关资源
    最近更新 更多