From 89b7f4f3efd39580b0b0a4ad896b3699870895a6 Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Wed, 24 Apr 2024 14:00:46 +0200 Subject: [PATCH] feat(kb/lefthook): use remote config --- .lefthook.yml | 11 ++++--- knowledge base/lefthook.md | 64 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 4 deletions(-) diff --git a/.lefthook.yml b/.lefthook.yml index 2decdc7..9c92c91 100644 --- a/.lefthook.yml +++ b/.lefthook.yml @@ -37,10 +37,13 @@ lint: # ini: &pyinilint # FIXME # run: pyinilint 'file' md: &markdownlint - glob: "*.md" - run: >- # '{all_files}' and {files} only include ones managed by git for some reason + 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' - **.md + {files} yaml: &yamllint glob: "*.{yaml,yml}" run: >- @@ -87,7 +90,7 @@ pre-commit: <<: *hadolint run: hadolint {staged_files} lint-md: - <<: *markdownlint + glob: '*.{markdown,md}' run: >- docker run --rm -v "$PWD:/workdir" 'ghcr.io/igorshubovych/markdownlint-cli:latest' {staged_files} diff --git a/knowledge base/lefthook.md b/knowledge base/lefthook.md index a0fcadf..f9ec1ba 100644 --- a/knowledge base/lefthook.md +++ b/knowledge base/lefthook.md @@ -2,6 +2,8 @@ 1. [TL;DR](#tldr) 1. [Configuration](#configuration) + 1. [Extend other files](#extend-other-files) + 1. [Use files from other repositories](#use-files-from-other-repositories) 1. [Further readings](#further-readings) 1. [Sources](#sources) @@ -66,6 +68,68 @@ $ ls -A1 *lefthook* Configuration files can extend other files recursively. +### Extend other files + +```yaml +extends: + - .lefthook/commitlint.yml + - .lefthook/docker.yml + - .lefthook/json.yml +``` + +### Use files from other repositories + +Refer the [configuration] page. + +Use the `remotes` key to include configuration files from this repository.
+The configuration from remotes will be merged to the local config using the following priority: + +- Local main config (`lefthook.yml`). +- Remote configs (`remotes`). +- Local overrides (`lefthook-local.yml`). + +```yaml +# lefthook.yml +lint: + parallel: true + commands: + yaml: + glob: "*.{yaml,yml}" + run: >- + docker run --rm -v "$PWD:/code" 'registry.gitlab.com/pipeline-components/yamllint:latest' + yamllint {all_files} +remotes: + - git_url: https://gitlab.com/mine/oam.git + ref: main + configs: + - quality-assurance/lefthook/commitlint.yml + - quality-assurance/lefthook/docker.yml + - quality-assurance/lefthook/json.yml +``` + +```yaml +# lefthook-local.yml +no_tty: false +lint: + commands: + yaml: + run: .venv/bin/yamllint {all_files} +``` + +```sh +$ lefthook dump +… +lint: + commands: + docker: + run: hadolint {all_files} + glob: "*[Dd]ockerfile*" + yaml: + run: .venv/bin/yamllint {all_files} + glob: "*.{yaml,yml}" + parallel: true +``` + ## Further readings - [Github]