Tweak builderrors script for git hooks
Build error checks can be configured locally. We need to leverage
builderrors script and create a new check.
Developers push to server and CI runner shares the build error report. Build error checks can be configured
Some might have configured
htmllint etc. to run before commits but are in isolation. We need teams to adopt such practices and it should be easy to configure.
What I tried
- Configured my local machine with the instructions including cloning
- In a project directory, ran
monitor/builderrors. The script didn't ignore
- I'd like teams to configure
builderrorsscript as a
builderrorsscript to be run as a pre-commit hook. without any YAML configuration.
pre-commit is a useful utility to configure script sanity checks via git hooks.
It relies on a
.pre-commit-config.yaml config where checks are spelt out. Sample configuration below:
# See https://pre-commit.com for more information # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v2.0.0 hooks: - id: trailing-whitespace description: This hook trims trailing whitespace. - id: end-of-file-fixer description: Ensures that a file is either empty or ends with one newline. - id: check-yaml description: This hook checks yaml files for parseable syntax. - id: check-added-large-files description: Prevent giant files from being committed. Defaults to 500kB. - id: pretty-format-json description: This hook sets a standard for formatting JSON files. args: [--indent=2, --no-sort-keys] - id: flake8 description: This hook runs flake8.
Note that minimal working config is only 5 lines (
id). This works well.
- install pre-commit:
pip install pre-commit
.pre-commit-config.yamlwith critical checks, in root directory of project
- In terminal, run:
pre-commit install. This will create a
.git/is not version controlled.
pre-commit runs before every commit. To test,
- In terminal, run:
pre-commit run --all-files. This will validate the config file.
- Change a file (introduce a bug, example add a
JSfile) and run:
git commit. Commit should fail. Fix the bug and re-commit. Commit should succeed.