GitHub Actions生成3D贡献图时git push返回403权限错误
针对你用yoshi389111/github-profile-3d-contrib生成3D贡献图时遇到的403权限问题,给你几个针对性的排查和解决步骤:
确认ACCESS_TOKEN的类型与权限
别用仓库默认的GITHUB_TOKEN,它的权限是受限的,必须用个人访问令牌(PAT)。创建PAT时直接勾选repo权限组(包含所有仓库相关操作权限),确保这个令牌能访问你的目标仓库。然后在仓库的「Settings → Secrets and variables → Actions」里添加这个PAT,命名严格和Workflow里的ACCESS_TOKEN一致。修正Workflow中的git推送配置
推送时必须用PAT做身份认证,不能用默认的git地址。在Workflow的push步骤里,把推送URL改成带令牌的格式:- name: Push updated 3D graph run: | git config --global user.name "github-actions[bot]" git config --global user.email "github-actions[bot]@users.noreply.github.com" git add . git commit -m "Update 3D contribution graph" git push https://${{ secrets.ACCESS_TOKEN }}@github.com/${{ github.repository }}.git HEAD:main注意把
main换成你仓库的实际默认分支名(比如master)。检查分支保护规则
如果你的目标分支开了分支保护(比如必须通过PR合并、需要审核),就算有PAT也直接push失败。去仓库「Settings → Branches → Branch protection rules」找到对应分支的规则,在「Allow specified actors to bypass required pull requests」里添加github-actions[bot]或者PAT对应的用户账号。验证PAT的有效性
检查PAT是否过期(创建时如果选了有效期,到期会失效),再确认PAT的权限列表里确实包含repo下的所有子权限,别漏选了关键权限项。
如果你的错误日志是类似下面的内容:
remote: Permission to xxx/xxx.git denied to github-actions[bot].
fatal: unable to access 'https://github.com/xxx/xxx.git/': The requested URL returned error: 403
那上面的步骤应该能解决问题。
内容的提问来源于stack exchange,提问作者Ahmad Mujtaba

