diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..7430626 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,44 @@ +--- +name: Report a bug +about: Found something broken? Let us know! If it's not yet reproducible, +please `Ask a question` instead. +labels: 'bug' +--- + + +### Summary + + + +### Lefthook version + + + +### Steps to reproduce + + + +### Expected results + + + +### Actual results + + + +### Possible Solution + + + +### Logs / Screenshots + + + +```bash +LEFTHOOK_VERBOSE=true git ... +``` + + diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..7f07d38 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,4 @@ +# SPDX-FileCopyrightText: Copyright Boozt Fashion, AB +# SPDX-License-Identifier: MIT +--- +blank_issues_enabled: false diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..3ada22e --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Want to add a new hook or improve it? Create a feature request! +labels: 'feature request' +--- + + +### Summary + + + +### Value + + + +### Behavior and configuration changes + + + + diff --git a/.github/issue_template.md b/.github/issue_template.md deleted file mode 100644 index 70f0361..0000000 --- a/.github/issue_template.md +++ /dev/null @@ -1,28 +0,0 @@ - - - -Thank you for taking the time to submit an issue! Your contribution is valuable to us. Before you proceed, please take a moment to go through the checklist below: - -### Checklist - -- [ ] Have you attempted to debug or fix the issue yourself? Bug fixes and documentation improvements are always welcome. -- [ ] Have you checked if a similar issue has already been created? -- [ ] Do you have an idea for a new feature? If so, please label your issue with "enhancement". - - -If none of the above apply, you may proceed to create a new bug report. Please provide the following information to help us address the issue effectively: - -### Bug Report Details - -- **Description**: Describe the issue in detail. -- **Steps to Reproduce**: Provide a clear and concise description of the steps to reproduce the issue. -- **Expected Behavior**: Describe what you expected to happen. -- **Actual Behavior**: Describe what actually happened. -- **Version**: Specify the version of the software you are using. -- **Operating System**: Specify the OS and version you are using (e.g., Mac, Linux, Windows). -- **Labels**: Use `bug` and `help wanted`. - - -Feel free to include any additional information such as code snippets, links, screenshots, or any other relevant facts that may help in diagnosing and resolving the issue. - -Thank you for your contribution to our project! diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index baef864..b969ada 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,19 +1,17 @@ -- **Description**: -- **Current Behavior**: -- **New Behavior**: -- **Breaking Changes**: -- **Type of Change**: + - -### Additional Information +#### Summary -Please provide any additional information or context that may be relevant to this pull request. + -Thank you for your contribution to our project! ---> +#### Checklist + +- [ ] Check locally +- [ ] Add tests +- [ ] Add documentation + + diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9e789c3..d63cc20 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,8 +1,9 @@ # SPDX-FileCopyrightText: Copyright Boozt Fashion, AB # SPDX-License-Identifier: MIT +--- name: Release -on: +"on": push: branches: - 'main' diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 1986bbe..66b31bd 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -3,12 +3,13 @@ # For more information about the configuration file, see: # https://goreleaser.com/customization/build/ - +--- builds: - # By default we don't let to release packages. Our consideration is to use SemVer - # based by conventional commits to release new versions of the project once it's - # merged to the main branch. If this is a Go project, you can remove this section - # and use the default configuration to release the packages within the new version. + # By default we don't let to release packages. Our consideration is to use + # SemVer based by conventional commits to release new versions of the project + # once it's merged to the main branch. If this is a Go project, you can + # remove this section and use the default configuration to release the + # packages within the new version. - skip: true checksum: diff --git a/.lefthook.yaml b/.lefthook.yaml index fad3a8f..b6ec6ad 100644 --- a/.lefthook.yaml +++ b/.lefthook.yaml @@ -1,12 +1,14 @@ # SPDX-FileCopyrightText: Copyright Boozt Fashion, AB # SPDX-License-Identifier: MIT - +--- extends: # lint commit messages based by the conventional commits - hooks/commitlint/.lefthook.yaml - # lint Dockerfiles - - hooks/hadolint/.lefthook.yaml # lint shell scripts - hooks/shellcheck/.lefthook.yaml # check if the license headers are present in the files - hooks/license-checker/.lefthook.yaml + # lint the markdown (.md) files + - hooks/markdown-lint/.lefthook.yaml + # lint the yaml (.yml, .yaml) files + - hooks/yamllint/.lefthook.yaml diff --git a/.lefthook/pre-commit/license-checker.sh b/.lefthook/pre-commit/license-checker.sh index f972014..dcee5c6 100755 --- a/.lefthook/pre-commit/license-checker.sh +++ b/.lefthook/pre-commit/license-checker.sh @@ -4,19 +4,22 @@ # SPDX-License-Identifier: MIT # Script is a pre-commit hook to check if the staged files -# has the license header from the file license-header.txt (we only check if it's contains). +# has the license header from the file license-header.txt or the +# environment variable called LICENSE_HEADER (we only check if +# it's contains). set -eo pipefail -# include .license-checker file if exists in the root directory -if [ -f .license-checker ]; then - # shellcheck source=/dev/null - source .license-checker -fi - -EXCLUDE_FILES_EXT=${EXCLUDE_FILES_EXT:-"LICENSE|\\.md|\\.gitignore|\\.license-checker|CODEOWNERS|\\.gitattributes|\\.editorconfig|\\.json|\\.lock|\\.toml"} +LICENSE_HEADER=${LICENSE_HEADER:-""} +EXCLUDE_FILES_EXT=${EXCLUDE_FILES_EXT:-"LICENSE|\\.md|\\.gitignore|\\.license-checker.txt|CODEOWNERS|\\.gitattributes|\\.editorconfig|\\.json|\\.lock|\\.toml"} STAGED_FILES=$(git diff --name-only --diff-filter=d --staged) +# read .license-checker.txt file if exists in the root directory +if [[ -f .license-checker.txt && -z "$LICENSE_HEADER" ]]; then + # read the file and set the LICENSE_HEADER variable + LICENSE_HEADER=$(cat .license-checker.txt) +fi + # error message function printing in red color # usage: error "message" error() { @@ -27,7 +30,7 @@ error() { # if the LICENSE_HEADER is empty, then exit if [ -z "$LICENSE_HEADER" ]; then error "The LICENSE_HEADER environment variable is empty." - error "Either create .license-checker file in the root directory or set the LICENSE_HEADER environment variable." + error "Either create .license-checker.txt file in the root directory or set the LICENSE_HEADER environment variable." exit 1 fi diff --git a/.license-checker b/.license-checker.txt similarity index 71% rename from .license-checker rename to .license-checker.txt index 57691ef..22a7f14 100644 --- a/.license-checker +++ b/.license-checker.txt @@ -1,5 +1,2 @@ -LICENSE_HEADER=$(cat < [][homepage] [![GitHub Tag (latest SemVer)](https://img.shields.io/github/v/tag/boozt-platform/lefthook.svg?label=latest&sort=semver)][releases] [![license](https://img.shields.io/badge/license-mit-brightgreen.svg)][license] + # lefthook -Various organizational hooks based on the [lefthook](https://github.com/evilmartians/lefthook) for development and continuous integration. Hooks enforce consistent practices across all commits and deployments. +Various organizational hooks based on the [lefthook](https://github.com/evilmartians/lefthook) +for development and continuous integration. Hooks enforce consistent practices +across all commits and deployments. ## Table of Contents @@ -18,7 +22,12 @@ Various organizational hooks based on the [lefthook](https://github.com/evilmart ## How to Use It +Create a new file `.lefthook.yaml` in your project's root folder and use the +example content below: + ```yaml +# .lefthook.yaml +--- remotes: - git_url: git@github.com:boozt-platform/lefthook ref: v1.2.0 @@ -31,28 +40,52 @@ remotes: - hooks/shellcheck/.lefthook.yaml # check if the license headers are present in the files - hooks/license-checker/.lefthook.yaml + # lint the markdown (.md) files + - hooks/markdown-lint/.lefthook.yaml + # A linter for YAML files. + - hooks/yamllint/.lefthook.yaml + # validate the JSON files + - hooks/jsonlint/.lefthook.yaml ``` +Run `lefthook install` (follow the [installation guide](https://github.com/evilmartians/lefthook/blob/master/docs/install.md) +if the lefthook command is not present on the system). + ## Available Hooks - - [commitlint](./hooks/commitlint/) (**commit-msg**) - Lint commit messages based by the conventional commits - - [hadolint](./hooks/hadolint/) (**pre-commit**) - A smarter Dockerfile linter - - [shellcheck](./hooks/shellcheck/) (**pre-commit**) - a static analysis tool for shell scripts - - [license-checker](./hooks/license-checker/) (**pre-commit**) - Checks if the license headers are present in the Git staged files with possibility to exclude certain files or file extensions using Regular Expression pattern. +- [commitlint](./hooks/commitlint/) (**commit-msg**) - Lint commit messages +based by the conventional commits +- [hadolint](./hooks/hadolint/) (**pre-commit**) - A smarter Dockerfile linter +- [shellcheck](./hooks/shellcheck/) (**pre-commit**) - a static analysis tool +for shell scripts +- [license-checker](./hooks/license-checker/) (**pre-commit**) - Checks if the +license headers are present in the Git staged files with possibility to exclude +certain files or file extensions using Regular Expression pattern. +- [jsonlint](./hooks/jsonlint/) (**pre-commit**) - Validation tool for JSON files. +- [yamllint](./hooks/yamllint/) (**pre-commit**) - A linter for YAML files. +- [markdown-lint](./hooks/markdown-lint/) (**pre-commit**) - is a static +analysis tool for *.md files. ## About Boozt -Boozt is a leading and fast-growing Nordic technology company selling fashion and lifestyle online mainly through its multi-brand webstore [Boozt.com][boozt] and [Booztlet.com][booztlet]. +Boozt is a leading and fast-growing Nordic technology company selling fashion +and lifestyle online mainly through its multi-brand webstore [Boozt.com][boozt] +and [Booztlet.com][booztlet]. -The company is focused on using cutting-edge, in-house developed technology to curate the best possible customer experience. +The company is focused on using cutting-edge, in-house developed technology to +curate the best possible customer experience. -With offices in Sweden, Denmark, Lithuania and Poland, we pride ourselves in having a diverse team, consisting of 1100+ employees and 38 nationalities. +With offices in Sweden, Denmark, Lithuania and Poland, we pride ourselves in +having a diverse team, consisting of 1100+ employees and 38 nationalities. -See our [Medium][blog] blog page for technology-focused articles. Would you like to make your mark by working with us at Boozt? Take a look at our [latest hiring opportunities][careers]. +See our [Medium][blog] blog page for technology-focused articles. Would you +like to make your mark by working with us at Boozt? Take a look at our +[latest hiring opportunities][careers]. ## Reporting Issues -Please provide a clear and concise description of the problem or the feature you're missing along with any relevant context or screenshots. +Please provide a clear and concise description of the problem or the feature +you're missing along with any relevant context or screenshots. Check existing issues before reporting to avoid duplicates. @@ -60,13 +93,16 @@ Please follow the [Issue Reporting Guidelines][issues] before opening a new issu ## Contributing -Contributions are highly valued and very welcome! For the process of reviewing changes, we use [Pull Requests][pull-request]. For a detailed information please follow the [Contribution Guidelines][contributing] +Contributions are highly valued and very welcome! For the process of reviewing +changes, we use [Pull Requests][pull-request]. For a detailed information +please follow the [Contribution Guidelines][contributing] ## License [![license](https://img.shields.io/badge/license-mit-brightgreen.svg)][license] -This project is licensed under the MIT. Please see [LICENSE][license] for full details. +This project is licensed under the MIT. Please see [LICENSE][license] for +full details. [homepage]: https://github.com/boozt-platform/lefthook [releases]: https://github.com/boozt-platform/lefthook/releases diff --git a/add-hook.sh b/add-hook.sh deleted file mode 100755 index 3de0a1a..0000000 --- a/add-hook.sh +++ /dev/null @@ -1,105 +0,0 @@ -#!/usr/bin/env bash - -# SPDX-FileCopyrightText: Copyright Boozt Fashion, AB -# SPDX-License-Identifier: MIT - -export NAME="${NAME:-""}" -export CREATE_DOCKERFILE="${CREATE_DOCKERFILE:-N}" - -SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" -HOOKS_DIR="hooks" -HOOKS_PATH="${SCRIPT_DIR}/${HOOKS_DIR}" - -# error message function printing in red color -# usage: error "message" -error() { - local message=${1:-""} - echo -e "\033[0;31m${message}\033[0m" -} - -# create hooks dir if not exists -if [ ! -d "${HOOKS_PATH}" ]; then - mkdir -p "${HOOKS_PATH}" -fi - -# check if the NAME environment variable is not empty -if [ -z "$NAME" ]; then - error "The NAME environment variable is empty" - exit 1 -fi - -# check if the given module name not yet exists to be able to create a new module -if [ -d "${HOOKS_PATH}/${NAME}" ]; then - error "The module ${NAME} already exists" - exit 1 -fi - -# create a new module directory -mkdir -p "${HOOKS_PATH}/${NAME}" - -# create .lefthook.yaml file with the SPDX license in it -cat > "${HOOKS_PATH}/${NAME}/.lefthook.yaml" < "${HOOKS_PATH}/${NAME}/README.md" < "${HOOKS_PATH}/${NAME}/Dockerfile" <[optional scope]: [optional body] [optional footer(s)]` - - `[optional scope]: ` +- `[optional scope]: [optional body] [optional footer(s)]` +- `[optional scope]: ` Refer to the table below for the possible commit types: | Type | Description| | ---- | ---- | -| build | Changes affecting the build system or dependencies (example scopes: gulp, npm) +| build | Changes affecting the build system or dependencies | | chore | Maintenance tasks such as upgrades or cleanup | -| ci | Changes to CI configuration files or scripts (example scopes: Travis, Circle, GitLab, GitHub) | +| ci | Changes to CI configuration files or scripts | | docs | Documentation-only changes | | feat | New features | | fix | Bug fixes | @@ -58,15 +80,20 @@ Refer to the table below for the possible commit types: | style | Changes to code style or formatting | | test | Adding or correcting tests | -Exclamation mark (!) is optional and can be used to indicate breaking changes. Use it before colon (:). i.e. `feat(auth)!: add login feature`. +Exclamation mark (!) is optional and can be used to indicate breaking changes. +Use it before colon (:). i.e. `feat(auth)!: add login feature`. For comprehensive documentation, [click here][conventional-commits]. -If a backwards incompatible change is unavoidable, ensure to mention it in your pull request and provide justification for the necessity of the change. +If a backwards incompatible change is unavoidable, ensure to mention it in +your pull request and provide justification for the necessity of the change. ## Creating a Pull Request -Once you've made your changes and are ready to contribute them back to the project, [create a pull request (PR)][pr]. Provide a clear and descriptive title for your PR, along with a summary of the changes made, any related GitHub issues and any notes on backwards incompatibility. +Once you've made your changes and are ready to contribute them back to the +project, [create a pull request (PR)][pr]. Provide a clear and descriptive +title for your PR, along with a summary of the changes made, any related GitHub +issues and any notes on backwards incompatibility. Be sure to follow the pull request template, if one is provided. @@ -74,39 +101,71 @@ Be sure to follow the pull request template, if one is provided. To create a new hook, follow these steps: -1. Run `make add_hook [options]` (i.e. `make add_hook NAME=jslint`). Below are the available options you can pass: +1. Create a new folder in `hooks/[new-hook-name]/`. + +1. Create a file inside folder `hooks/[new-hook-name]/` called `.lefthook.yaml` +within license header as the following code below: + + ```yaml + # SPDX-FileCopyrightText: Copyright Boozt Fashion, AB + # SPDX-License-Identifier: MIT + --- + pre-commit: + parallel: true + commands: + hadolint: + glob: "Dockerfile*" + run: | + docker run --rm -it -v $(pwd):/app -w /app \ + ghcr.io/hadolint/hadolint \ + hadolint {staged_files} + ``` + +1. Create a file inside folder `hooks/[new-hook-name]/` called `README.md` with +the following content structure: + + ```markdown + # [new-hook-name] hook -Name|Description|Required|Default| ----|---|---|---| -NAME|The name of the hook|Yes|| -DOCKERFILE|Boolean option to create an empty Dockerfile file in the hook folder with the license included|No|False| + ## How to Use It -2. Add necessary files to your new hook. -3. Adjust the `.lefthook.yaml` file to execute your new hook. You can use either a script or Docker. It's recommended to use Docker unless it's a simple bash script or specific to a development niche (such as frontend - JavaScript, CSS, or backend - Go, Python). -4. Update the README.md documentation to include your new hook in the list of available hooks and provide a brief description. -5. If you requested to create a Dockerfile, the script will output the `yaml` options to add to the `.goreleaser.yaml` file. These options facilitate the creation of a Docker image for various OS architectures. -6. To run tests against your Docker image, you can use the following commands: + - - `make NAME=` or `make build NAME=`: This command builds the image and runs the security check. For example: `make NAME=jslint`. - - Alternatively, you can execute these commands individually: - - `make container_build NAME=`: Builds the Docker image. - - `make container_scan NAME=`: Performs a security scan on the Docker image. - - `make container_run NAME=`: Runs the Docker image. + ## Configuration + + + + ``` + + > [!NOTE] + > For hooks that have scripts, consider [following the guidelines](https://github.com/evilmartians/lefthook/blob/master/docs/configuration.md#scripts) + to place them in the correct `.lefthook/` directory. + +1. Update the main project's `README.md` file to add this hook in +"How to Use It" and "Available Hooks" sections. ## License Information -To ensure proper attribution and compliance with licensing terms, we require that all source code files include a [short-form SPDX ID][spdx-license-info] license comment block. This block should be added at the top of each source code file. +To ensure proper attribution and compliance with licensing terms, we require +that all source code files include a [short-form SPDX ID][spdx-license-info] +license comment block. This block should be added at the top of each +source code file. -``` +```text SPDX-FileCopyrightText: Copyright Boozt Fashion, AB SPDX-License-Identifier: MIT ``` -For more information of the SPDX file tags please follow https://spdx.github.io/spdx-spec/v2.3/file-tags/. +For more information of the SPDX file tags please follow [https://spdx.github.io/spdx-spec/v2.3/file-tags/](https://spdx.github.io/spdx-spec/v2.3/file-tags/). ## Merging and Releasing -After your pull request has been reviewed and approved by the project maintainers ([CODEOWNERS][codeowners]), it will be merged into the main branch. Once merged, the changes will be included in the next release of the project and the [Semantic Versioning (SemVer)][semver] principles will be applied. You'll be asked for squash your commits if it's not following the standards of the [conventional commits][conventional-commits]. +After your pull request has been reviewed and approved by the project +maintainers ([CODEOWNERS][codeowners]), it will be merged into the main branch. +Once merged, the changes will be included in the next release of the project +and the [Semantic Versioning (SemVer)][semver] principles will be applied. +You'll be asked for squash your commits if it's not following the standards of +the [conventional commits][conventional-commits]. **Thank you for your contribution!** diff --git a/docs/SECURITY.md b/docs/SECURITY.md index 48baca8..d8ccbfc 100644 --- a/docs/SECURITY.md +++ b/docs/SECURITY.md @@ -1,7 +1,15 @@ # Reporting Security Vulnerabilities -If you discover any security vulnerabilities in our project, we appreciate your responsible disclosure. To report a security issue, please avoid creating public GitHub issues. Instead, email us directly at security@boozt.com. We kindly request that you refrain from disclosing the vulnerability publicly until it has been addressed by our team. +If you discover any security vulnerabilities in our project, we appreciate your +responsible disclosure. To report a security issue, please avoid creating +public GitHub issues. Instead, email us directly at [security@boozt.com](security@boozt.com). +We kindly request that you refrain from disclosing the vulnerability publicly +until it has been addressed by our team. -We prioritize vulnerabilities present only in the latest version of our product. This helps us focus on addressing the most relevant security concerns and minimizing noise. +We prioritize vulnerabilities present only in the latest version of our +product. This helps us focus on addressing the most relevant security concerns +and minimizing noise. -We take security seriously and are committed to promptly addressing and resolving any reported vulnerabilities. Thank you for helping us maintain the security and integrity of our project. +We take security seriously and are committed to promptly addressing and +resolving any reported vulnerabilities. Thank you for helping us maintain the +security and integrity of our project. diff --git a/hooks/commitlint/.lefthook.yaml b/hooks/commitlint/.lefthook.yaml index 287fdc9..5525b77 100644 --- a/hooks/commitlint/.lefthook.yaml +++ b/hooks/commitlint/.lefthook.yaml @@ -1,6 +1,6 @@ # SPDX-FileCopyrightText: Copyright Boozt Fashion, AB # SPDX-License-Identifier: MIT - +--- commit-msg: parallel: true scripts: diff --git a/hooks/commitlint/README.md b/hooks/commitlint/README.md index 19f2624..989f945 100644 --- a/hooks/commitlint/README.md +++ b/hooks/commitlint/README.md @@ -1,6 +1,8 @@ # commitlint hook -This hook checks if the commit message follows the conventional commits framework. For a full information take a look at CONTRIBUTING.md guideline (Updating Code section). +This hook checks if the commit message follows the conventional commits +framework. For a full information take a look at CONTRIBUTING.md guideline +(Updating Code section). ## How to Use It @@ -16,7 +18,8 @@ remotes: ## Configuration -The script supports two environment variables that can be reconfigured. You can define the environment variables as follows: +The script supports two environment variables that can be reconfigured. You +can define the environment variables as follows: ```shell # default values for environment variables @@ -25,7 +28,8 @@ export MAX_COMMIT_MESSAGE_LENGTH=80 export VALID_COMMIT_PREFIXES="build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test" ``` -Alternatively, you can create a `.commitlint` environment file in the project root, and the script will automatically source it: +Alternatively, you can create a `.commitlint` environment file in the project +root, and the script will automatically source it: ```bash # .commitlint diff --git a/hooks/hadolint/.lefthook.yaml b/hooks/hadolint/.lefthook.yaml index 38fc40b..6b8988e 100644 --- a/hooks/hadolint/.lefthook.yaml +++ b/hooks/hadolint/.lefthook.yaml @@ -1,10 +1,12 @@ # SPDX-FileCopyrightText: Copyright Boozt Fashion, AB # SPDX-License-Identifier: MIT - +--- pre-commit: parallel: true commands: hadolint: glob: "Dockerfile*" run: | - docker run --rm -it -v $(pwd):/app -w /app ghcr.io/hadolint/hadolint hadolint {staged_files} + docker run --rm -it -v $(pwd):/app -w /app \ + ghcr.io/hadolint/hadolint \ + hadolint {staged_files} diff --git a/hooks/hadolint/README.md b/hooks/hadolint/README.md new file mode 100644 index 0000000..c1867b6 --- /dev/null +++ b/hooks/hadolint/README.md @@ -0,0 +1,16 @@ +# hadolint hook + +A Dockerfile linter that helps to build Docker images by following the best +practices. [https://github.com/hadolint/hadolint](https://github.com/hadolint/hadolint) + +## How to Use It + +```yaml +# .lefthook.yaml +remotes: + - git_url: git@github.com:boozt-platform/lefthook + ref: [tag] + configs: + # lint Dockerfiles + - hooks/hadolint/.lefthook.yaml +``` diff --git a/hooks/jsonlint/.lefthook.yaml b/hooks/jsonlint/.lefthook.yaml new file mode 100644 index 0000000..1b158b9 --- /dev/null +++ b/hooks/jsonlint/.lefthook.yaml @@ -0,0 +1,13 @@ +# SPDX-FileCopyrightText: Copyright Boozt Fashion, AB +# SPDX-License-Identifier: MIT +--- +pre-commit: + parallel: true + commands: + jsonlint: + glob: "*.json" + stage_fixed: true + run: | + docker run --rm -v $(pwd):/code \ + pipelinecomponents/jsonlint:0.19.1 \ + jsonlint {staged_files} -s -i diff --git a/hooks/jsonlint/README.md b/hooks/jsonlint/README.md new file mode 100644 index 0000000..eda4d42 --- /dev/null +++ b/hooks/jsonlint/README.md @@ -0,0 +1,22 @@ +# jsonlint hook + +Validation tool for JSON files. [https://github.com/zaach/jsonlint](https://github.com/zaach/jsonlint) + +## Configuration + +Currently, we are using this tool to validate our JSON files and run a git +patch to fix it due to formatting issues. So by default, we use it to sort +the keys and automatically update the actual files (and lefthook will execute +the `git add`). + +## How to Use It + +```yaml +# .lefthook.yaml +remotes: + - git_url: git@github.com:boozt-platform/lefthook + ref: [tag] + configs: + # validate the JSON files + - hooks/jsonlint/.lefthook.yaml +``` diff --git a/hooks/license-checker/.lefthook.yaml b/hooks/license-checker/.lefthook.yaml index ceb5f1b..e95bbcd 100644 --- a/hooks/license-checker/.lefthook.yaml +++ b/hooks/license-checker/.lefthook.yaml @@ -1,6 +1,6 @@ # SPDX-FileCopyrightText: Copyright Boozt Fashion, AB # SPDX-License-Identifier: MIT - +--- pre-commit: parallel: true scripts: diff --git a/hooks/license-checker/README.md b/hooks/license-checker/README.md index ad9bf52..cf78b4a 100644 --- a/hooks/license-checker/README.md +++ b/hooks/license-checker/README.md @@ -1,6 +1,8 @@ # license-checker hook -This hook checks if the git staged files contain a license header. The script supports excluding certain files from the check, helping to ignore undesirable files. +This hook checks if the git staged files contain a license header. The script +supports excluding certain files from the check, helping to ignore undesirable +files. ## How to Use It @@ -16,7 +18,10 @@ remotes: ## Configuration -The script supports two environment variables that can be reconfigured. You can define the environment variables as follows: +You may customize the license header and the file extensions to exclude for the +checks using the environment variables. + +You can define the environment variables as follows: ```shell # Define the license header @@ -27,21 +32,9 @@ EOF ) # Define the regular expression of unwanted files to be checked -export EXCLUDE_FILES_EXT="LICENSE|\\.md|\\.gitignore|CODEOWNERS|\\.gitattributes|\\.editorconfig|\\.json|\\.lock|\\.toml" +export EXCLUDE_FILES_EXT="LICENSE|\\.md|\\.gitignore|\\.license-checker.txt|CODEOWNERS|\\.gitattributes|\\.editorconfig|\\.json|\\.lock|\\.toml" ``` -Alternatively, you can create a `.license-checker` environment file in the project root, and the script will automatically source it: - -```bash -# .license-checker - -# Define the license header -LICENSE_HEADER=$(cat <