動かざることバグの如し

近づきたいよ 君の理想に

GitHub Actionsでgit差分がある時のみコミットする方法

環境

  • actions/checkout@v3

やりたいこと

GitHub ActionsでCI実行後にgit差分があればコミット&pushする。

なければそのまま終了する

どういうとき使うのかって言うと自動定期アップデートとか

コード

- name: Commit updated files
  run: |
    git config core.filemode false
    if ! git diff --exit-code --quiet
    then
      git add -A
      git config user.name thr3a
      git config user.email thr3a@example.com
      git commit -m "Commit updated files"
      git push
    fi