Add dedicated pre-commit job
pre-commit
is a tool that runs checks and fixes locally, giving very fast feedback. When using it we also want to run it in the CI to ensure everyone is running it locally (or manually running the checks/fixes) and that merge events don't break rules (e.g. auto-merges can break black
formatting).
Running it as it's own job is beneficial for developer feedback as the checks are in the seconds range unlike tests which tend to be in the minutes range.
This is (soon to be) running in the lab allocator project and this MR shows the current job in .gitlab-ci.yml
:
- (MR) https://gitlab.developers.cam.ac.uk/uis/devops/laboratory-allocator/lab-allocator/-/merge_requests/7
- (file) https://gitlab.developers.cam.ac.uk/uis/devops/laboratory-allocator/lab-allocator/-/blob/df091145f9e7d77ccb0ebd91b5671afe704a20ec/.gitlab-ci.yml
Notable desirable changes from the lab allocator job:
- pre-built docker image (see CMD in the MR)
- ideally runs in the
test
stage but starts immediately and isn't blocked by thebuild
phase. See this thread: https://gitlab.developers.cam.ac.uk/uis/devops/laboratory-allocator/lab-allocator/-/merge_requests/7#note_466834 - conditionally run when
.pre-commit-config
present using theexists
rule
.
I would also suggest moving the contents of the current .gitlab-ci.yml
in the web boilerplate into a new file in ci-templates
named something like python-ci.yml
. The boilerplate can then just call include:... python-ci.yml
and we can pin that include
to a major version.