[Alpha] Plugin for pre-commit caching and installation

Based on the answer to How to cache both pre-commit and Hugo I have created netlify-plugin-pre-commit which handles installing pre-commit hooks and caching them (for faster builds when the cache is ‘hot’).

I welcome any comments, issues, or PRs on it’s GitHub repository.

I hope this proves useful.

Be warned, it is currently alpha, although I have started using it.

Hi @danielfdickinson1 this is awsome! Thank’s for sharing this with the community!! :netliheart:

1 Like

I have written a blog post with more information on using the plugin Netlify pre-commit and other news

One other thing (that I need to add to the post and documentation) is that you need a requirements.txt that includes pre-commit so that Netlify’s build auto-installs the needed Python packages:

e.g.:

argcomplete==3.0.8
cfgv==3.3.1
distlib==0.3.6
filelock==3.12.0
identify==2.5.24
nodeenv==1.8.0
platformdirs==3.5.1
pre-commit==3.3.2
virtualenv==20.23.0

FYI I’ve issued a new version of the NPM package and have made a GitHub prerelease release as I have solved issues related to async, as well as a workaround for cache.save omitting empty directories breaks pre-commit on restore · Issue #5030 · netlify/build · GitHub (assuming I was not fooled by the async issues and the workaround isn’t needed, just correctly serializing certain actions).

In any event it now seems to work properly, though it’s still experimental (alpha). Fortunately, I’ve been ‘dogfooding’ else I wouldn’t have realized the issue so quickly.