🐈

actions/checkoutでgit configが上書きされるってマジ?

に公開

マジである。READMEにもちゃんと書いてある。

https://github.com/actions/checkout

The auth token is persisted in the local git config. This enables your scripts to run authenticated git commands. The token is removed during post-job cleanup. Set persist-credentials: false to opt-out.

GitHub Actions内で発生したイベントで別のGitHub Actionsを発火したい 場合、デフォルトのトークン以外でイベントを発火すればいいので(なぜか) actions/checkout にカスタムトークンを指定すれば良いというハックは有名だが、これは actions/checkout がgit configを書き換えることが原因だったのだ。

いいわけあるか

もちろん persist-credentials: false を指定すればconfigが他に波及しないのだが、あまりにも暗黙的すぎる振る舞いではないだろうか。

GitHub App Installation Tokenの登場で特殊な処理を行いたい場合[1]には適切な権限を持たせたGitHub Appのトークンで処理するのがベストプラクティスになっているので、その場でtokenを渡してgit configを書き換えるGitHub Actionsが欲しいなと感じた。

そのうち作るので作ったら追記する。

脚注
  1. 例えば、最近ではbranch protectを無視してpushをしたいというケースがあった ↩︎

Discussion