[求助] github action: Permission to git denied to github-actions

讨论 未结 11 46
Doragd
Doragd 会员 2022年4月26日 11:47 发表
<p>各位 v 友好,我最近在学习 github actions, 但是不清楚为啥会在自动 push 的时候报错~ 就是 push 到当前 repo 的 main 分支的时候报错了 我也搜索了相关的 issue ,但是还是没法解决: <a href="https://github.com/ad-m/github-push-action/issues/96" rel="nofollow">https://github.com/ad-m/github-push-action/issues/96</a></p> <p>特来求助各位呜呜呜</p> <p>我的报错信息是:</p> <pre><code>Push to branch main remote: Permission to ... denied to github-actions[bot]. fatal: unable to access '...': The requested URL returned error: 403 Error: Invalid exit code: 128 at ChildProcess.&lt;anonymous&gt; (/home/runner/work/_actions/ad-m/github-push-action/master/start.js:29:21) at ChildProcess.emit (events.js:314:20) at maybeClose (internal/child_process.js:1022:16) at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5) { code: 128 } Error: Invalid exit code: 128 at ChildProcess.&lt;anonymous&gt; (/home/runner/work/_actions/ad-m/github-push-action/master/start.js:29:21) at ChildProcess.emit (events.js:314:20) at maybeClose (internal/child_process.js:1022:16) at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5) </code></pre> <p>配置文件如下:</p> <pre><code class="language-yml">name: learn env: PYTHON_VERSION: '3.8' # set this to the Python version to use on: issues: types: - labeled jobs: learning: runs-on: ubuntu-latest permissions: issues: write steps: - uses: actions/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7c1f14191f171309083c0a4e">[email&nbsp;protected]</a> with: persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token. fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository. ... - name: Commit files run: | git config --local user.email "github-actions[bot]@users.noreply.github.com" git config --local user.name "github-actions[bot]" git commit -m "Add changes" -a - name: Push changes uses: ad-m/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="492e203d213c2b64393c3a2164282a3d2026270924283a3d2c3b">[email&nbsp;protected]</a> with: github_token: ${{ secrets.GITHUB_TOKEN }} </code></pre>
收藏(0)  分享
相关标签: 灌水交流
注意:本文归作者所有,未经作者允许,不得转载
11个回复
  • imzcg2
    2022年4月26日 11:47
    GITHUB_TOKEN ,你配置了吗,不会配百度啊
    0 0
  • Doragd
    2022年4月26日 11:47
    我以为这个 GITHUB_TOKEN 是一个上下文变量来着呜呜呜,我懂了,是要去 secrets 里面添加是吧
    0 0
  • ch2
    2022年4月26日 11:47
    试试用这个,首先生成一个 token 填到 settings->secrets 里,取名为 action_token - name: GitHub push run: | git config --global user.email "" git config --global "js-deliver" git config --global github.user js-deliver git config --global github.token $GITHUB_TOKEN git remote add publish https://你的用户名:/你的用户名 /你的仓库名 /.git git checkout --orphan publish git commit -m "Auto commit version $version" git config -l | grep 'http\..*\.extraheader' | cut -d= -f1 | xargs -L1 git config --unset-all git push --force https://你的用户名:/你的用户名 /你的仓库名 /.git publish:main env: GITHUB_TOKEN: ${{ secrets.action_token }}
    0 0
  • imzcg2
    2022年4月26日 11:47
    随便百度一个教程都会教你这样做
    0 0
  • Doragd
    2022年4月26日 11:47
    谢谢您!!我现在明白了,之前确实自己没有去百度~用的谷歌,自己英文比较菜,没有很好地描述好问题,可能就没检索到,谢谢!
    0 0
  • Doragd
    2022年4月26日 11:47
    谢谢您!我试试啦~
    0 0
  • Doragd
    2022年4月26日 12:18
    @ 您刚才说的应该是 PAT ?我看到文档里面写到:At the start of each workflow run, GitHub automatically creates a unique GITHUB_TOKEN secret to use in your workflow. You can use the GITHUB_TOKEN to authenticate in a workflow run. 我想问问这不是自动创建的吗?
    0 0
  • AoEiuV020CN
    2022年4月26日 12:18
    GITHUB_TOKEN 是有自动创建的,但有些限制,比如无法修改 workflows 相关,或者是有其他限制触发了,
    0 0
  • Doragd
    2022年4月26日 12:18
    谢谢您回复,我就是修改了 repo 的一些文件,然后 commit ,然后想 push 到这个 repo 来应用更改~这样也没有权限吗呜呜呜
    0 0
  • Doragd
    2022年4月26日 12:18
    @ @ 谢谢大家的帮忙,我发现是我自己忘记把 contents 的 permission 设置为 write 了~呜呜呜真抱歉给大家造成麻烦~(当然 GITHUB_TOKEN 确实是不用配置的~TUT
    0 0
  • imzcg2
    2022年4月26日 12:18
    我的本意是让你去搜索一下这个文档,结果我替你收搜了,用哪个搜索引擎不重要,黑猫白猫能抓到就行
    0 0