From 1a6f8e8485e779fca15d5b256a4f8a7cfae488fd Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Thu, 29 Feb 2024 22:09:14 +0100 Subject: [PATCH] chore(repository): pre-commit hooks maintenance --- .lefthook.yml | 49 +++++++++++++++++++++++++++---------------------- .yamllint.yaml | 2 +- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/.lefthook.yml b/.lefthook.yml index 1d476cc..10e2195 100644 --- a/.lefthook.yml +++ b/.lefthook.yml @@ -4,7 +4,22 @@ no_tty: true skip_output: - meta - skips - - execution_out + + +lint: + parallel: true + commands: + 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} + yaml: &yamllint + glob: "*.{yaml,yml}" + run: >- + docker run --rm -v "$PWD:/code" 'registry.gitlab.com/pipeline-components/yamllint:latest' + yamllint {all_files} validate: parallel: true @@ -12,39 +27,29 @@ validate: json: &jq # No official docker image available for now, falling back to the local # command. - glob: "*.json" - run: jq -c '.' {all_files} + 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: yq -c '.' {all_files} - -lint: - parallel: true - commands: - hadolint: &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} - yamllint: &yamllint - glob: "*.{yaml,yml}" + glob: '*.{yaml,yml}' run: >- - docker run --rm -v "$PWD:/code" 'registry.gitlab.com/pipeline-components/yamllint:latest' - yamllint {all_files} + echo '{all_files}' + | xargs -t yq '.' + pre-commit: parallel: true commands: validate-json: <<: *jq - run: jq -c '.' {staged_files} + run: jq -r 'input_filename' {staged_files} validate-yaml: <<: *yq - run: yq -c '.' {staged_files} + run: >- + yq '.' {staged_files} > /dev/null + && echo 'All YAML files are readable' lint-docker: <<: *hadolint run: hadolint {staged_files} @@ -59,4 +64,4 @@ commit-msg: commitlint: # No official docker image available for now, falling back to the local # command. - run: commitlint -c '.commitlintrc.js' --edit + run: commitlint --edit diff --git a/.yamllint.yaml b/.yamllint.yaml index 393427d..97b910d 100644 --- a/.yamllint.yaml +++ b/.yamllint.yaml @@ -1,6 +1,6 @@ --- # See https://yamllint.readthedocs.io/en/stable/configuration.html for -# more information +# more information. extends: default