-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implementation of pre-commit hook to format justfiles (#1)
- Loading branch information
1 parent
0e8df7d
commit 209f33e
Showing
6 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: pre-commit | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: [main] | ||
|
||
jobs: | ||
pre-commit: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-python@v3 | ||
- uses: pre-commit/action@v3.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.5.0 | ||
hooks: | ||
- id: trailing-whitespace | ||
- id: end-of-file-fixer | ||
- id: check-yaml | ||
- id: check-added-large-files | ||
- id: fix-byte-order-marker | ||
- id: check-json | ||
- id: check-merge-conflict | ||
- repo: https://github.com/Mateusz-Grzelinski/actionlint-py | ||
rev: v1.6.26.11 | ||
hooks: | ||
- id: actionlint | ||
additional_dependencies: [ pyflakes>=3.0.1, shellcheck-py>=0.9.0.5 ] | ||
- repo: https://github.com/shellcheck-py/shellcheck-py | ||
rev: v0.9.0.6 | ||
hooks: | ||
- id: shellcheck | ||
- repo: https://github.com/scop/pre-commit-shfmt | ||
rev: v3.7.0-4 | ||
hooks: | ||
- id: shfmt | ||
args: [-w, -s, -i, '4', -ci] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
- id: format-justfile | ||
name: Format Justfiles | ||
language: script | ||
entry: pre-commit-just.sh | ||
files: '\.?[jJ]ustfile' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
ISC License | ||
|
||
Copyright 2024 Instrumentl, Inc. | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
This repository contains a pre-commit config for running `just --fmt` on any | ||
discovered [just](https://github.com/casey/just) files. It will auto-fix the | ||
files. | ||
|
||
## Usage | ||
|
||
You must have `just` installed on your system for this hook to work. | ||
|
||
```yaml | ||
- repo: https://github.com/instrument/pre-commit-justfile | ||
rev: 'main' | ||
hooks: | ||
- id: format-justfile | ||
``` | ||
## License | ||
This work is licensed under the ISC license, a copy of which can be found at [LICENSE.txt](LICENSE.txt). | ||
`just` itself is licensed under the CC0 license. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
if ! command -v just /dev/null 2>&1; then | ||
echo >&2 "no just binary found; not running" | ||
exit 0 | ||
fi | ||
|
||
status=0 | ||
|
||
for file in "$@"; do | ||
if ! just --fmt --unstable --check -f "$file" >/dev/null 2>&1; then | ||
echo >&2 "fixing ${file}" | ||
just --fmt --unstable -f "$file" >/dev/null 2>&1 | ||
status=1 | ||
fi | ||
done | ||
|
||
exit $status |