|
| 1 | +================ |
| 2 | +Pre-commit Hooks |
| 3 | +================ |
| 4 | + |
| 5 | +StackHPC Kayobe configuration carries support for |
| 6 | +`pre-commit hooks <https://pre-commit.com/>`_ which simplify the use of git |
| 7 | +hooks enabling the identification and repairing of broken or poor code |
| 8 | +before committing. |
| 9 | +These hooks are designed to make working within SKC easier and less error prone. |
| 10 | + |
| 11 | +Currently the following hooks are provided: |
| 12 | + |
| 13 | +- ``check-yaml``: perform basic yaml syntax linting |
| 14 | +- ``end-of-file-fixer``: identify and automatically fix missing newline |
| 15 | +- ``trailing-whitespace``: identify and automatically fix excessive white space |
| 16 | +- ``ripsecrets``: identify and prevent secrets from being committed to the branch |
| 17 | + |
| 18 | +.. warning:: |
| 19 | + The hook ``ripsecrets`` is capable of preventing the accidental leaking of secrets |
| 20 | + such as those found within `secrets.yml` or `passwords.yml`. |
| 21 | + However if the secret is contained within a file on it's own and lacks a certain level |
| 22 | + of entropy then the secret will not be identified as such as and maybe leaked as a result. |
| 23 | + |
| 24 | +Installation of `pre-commit` hooks is handled via the `install-pre-commit-hooks` playbook |
| 25 | +found within the Ansible directory. |
| 26 | +Either use `kayobe playbook run` or add the playbook as a hook within Kayobe config such as |
| 27 | +within `control-host-bootstrap/post.d`. |
| 28 | +Once done you should find `pre-commit` is available within the `kayobe` virtualenv. |
| 29 | + |
| 30 | +All that remains is the installation of the hooks themselves which can be accomplished either by |
| 31 | +running `pre-commit run` or using `git commit` when you have changes that need to be committed. |
| 32 | +This will trigger a brief installation process of the hooks which may take a few minutes. |
| 33 | +This a one time process and will not be required again unless new hooks are added or existing ones are updated. |
| 34 | + |
| 35 | +.. note:: |
| 36 | + Currently if you run ``pre-commit run --all-files`` it will make a series of changes to |
| 37 | + release notes that lack new lines as well configuration files that ``check-yaml`` does not |
| 38 | + approve of. |
0 commit comments