なんでもノート

なんでも書くノートみたいなブログ

GitHub ActionsからGitHubへpushできないエラー

GitHub Actionsで以下のエラーが出た。

Push the commit or tag
  /usr/bin/git push origin master
  remote: Permission to azujuuuuuun/azujuuuuuun.github.io.git denied to github-actions[bot].
  fatal: unable to access 'https://github.com/azujuuuuuun/azujuuuuuun.github.io.git/': The requested URL returned error: 403
  Error: Action failed with "The process '/usr/bin/git' failed with exit code 128"

権限がなくGitHub Actionsからpushが拒否されたよう。直前のPRで権限を変更したので心当たりがあった。

https://github.com/azujuuuuuun/azujuuuuuun.github.io/blob/d38acc9466d01ec004d861427e285597055db0a4/.github/workflows/continuous-delivery-workflow.yml#L13-L15

    permissions:
      contents: "read"
      id-token: "write"

このpermissionsはgoogle-github-actions/authを元に設定した。Assigning permissions to jobs - GitHub Docsによると

これらのスコープのいずれかのアクセスを指定した場合、指定されたなかったものはすべてnoneに設定されます。

だそうだ。つまり、このpermissionsの設定によってどれかのスコープにnoneが設定されて書き込み権限がなくなったか、contents: "read" によって書き込み権限がなくなったかのどちらかが原因だとわかった。

スコープと対応するアクセス権限はPermissions required for GitHub Apps - GitHub Docsにあった。Git操作のアクセス権はcontentsスコープだったので contents: "write" に変更したら解決した。