refactor(lefthook): slice config file into dedicated config files

This commit is contained in:
Michele Cereda
2024-08-22 19:48:57 +02:00
parent 8c9639efd6
commit e6d2c4e30e
13 changed files with 223 additions and 85 deletions

View File

@@ -6,104 +6,37 @@ skip_output:
- skips
extends:
- lefthook/ansible.yml
- lefthook/commitlint.yml
- lefthook/docker.yml
- lefthook/json.yml
- lefthook/kics.yml
- lefthook/markdown.yml
- lefthook/yaml.yml
bootstrap:
parallel: true
commands:
commitlint:
run: npm install --save-dev '@commitlint/cli' '@commitlint/config-conventional'
venv:
run: make create-venv
debug:
parallel: true
commands:
commitlint-config:
glob: '.commitlintrc.js'
run: node_modules/.bin/commitlint --print-config
lint:
parallel: true
commands:
ansible: &ansible-lint
files: find . -type f -path "*ansible*" -not -path "*venv*"
glob: '*.{yaml,yml}'
run: .venv/bin/ansible-lint {files}
docker: &hadolint
# The official docker image is based on scratch and only takes only one
# input file at a time. I have no clue how to fix that for now so let's
# just use the local command.
glob: "*Dockerfile*"
run: hadolint {all_files}
# ini: &pyinilint # FIXME
# run: pyinilint 'file'
md: &markdownlint
files: >-
find . -type 'f'
\( -name '*.md' -or -name '*.markdown' \)
-not \( -path '*/node_modules/*' -or -path '*/venv/*' \)
run: >-
docker run --rm -v "$PWD:/workdir" 'ghcr.io/igorshubovych/markdownlint-cli:latest'
{files}
yaml: &yamllint
glob: "*.{yaml,yml}"
run: >-
docker run --rm -v "$PWD:/code" 'registry.gitlab.com/pipeline-components/yamllint:latest'
yamllint {all_files}
# commands:
# ini: &pyinilint # FIXME
# run: pyinilint 'file'
validate:
parallel: true
commands:
ansible-playbook: &ansible-playbook-syntax-check
ansible-playbook:
glob: "*ansible*/play*.{yaml,yml}"
run: .venv/bin/ansible-playbook -i localhost, --syntax-check {all_files}
json: &jq
# No official docker image available for now, falling back to the local
# command.
glob: '*.json'
run: jq -r 'input_filename' {all_files}
yaml: &yq
# Python's one, not mikefarah's.
# No official docker image available for now, falling back to the local
# command.
glob: '*.{yaml,yml}'
run: >-
echo '{all_files}'
| xargs -t .venv/bin/yq '.'
pre-commit:
parallel: true
commands:
validate-json:
<<: *jq
run: jq -r 'input_filename' {staged_files}
validate-yaml:
<<: *yq
run: >-
.venv/bin/yq '.' {staged_files} > /dev/null
&& echo 'All YAML files are readable'
validate-ansible-playbooks:
<<: *ansible-playbook-syntax-check
lint-ansible:
<<: *ansible-lint
lint-docker:
<<: *hadolint
run: hadolint {staged_files}
lint-md:
glob: '*.{markdown,md}'
run: >-
docker run --rm -v "$PWD:/workdir" 'ghcr.io/igorshubovych/markdownlint-cli:latest'
{staged_files}
lint-yaml:
<<: *yamllint
run: >-
docker run --rm -v "$PWD:/code" 'registry.gitlab.com/pipeline-components/yamllint:latest'
yamllint {staged_files}
commit-msg:
commands:
lint: &commitlint
# No official docker image available for now, falling back to the local
# command.
run: node_modules/.bin/commitlint --edit