From d4a031b2c37c844dc7661cb3816f1812e98d79df Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Sat, 17 Feb 2024 19:54:22 +0100 Subject: [PATCH] refactor(management): add hadolint to lefthook's hook --- .lefthook.yml | 25 ++++++++++++++++++++----- knowledge base/lefthook.md | 7 ++++++- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/.lefthook.yml b/.lefthook.yml index 9d13062..087817c 100644 --- a/.lefthook.yml +++ b/.lefthook.yml @@ -1,21 +1,36 @@ +assert_lefthook_installed: true no_tty: true 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}" run: >- docker run --rm -v "$PWD:/code" 'registry.gitlab.com/pipeline-components/yamllint:latest' - yamllint '.' + yamllint {all_files} pre-commit: parallel: true commands: + hadolint: + <<: *hadolint + run: hadolint {staged_files} yamllint: <<: *yamllint + run: >- + docker run --rm -v "$PWD:/code" 'registry.gitlab.com/pipeline-components/yamllint:latest' + yamllint {staged_files} -# commit-msg: -# commands: -# commitlint: -# run: commitlint --edit +commit-msg: + commands: + commitlint: + # No official docker image available for now, falling back to the local + # command. + run: commitlint --edit diff --git a/knowledge base/lefthook.md b/knowledge base/lefthook.md index 0558b2e..a0fcadf 100644 --- a/knowledge base/lefthook.md +++ b/knowledge base/lefthook.md @@ -37,13 +37,15 @@ lefthook add -dv 'commit-msg' # Execute groups of hooks. lefthook run 'pre-push' lefthook run -v 'lint' --all-files -lefthook run 'pre-commit' -n --commands 'lint' --files 'lefthook.yml' +lefthook run 'pre-commit' -n --commands 'hadolint' --files 'lefthook.yml' # Remove configured hooks from the current git repository. lefthook uninstall lefthook uninstall -cv ``` +Uses the [glob library] for glob patterns. + ## Configuration Configuration files can be written in JSON, TOML or YAML.
@@ -93,3 +95,6 @@ All the references in the [further readings] section, plus the following: [configuration]: https://github.com/evilmartians/lefthook/blob/master/docs/configuration.md [github]: https://github.com/evilmartians/lefthook [lefthook: knock your team's code back into shape]: https://evilmartians.com/chronicles/lefthook-knock-your-teams-code-back-into-shape + + +[glob library]: https://github.com/gobwas/glob