mirror of
https://gitea.com/mcereda/oam.git
synced 2026-02-09 05:44:23 +00:00
feat: lefthook
This commit is contained in:
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@@ -94,6 +94,7 @@
|
|||||||
"kubeval",
|
"kubeval",
|
||||||
"kubie",
|
"kubie",
|
||||||
"kustomize",
|
"kustomize",
|
||||||
|
"lefthook",
|
||||||
"libexec",
|
"libexec",
|
||||||
"localdomain",
|
"localdomain",
|
||||||
"luci",
|
"luci",
|
||||||
|
|||||||
34
examples/dotfiles/.lefthook.yml
Normal file
34
examples/dotfiles/.lefthook.yml
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
# See https://github.com/evilmartians/lefthook/blob/master/docs/configuration.md
|
||||||
|
|
||||||
|
assert_lefthook_installed: true
|
||||||
|
no_tty: true
|
||||||
|
|
||||||
|
# pre-commit:
|
||||||
|
# parallel: true
|
||||||
|
# commands:
|
||||||
|
# eslint:
|
||||||
|
# glob: "*.{js,ts,jsx,tsx}"
|
||||||
|
# run: yarn eslint {staged_files}
|
||||||
|
# rubocop:
|
||||||
|
# tags: backend style
|
||||||
|
# glob: "*.rb"
|
||||||
|
# exclude: '(^|/)(application|routes)\.rb$'
|
||||||
|
# run: bundle exec rubocop --force-exclusion {all_files}
|
||||||
|
# govet:
|
||||||
|
# tags: backend style
|
||||||
|
# files: git ls-files -m
|
||||||
|
# glob: "*.go"
|
||||||
|
# run: go vet {files}
|
||||||
|
# scripts:
|
||||||
|
# "hello.js":
|
||||||
|
# runner: node
|
||||||
|
# "any.go":
|
||||||
|
# runner: go run
|
||||||
|
# pre-push:
|
||||||
|
# commands:
|
||||||
|
# packages-audit:
|
||||||
|
# tags: frontend security
|
||||||
|
# run: yarn audit
|
||||||
|
# gems-audit:
|
||||||
|
# tags: backend security
|
||||||
|
# run: bundle audit
|
||||||
@@ -86,7 +86,7 @@ What really worked for me.
|
|||||||
- All tasks should be able to execute from one's own local machine.<br/>
|
- All tasks should be able to execute from one's own local machine.<br/>
|
||||||
This allows to fail fast and avoid wasting time waiting for pipelines to run in a black box somewhere.
|
This allows to fail fast and avoid wasting time waiting for pipelines to run in a black box somewhere.
|
||||||
- Consider using local automation to guarantee basic quality **before** the code reaches the shared repository.<br/>
|
- Consider using local automation to guarantee basic quality **before** the code reaches the shared repository.<br/>
|
||||||
Tools like [`pre-commit`][pre-commit] are a doozy for this.
|
Tools like [`pre-commit`][pre-commit] or [`lefthook`][lefthook] are a doozy for this.
|
||||||
- DevOps pipelines are meant to be used as **last mile** steps for specific goals.<br/>
|
- DevOps pipelines are meant to be used as **last mile** steps for specific goals.<br/>
|
||||||
There **cannot** be a single pipeline for everything, the same way as the _one-size-fits-all_ concept never really works.
|
There **cannot** be a single pipeline for everything, the same way as the _one-size-fits-all_ concept never really works.
|
||||||
|
|
||||||
@@ -140,6 +140,7 @@ Listed in order of addition:
|
|||||||
<!-- Knowledge base -->
|
<!-- Knowledge base -->
|
||||||
[crossplane]: https://www.crossplane.io/
|
[crossplane]: https://www.crossplane.io/
|
||||||
[editorconfig]: editorconfig.md
|
[editorconfig]: editorconfig.md
|
||||||
|
[lefthook]: lefthook.md
|
||||||
[pre-commit]: pre-commit.md
|
[pre-commit]: pre-commit.md
|
||||||
[safe]: safe.placeholder
|
[safe]: safe.placeholder
|
||||||
[the automation paradox]: the%20automation%20paradox.md
|
[the automation paradox]: the%20automation%20paradox.md
|
||||||
|
|||||||
94
knowledge base/lefthook.md
Normal file
94
knowledge base/lefthook.md
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
# Lefthook
|
||||||
|
|
||||||
|
1. [TL;DR](#tldr)
|
||||||
|
1. [Configuration](#configuration)
|
||||||
|
1. [Further readings](#further-readings)
|
||||||
|
1. [Sources](#sources)
|
||||||
|
|
||||||
|
## TL;DR
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# Installation.
|
||||||
|
go install 'github.com/evilmartians/lefthook@latest'
|
||||||
|
npm install 'lefthook' --save-dev
|
||||||
|
gem install 'lefthook'
|
||||||
|
brew install 'lefthook'
|
||||||
|
|
||||||
|
# Get help about any command.
|
||||||
|
lefthook help
|
||||||
|
lefthook help 'dump'
|
||||||
|
|
||||||
|
# Generate autocompletion scripts for the specified shells.
|
||||||
|
lefthook completion 'zsh'
|
||||||
|
lefthook completion -v 'fish' > "$HOME/.config/fish/completions/lefthook.fish"
|
||||||
|
source <(lefthook completion 'bash')
|
||||||
|
|
||||||
|
# Add configured hooks to the current git repository.
|
||||||
|
# Creates a basic configuration file in the repository if missing.
|
||||||
|
lefthook install
|
||||||
|
|
||||||
|
# Print the merged configuration from all files.
|
||||||
|
lefthook dump
|
||||||
|
|
||||||
|
# Add hook directories to the current repository.
|
||||||
|
lefthook add 'pre-commit'
|
||||||
|
lefthook add -dv 'commit-msg'
|
||||||
|
|
||||||
|
# Execute groups of hooks.
|
||||||
|
lefthook run 'pre-push'
|
||||||
|
lefthook run 'pre-commit' -n --commands 'lint' --files 'lefthook.yml'
|
||||||
|
|
||||||
|
# Remove configured hooks from the current git repository.
|
||||||
|
lefthook uninstall
|
||||||
|
lefthook uninstall -cv
|
||||||
|
```
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
Configuration files can be written in JSON, TOML or YAML.<br/>
|
||||||
|
Only one of them will be used, even if there are more than one in the repository. The chosen one will be the first one found during initialization, hence it is suggested to use a **single** configuration file in any of the above formats.
|
||||||
|
|
||||||
|
The _main_ configuration file must exist and go by the name `lefthook.<formatExtension>` or `.lefthook.<formatExtension>`.
|
||||||
|
|
||||||
|
An _extra_ configuration file named `lefthook-local` is merged with the main file if found upon initialization. All supported formats can be applied to this `-local` file.<br/>
|
||||||
|
If the main configuration file starts with the leading dot, the `-local` file must also start with the leading dot.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ ls -A1 *lefthook*
|
||||||
|
.lefthook-local.json
|
||||||
|
.lefthook.yml
|
||||||
|
```
|
||||||
|
|
||||||
|
[Configuration file example]
|
||||||
|
|
||||||
|
Configuration files can extend other files recursively.
|
||||||
|
|
||||||
|
## Further readings
|
||||||
|
|
||||||
|
- [Github]
|
||||||
|
- [Configuration]
|
||||||
|
- [Pre-commit]
|
||||||
|
|
||||||
|
## Sources
|
||||||
|
|
||||||
|
All the references in the [further readings] section, plus the following:
|
||||||
|
|
||||||
|
- [Lefthook: knock your team's code back into shape]
|
||||||
|
|
||||||
|
<!--
|
||||||
|
References
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!-- In-article sections -->
|
||||||
|
[further readings]: #further-readings
|
||||||
|
|
||||||
|
<!-- Knowledge base -->
|
||||||
|
[pre-commit]: pre-commit.md
|
||||||
|
|
||||||
|
<!-- Files -->
|
||||||
|
[configuration file example]: ../examples/dotfiles/.lefthook.yml
|
||||||
|
|
||||||
|
<!-- Upstream -->
|
||||||
|
[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
|
||||||
@@ -70,6 +70,9 @@ Check they are tracked (have been `add`ed to the repository).
|
|||||||
References
|
References
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
<!-- Knowledge base -->
|
||||||
|
[lefthook]: lefthook.md
|
||||||
|
|
||||||
<!-- Upstream -->
|
<!-- Upstream -->
|
||||||
[file types by extension]: https://github.com/pre-commit/identify/blob/main/identify/extensions.py
|
[file types by extension]: https://github.com/pre-commit/identify/blob/main/identify/extensions.py
|
||||||
[supported hooks]: https://pre-commit.com/hooks.html
|
[supported hooks]: https://pre-commit.com/hooks.html
|
||||||
|
|||||||
Reference in New Issue
Block a user