kro*_*c97 9 rest curl github github-actions
我有一个托管在 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根据 GitHub 推荐)owner: GitHub \xc3\xb5rganization 的名称repo: 存储库名称workflow_id:使用 GitHub Action YAML 文件的完整文件名(包括结尾.yml),因为我不确定在哪里可以找到 ID。ref: main,因为我认为这是指相关的存储库分支(?),并且存储库只有一个main分支并且操作驻留在那里使用文档curl中的示例(但添加身份验证):
curl -X POST -H "Accept: application/vnd.github.v3+json" \\\n -u GITHUBUSERNAME:GITHUBPERSONALACCESSTOKEN \\\n https://api.github.com/repos/ORGNAME/REPONAME/actions/workflows/YMLFILE/dispatches \\\n -d \'{"ref":"main"}\'\nRun Code Online (Sandbox Code Playgroud)\n我得到以下结果:
\n{\n "message": "Problems parsing JSON",\n "documentation_url": "https://docs.github.com/rest/reference/actions#create-a-workflow-dispatch-event"\n}\nRun Code Online (Sandbox Code Playgroud)\nPOST我还测试了从Postman发出请求(通过导入上述curl语句)。\n这会产生完全相同的结果。
curl说法有错吗?小智 10
按照此说明https://goobar.dev/manually-trigger-a-github-actions-workflow/你可能做的大部分都是正确的
尝试在 LINUX 上运行它
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
在 Windows 上:cURL POST 命令在 Windows 命令提示符上不起作用,因为使用单引号,请参阅https://github.com/spring-guides/gs-accessing-data-rest/issues/11
| 归档时间: |
|
| 查看次数: |
15837 次 |
| 最近记录: |