1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

GitHubActionsでPullRequestが必要なワークフローを作ろうとした時にハマった事

Posted at

はじめに

個人で作っているReactアプリの変更をpushした際、GitHubActionsを使って自動でビルドしてGitHubPagesにデプロイするまでを自動化しようとした際、エラーが発生したのでその解決までをメモする

発生したエラー

/usr/bin/git push origin gh-pages
remote: Permission to xxx/yyy.git denied to github-actions[bot].
fatal: unable to access 'https://github.com/xxx/yyy.git/': The requested URL returned error: 403
Error: Action failed with "The process '/usr/bin/git' failed with exit code 128"

エラーから読み取れるのは

  • pushする際に403エラーが出ている
  • リポジトリの認証周りに問題がありそう?

仮説

初めに怪しいと思ったのは、どこからともなく入っているトークン周りで、一体どこから出てきたんだと言わんばかりのここが怪しいと思い、調べたところ問題ないらしい

github_token: ${{ secrets.GITHUB_TOKEN }}

各ワークフロー実行の開始時に、GitHub によって、ワークフローで使用する一意の GITHUB_TOKEN シークレットが自動的に作成されます。 GITHUB_TOKEN はワークフロー実行での認証に使用できます。

正式らしくて便利としか。すばらしい。

解決方法

結局、GitHubActions用のパーミッションをGitHubの設定から変更すれば解決した。
デフォルトだとRead repository contents and packages permissionsにチェックがついていてRead権限のみなので、Writeも許可するように変更する。するとpushが完了した。

/usr/bin/git push origin gh-pages
Everything up-to-date

image.png

おわりに

CI/CDの構築はいろんな罠が潜むので、しっかりエラーログを見ることが大切。それと、デフォルトはRead権限のみだと覚えておく。

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?