11

My team uses Pre-commit in our repositories to run various code checks and formatters. Most of my teammates use it but some skip it entirely by committing with git commit --no-verify. Is there anyway to run something in CI/CD to ensure all Pre-commit hooks pass (we're using GitHub actions). If at least one hooks fails, then throw an error.

anthony sottile
  • 61,815
  • 15
  • 148
  • 207
Johnny Metz
  • 5,977
  • 18
  • 82
  • 146

1 Answers1

24

There are several choices:

  • an adhoc job which runs pre-commit run --all-files as demonstrated in pre-commit.com docs (you probably also want --show-diff-on-failure if you're using formatters)
  • pre-commit.ci a CI system specifically built for this purpose
  • pre-commit/action a github action which is in maintenance-only mode (not recommended for new usecases)

disclaimer: I created pre-commit, and pre-commit.ci, and the github action

anthony sottile
  • 61,815
  • 15
  • 148
  • 207