Github 分派工作流无效请求
Github dispatches workflow Invalid request
我正在尝试触发 Github 中的工作流事件。
出于某种原因,我能够获取有关我的组织存储库工作流程的信息,但无法使用“/dispatches”
工作基于:https://docs.github.com/en/rest/actions/workflows#create-a-workflow-dispatch-event
这里是 curl 代码:
curl -X POST \
-H "Accept:application/vnd.github.v3+json" \
-H 'Authorization:token ${{ github.token }}' \
'https://api.github.com/repos/[owner/org]/[repo]/actions/workflows/9999999/dispatches' \
-d '{"event_type":"semantic-release"}'
获取错误:
422 Unprocessable Entity
"message": "Invalid request.\n\nFor 'links/0/schema', nil is not an object.",
"documentation_url": "https://docs.github.com/rest/reference/repos#create-a-repository-dispatch-event"
我是否遗漏了一些基本信息才能正常工作并触发事件?
与其尝试直接调用 GitHub API,不如尝试使用 GitHub CLI gh
(that you can install first 在本地进行测试。
你也可以use GitHub CLI in workflows.
GitHub CLI is preinstalled on all GitHub-hosted runners.
For each step that uses GitHub CLI, you must set an environment variable called GITHUB_TOKEN to a token with the required scopes
它有一个 gh workflow run
,它确实为给定的工作流程创建了一个 workflow_dispatch
事件。
首先进行身份验证(gh auth login
,如果您正在进行本地测试):
# authenticate against github.com by reading the token from a file
$ gh auth login --with-token < mytoken.txt
示例:
# Run the workflow file 'triage.yml' at the remote's default branch
$ gh workflow run triage.yml
# Run the workflow file 'triage.yml' at a specified ref
$ gh workflow run triage.yml --ref my-branch
# Run the workflow file 'triage.yml' with command line inputs
$ gh workflow run triage.yml -f name=scully -f greeting=hello
# Run the workflow file 'triage.yml' with JSON via standard input
$ echo '{"name":"scully", "greeting":"hello"}' | gh workflow run triage.yml --json
你的情况(GitHub 操作):
jobs:
push:
runs-on: ubuntu-latest
steps:
- run: gh workflow run triage.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
如 hanayama in 所述:
Found out the secrets. GITHUB_TOKEN
doesn't work, even with permissions edited for the entire workflow.
Using a personal access token worked.
我正在尝试触发 Github 中的工作流事件。
出于某种原因,我能够获取有关我的组织存储库工作流程的信息,但无法使用“/dispatches”
工作基于:https://docs.github.com/en/rest/actions/workflows#create-a-workflow-dispatch-event
这里是 curl 代码:
curl -X POST \
-H "Accept:application/vnd.github.v3+json" \
-H 'Authorization:token ${{ github.token }}' \
'https://api.github.com/repos/[owner/org]/[repo]/actions/workflows/9999999/dispatches' \
-d '{"event_type":"semantic-release"}'
获取错误:
422 Unprocessable Entity
"message": "Invalid request.\n\nFor 'links/0/schema', nil is not an object.",
"documentation_url": "https://docs.github.com/rest/reference/repos#create-a-repository-dispatch-event"
我是否遗漏了一些基本信息才能正常工作并触发事件?
与其尝试直接调用 GitHub API,不如尝试使用 GitHub CLI gh
(that you can install first 在本地进行测试。
你也可以use GitHub CLI in workflows.
GitHub CLI is preinstalled on all GitHub-hosted runners.
For each step that uses GitHub CLI, you must set an environment variable called GITHUB_TOKEN to a token with the required scopes
它有一个 gh workflow run
,它确实为给定的工作流程创建了一个 workflow_dispatch
事件。
首先进行身份验证(gh auth login
,如果您正在进行本地测试):
# authenticate against github.com by reading the token from a file
$ gh auth login --with-token < mytoken.txt
示例:
# Run the workflow file 'triage.yml' at the remote's default branch
$ gh workflow run triage.yml
# Run the workflow file 'triage.yml' at a specified ref
$ gh workflow run triage.yml --ref my-branch
# Run the workflow file 'triage.yml' with command line inputs
$ gh workflow run triage.yml -f name=scully -f greeting=hello
# Run the workflow file 'triage.yml' with JSON via standard input
$ echo '{"name":"scully", "greeting":"hello"}' | gh workflow run triage.yml --json
你的情况(GitHub 操作):
jobs:
push:
runs-on: ubuntu-latest
steps:
- run: gh workflow run triage.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
如 hanayama in
Found out the secrets.
GITHUB_TOKEN
doesn't work, even with permissions edited for the entire workflow.
Using a personal access token worked.