您需要在此处使用具有工作流程权限的个人访问令牌,而不是GITHUB_TOKEN
它有一个明确的范围。
实际上,这只是发生了变化(2022 年 9 月 8 日):
GitHub 操作:使用GITHUB_TOKEN with workflow_dispatch and repository_dispatch https://github.blog/changelog/2022-09-08-github-actions-use-github_token-with-workflow_dispatch-and-repository_dispatch/
客户现在可以使用GITHUB_TOKEN
with workflow_dispatch
and repository_dispatch
触发工作流程的事件。
在此更改之前,触发的事件GITHUB_TOKEN
不会创建新的工作流程运行。这样做是为了防止意外触发无休止的工作流程。
此更新有一个例外workflow_dispatch
and repository_dispatch
事件,因为它们是客户发出的显式调用,不太可能最终陷入循环。
name: Create Workflow Dispatch
on: workflow_dispatch:
jobs: build:
runs-on: ubuntu-latest
steps:
- name: Trigger Workflow
uses: actions/github-script@v6
with:
script: |
github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'test.yml',
ref: 'main',
})
欲了解更多详情,请参阅
从工作流触发工作流 https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#triggering-a-workflow-from-a-workflow.
So GITHUB_TOKEN
现在可能可以工作了。
在OP问题的上下文中:这里的主要任务是从另一个工作流程中修改工作流程文件。
我上面提到的最近的 GitHub 更改允许使用以下命令触发工作流程GITHUB_TOKEN
,但没有明确提及是否可以使用令牌直接将更改推送到工作流文件。这种能力可以解决最初的问题。
您仍然需要修改工作流程以提交更改并将更改推送到工作流程文件。您尝试更新工作流程文件的操作步骤如下所示:
- name: Update the other Action
run: |
# Do something to .github/workflows/the-other-action.yaml here
git config --local user.email "[email protected] /cdn-cgi/l/email-protection"
git config --local user.name "GitHub Action"
git add .github/workflows/the-other-action.yaml
git commit -m "Update the other Action"
git push
您需要使用具有必要权限的令牌来推送更改,并且可以使用更新后的功能来测试它GITHUB_TOKEN
:
随着peter-evans/create-pull-request@v3
行动,那就是:
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: some-branch
commit-message: Updated stuff