There are several choices:
- an adhoc job which runs
pre-commit run --all-filesas demonstrated in pre-commit.com docs (you probably also want--show-diff-on-failureif 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
Answer from anthony sottile on Stack OverflowVideos
So, I generally use commits as a saving mechanism, but after adding a linting and formatting pre-commit hook, I do find myself committing less often. While this does help me catch syntax errors, and I guess I could argue that my commits are cleaner, this does seem to be a bit inconvenient. I think part of it is breaking the mold of what I'm used to, but I also wonder if I would be more productive if I moved it to a pre-push, or even to part of my CI pipeline (running before my tests). Does anyone have any recommendations?
I’d make it part of merge checks.
Can’t merge unless all the requirements are OK, if formatting/linting are requirements then it’s nice to see failed checks and know what requires fixing.
Why not both? Provide the tools to run it as a pre-commit hook and require the checks to pass for each PR.