我有一个托管在GitHub组织中的私有GitHub存储库。回购包含一个带有GitHub选项(cf )的workflow_dispatch
操作。GitHub文档)。
摘要摘自Action文件:
on:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
我可以从GitHub Actions选项卡成功地触发此操作。
但是,我希望能够通过对POST
API的GitHub请求触发此操作。使用GitHub API应该是可能的。相关的API端点似乎是/repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches
,如文档中所描述的。
这些文件还指出:
要使用此端点,必须使用带repo作用域的访问令牌进行身份验证。
因此,在“开发人员设置”→“个人访问令牌”下的个人帐户设置中,我创建了一个令牌,并授予了对所有“回购”项以及“工作流”项的访问权。
我已经测试了通过使用GitHub和邮递员发出POST
请求来触发curl
操作。为此,我按照GitHub文档使用以下参数
accept
:application/vnd.github.v3+json
(按GitHub推荐)owner
:GitHub重组的名称repo
:存储库的名称workflow_id
:使用GitHub Action文件的完整文件名(包括find,.yml
),因为我不确定在哪里找到ID。ref
:main
,因为我认为这是指相关的存储库分支(?)而且回购程序只有一个main
分支,操作驻留在那里使用来自curl
的文档示例(但向其添加身份验证):
curl -X POST -H "Accept: application/vnd.github.v3+json" \
-u GITHUBUSERNAME:GITHUBPERSONALACCESSTOKEN \
https://api.github.com/repos/ORGNAME/REPONAME/actions/workflows/YMLFILE/dispatches \
-d '{"ref":"main"}'
我得到以下结果:
{
"message": "Problems parsing JSON",
"documentation_url": "https://docs.github.com/rest/reference/actions#create-a-workflow-dispatch-event"
}
我还测试了从POST
发出来自邮递员的curl
请求(通过导入上述curl
语句)。这产生了完全相同的结果。
curl
声明错了吗?发布于 2021-06-07 20:09:41
按照这个指令https://goobar.dev/manually-trigger-a-github-actions-workflow/,您可能做的大部分是正确的。
尝试使用curl -H "Accept: application/vnd.github+json" -H "Authorization: token your-token" --request POST --data '{"event_type": "do-something"}' https://api.github.com/repos/yourname/yourrepo/dispatches
在LINUX上运行它。
在Windows上: cURL POST命令在Windows提示符上不工作,因为使用单引号(参见https://github.com/spring-guides/gs-accessing-data-rest/issues/11 )
发布于 2021-06-07 21:51:00
还有一个储存库调度行动可以为您执行此操作(不管操作系统如何,都可以使用这个Github服务分派一个事件)。
使用
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v1
with:
token: ${{ secrets.REPO_ACCESS_TOKEN }}
event-type: my-event
https://stackoverflow.com/questions/67876177
复制相似问题