GoReleaserでハマったところ
GoでCLIを書いたらgithub actionsで自動的にビルドしてリリースしてしまいたい。
GoReleaser を使えばYAMLファイル一枚で簡単にできる!という解説がいっぱい見つかるのでそれらを見ながらやってみたけどいくつかハマったのでメモを残しておく。
main.goがルートディレクトリにない場合
リポジトリルートに main.go (package main) をレイアウトしてない場合は、以下のような内容を含む .goreleaser.yaml
ファイルをルートディレクトリに置いて設定をカスタムする必要がある。
builds:
- main: ./path/to/cmddir
403 Resource not accessible でこける
以下のようなエラーが出る場合
publishing
• scm releases
• creating or updating release repo=bayashi/go-edge tag=v0.1.8
⨯ release failed after 17s error=scm releases: failed to publish artifacts: could not release: POST https://api.github.com/repos/bayashi/go-edge/releases: 403 Resource not accessible by integration []
Error: The process '/opt/hostedtoolcache/goreleaser-action/1.17.2/x64/goreleaser' failed with exit code 1
エラーメッセージは error=scm releases: failed to publish artifacts: could not release
で、 403 Resource not accessible
と言われているので権限が足りないっぽい。
scm releases
というのは、今回はgithub actionsでgithubでリリースしようとしてるので、githubでの権限の話であると。
GoReleaserのドキュメント によると、secrets.GITHUB_TOKEN
の代わりに Personal Access Token (PAT) を発行して設定せよと書いてある。
言われた通りに PAT を発行(repoのread/write権限だけあればOK)して secretに設定して実行すると、するっと通ってしまう。
しかし、リポジトリごとに PAT を都度設定するのは面倒くさい。一般的には secrets.GITHUB_TOKEN
で通るようなのでどこかにその設定があるはず。
Workflow permissions
リポジトリの Settings > Actions > General と遷移して、Workflow permissions
の項目に設定がある。
おそらく、read権限の方になっているので、Read and write permissions
の方に設定を変える。
ぱわー