GitHub Actions部署GitHub Pages报错exit code 128权限问题咨询
GitHub Actions部署GitHub Pages时403权限错误原因分析
问题场景
使用GitHub Actions将项目发布到GitHub Pages时,执行Deploy步骤出现如下错误:
Action failed with "The process '/usr/bin/git' failed with exit code 128"
详细日志显示权限被拒绝:
Run peaceiris/actions-gh-pages@v3 [INFO] Usage https://github.com/peaceiris/actions-gh-pages#readme Dump inputs Setup auth token Prepare publishing assets Setup Git config Create a commit Push the commit or tag /usr/bin/git push origin gh-pages remote: Permission to RedDwarfTech/blog.poemhub.top.git denied to jiangxiaoqiang. fatal: unable to access 'https://github.com/RedDwarfTech/blog.poemhub.top.git/': The requested URL returned error: 403 Error: Action failed with "The process '/usr/bin/git' failed with exit code 128"
对应的Workflow配置如下:
name: Pages on: push: branches: - main # default branch jobs: pages: runs-on: ubuntu-latest permissions: contents: write steps: - uses: actions/checkout@v3 with: token: ${{ secrets.REPO_TOKEN }} # If your repository depends on submodule, please see: https://github.com/actions/checkout submodules: false - name: Use Node.js 16.x uses: actions/setup-node@v2 with: node-version: '16' - name: Cache NPM dependencies uses: actions/cache@v2 with: path: node_modules key: ${{ runner.OS }}-npm-cache restore-keys: | ${{ runner.OS }}-npm-cache - name: Install Dependencies run: npm install - name: Build run: npm run build - name: Deploy uses: peaceiris/actions-gh-pages@v3 with: github_token: ${{ secrets.REPO_TOKEN }} publish_dir: ./public
错误原因分析
- Token权限不足:当前使用的
REPO_TOKEN(无论组织还是个人类型)未被授予目标仓库的写入权限。日志明确显示用户jiangxiaoqiang没有权限推送到RedDwarfTech组织下的仓库,说明Token对应的身份没有仓库推送权限。 - 组织Token配置问题:从提供的组织Token权限配置来看,需确认是否勾选了
repo权限组(包含public_repo、repo:status等子权限)——推送到gh-pages分支必须具备仓库内容的写入权限,缺少该权限会直接触发403错误。 - Token归属与仓库权限不匹配:
- 若使用组织Token:需确保该Token是在
RedDwarfTech组织下创建,且被分配了目标仓库的写入权限,同时Token权限范围包含contents: write。 - 若使用个人Token:需确认
jiangxiaoqiang账号是RedDwarfTech组织仓库的成员,且拥有仓库推送权限(如管理员、写入权限角色),同时个人Token勾选了repo权限。
- 若使用组织Token:需确保该Token是在
- Workflow权限无法覆盖Token限制:虽然Workflow中设置了
permissions: contents: write,但该配置仅作用于GitHub Actions的临时权限,无法突破Token本身的权限范围。
解决建议
- 检查Token权限:无论是组织还是个人Token,必须确保包含
repo(私有仓库)或public_repo(公开仓库)权限,且目标仓库允许该Token对应的身份进行推送操作。 - 确认Token归属:组织Token需关联到目标组织,个人Token需确保账号在组织仓库中拥有合法的写入权限。
- 更新仓库Secrets:将仓库的
REPO_TOKEN替换为权限验证通过的Token,重新触发Workflow测试。
内容的提问来源于stack exchange,提问作者Dolphin
相关产品推荐
相关产品推荐

