github-actions[bot]无权限访问。请求的URL返回错误:403

25
我希望使用Github Actions将文件推送到当前仓库。我编写了一个基本配置,使用官方 actions/checkout@v3 操作。我的配置与 readme示例 几乎相同。
name: Example
on: workflow_dispatch
jobs:
  example:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - shell: bash
        run: |
          date > 1.txt
          git config user.name github-actions
          git config user.email github-actions@github.com
          git add 1.txt
          git commit -m updated
          git push

这个配置对于任何仓库都有效,除了 Github Pages 仓库。错误信息如下:

remote: Permission to sirekanian/sirekanian.github.io.git denied to github-actions[bot].
fatal: unable to access 'https://github.com/sirekanian/sirekanian.github.io/': The requested URL returned error: 403
Error: Process completed with exit code 128.

为什么GitHub Pages存储库与普通存储库不同?GitHub Pages存储库是否具有不允许推送的不同权限?
我找到的最相似的问题是如何让github actions工作流使用机器人名称将生成的文档推送到同一组织中的其他存储库。答案是使用令牌,但我认为我应该使用默认令牌。
2个回答

33

你需要配置你的代码库 - 设置 -> 操作 -> 通用 -> 工作流权限,并选择读写权限


3
对于使用组织存储库的人来说,组织的设置可能会有所不同。我在那里进行了更改,现在它可以正常工作了。 - undefined
请记住,这将更改此存储库中所有工作流程的默认设置。您可能想要的是,为此工作流程提供更细粒度的权限,并且仅允许其写入content(其中包括标签)。因此,我建议使用其他答案来设置permissions - undefined

9

看起来 GitHub Pages 仓库具有不同的默认权限设置。如果您添加了一个权限以写入内容,您就可以使用 GitHub 检出操作将内容推送到您的存储库:

name: Example
on: workflow_dispatch
permissions:
  contents: write
jobs:
  # your push job here

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接