The configuration file must be named pre-commit-build.yaml by default and placed in the root of the project workspace with the following structure:
- Root tag "hooks" (Required):
- For remote scripts, use a "remote" tag that contains a list of "repos" with the following structure:
- id: The ID of the script.
- origin: The URL of the GitHub repository.
- tag: The tag of the repository.
- target: The path that contains the script.
- name: The name of the script.
- disabled: The status of the script.
- expect: The expected result of the script โ
truefor exit code0,falsefor exit code< 1. - return: The actual return value of the script.
truefor1,falsefor0. - flags: The flags passed to the script, defined without the
--prefix. - args: The arguments passed to the script.
- For local scripts, use a "local" tag that contains a list of "scripts" with the following structure:
- id: The ID of the script.
- path: The path that contains the script.
- disabled: The status of the script.
- expect: The expected result of the script โ
truefor exit code0,falsefor exit code< 1. - return: The actual return value of the script.
truefor1,falsefor0. - flags: The flags passed to the script, defined without the
--prefix. - args: The arguments passed to the script.
- For remote scripts, use a "remote" tag that contains a list of "repos" with the following structure:
See the template example: pre-commit-build.template.yaml
File name: install-pre-commit
By default, the script will be mounted in the same workspace where the installer is located.
Arguments:
-
Help: Help command.
$ ./install-pre-commit -h
$ ./install-pre-commit --help
-
Update: Updates the installer to the defined version. If a version is not specified, it will be updated to the latest version.
$ ./install-pre-commit -u
$ ./install-pre-commit --update=tag
-
Version: Shows actual installer version.
$ ./install-pre-commit -v
$ ./install-pre-commit --version
-
Test: The script will be mounted inside the remote-scripts directory to prevent it from being used by Git.
$ ./install-pre-commit -t
-
Enable: Disables the hook if exists otherwise creates it disabled.
$ ./install-pre-commit -d
-
disable: Enables the hook if exists otherwise creates it enabled.
$ ./install-pre-commit -e
-
Workspace: Defines the workspace where the script will be placed.
$ ./install-pre-commit --workspace=../other_project/my_project
-
Input: Defines the directory and name where the input file is located.
$ ./install-pre-commit --input=.test.yaml
-
Output: Defines directory and name where the script will be placed.
$ ./install-pre-commit --output=.test.sh
-
Block: Generates the script as a single file without imports.
$ ./install-pre-commit -b
$ ./install-pre-commit --block
-
Mode: Specifies the build mode. Default is pre_commit. Valid options: pre_commit, pre_push.
$ ./install-pre-commit --mode=pre_commit
-
Pull: Downloads the specified remote script at the given version.
$ ./install-pre-commit --pull=golang/sh/run-govulncheck.sh:0.6.3
File name: clear-resources
By default, the script will clean the resources directory of the workspace where the installer is located.
Arguments:
-
Workspace: Defines the workspace resources directory that will be cleaned.
$ ./clear-resources --workspace=../other_project/my_project
Golang:
- check-go-context.sh: Executes functions to validate whether the current project is a valid Go project.
- Flags:
- If none are selected, all checks will be executed
- --project | --p: Verifies if this is a Go project
- --staged | --s: Checks for staged Go files
- --install | --i: Verifies if Go is installed
- run-fieldalignment.sh: Runs the
fieldalignmenttool to analyze Go struct memory layout and detect potential memory savings.
- Flags:
- --percent | --p: Defines the minimum percentage of memory savings required to fail the check. Default:
25%- run-formatter.sh: Format all Go files.
- run-linter.sh: Runs
golangci-lintto find errors in staged Go files.
- Flags:
- --install | --i: Installs the latest version of golangci-lint if it is not already.
- --strict | --i: Enable strict mode. If any file, regardless of whether it is in the staging area, contains errors, the execution will be marked as failed.
- --enable=
<lnt>| --e=<lnt>: Enables the specific linter. Can be specified multiple times. Linters are combined as a comma-separated list.- Dependencies:
- golangci-lint - 1.62.0 (https://github.com/golangci/golangci-lint)
- run-tests.sh: Runs all Go tests.
- Flags:
- --tags=
<tag>| --t=<tag>: Defines the test build tags. Can be specified multiple times. Tags are combined as a comma-separated list.- --race | --r: Runs the tests using the race detector.
- run-govulncheck.sh: Executes
govulncheckto check for vulnerabilities in dependencies.
- Flags:
- --install: Installs the latest version of govulncheck if it is not already installed
- Dependencies:
- govulncheck - v1.1.4 (https://github.com/golang/vuln)
- run-coverage-black-box.sh: Runs black-box tests on Go packages and calculates code coverage. By default, it checks whether the test directory structure matches the source structure and verifies if the current test coverage meets or exceeds the specified minimum.
- Flags:
- --verbose | --v : Displays the coverage details.
- --success-empty | --se : Treats the absence of tests as a successful result.
- --invalid-empty | --ie : Treats packages with no found tests as a valid result.
- --package=
<pkg>| --p=<pkg>: Manually specify one or more packages to analyze. Can be repeated to include multiple packages.- Arguments:
- Minimum coverage percentage. Example: 80.0
Node:
- run-npm-run.sh: Executes an npm script command based on a configurable argument.
- Arguments:
- Script command. Example: build, dev, test...
- Dependencies:
- node - Tested with Node.js v18+, but should work with all versions (https://nodejs.org/en)
- run-eslint.sh: Executes
ESLintanalysis tool to analyze code consistency and identify errors.
- Flags:
- --force-all | --fa: Runs
ESLintfor all configured project files. If not specified only staged files will be analyzed- Dependencies:
- node - Tested with Node.js v18+, but should work with all versions (https://nodejs.org/en)
- eslint - 9.34.0 (https://www.npmjs.com/package/eslint)
- eslint-formatter-unix - 8.40.0 (https://www.npmjs.com/package/eslint-formatter-unix)
Elixir/Mix:
- check-mix-context.sh: Executes functions to validate whether the current project is a valid Mix project.
- Flags:
- If none are selected, all checks will be executed
- --project | --p: Verifies if this is a Mix project
- --staged | --s: Checks for staged Elixir files (
*.ex/*.exs)- --install | --i: Verifies if Elixir and Mix are installed
- run-mix-tests.sh: Executes all Mix tests.
- Dependencies:
- Mix - ^1.12.0 (https://hexdocs.pm/mix/Mix.Tasks.Test.html)
- run-credo.sh: Executes Credo analysis tool to analyze code consistency and identify errors.
- Flags:
- --static | --s: Includes all issues. Without it, only positive-priority issues (โ โ โ) will be reported
- --force-all | --fa: Runs Credo for all project files. If not specified only staged files will be analyzed
- Dependencies:
- Credo - v1.7.12 (https://hexdocs.pm/credo/overview.html)
Zig:
- check-zig-context.sh: Executes functions to validate whether the current project is a valid Zig project.
- Flags:
- If none are selected, all checks will be executed
- --project | --p: Verifies if this is a Zig project
- --staged | --s: Checks for staged Elixir files (
*.zig/*.zon)- --install | --i: Verifies if Zig is installed
- run-check.sh: Run Zig's ast-check on staged Zig files to detect errors.
- run-fmt.sh: Run Zig's fmt to check staged files for formatting issues and optionally fix them.
- Flags:
- --apply | --a: Fix the issues and add the corrected files back to the Git staging area.
- run-tests.sh: Run all Zig tests.
Shell:
- run-linter.sh: Runs shellcheck to find errors in staged Shell files.
- Dependencies:
- shellcheck - 0.8.0 (https://www.shellcheck.net)
Tools:
- check-large-files.sh: Searches for large files based on a configurable number of bytes.
- Arguments:
- File size in bytes. Example: 5242880
- yq - v4.44.2 (https://github.com/mikefarah/yq)
- Notes: snap installations of yq could not working as expected. See: snap-notes