Skip to content

Commit

Permalink
Add sentinel fmt hook (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
thepoppingone authored Mar 10, 2023
1 parent eee43be commit ae4a77b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,11 @@
entry: ./hooks/check_skip_env.py
language: script
files: \.go$

- id: sentinel-fmt
name: Sentinel fmt
description: Rewrites all Sentinel configuration files to a canonical format
entry: hooks/sentinel-fmt.sh
language: script
files: \.sentinel$
require_serial: true
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ supported hooks are:
* **helmlint** Automatically run [`helm lint`](https://helm.sh/docs/helm/helm_lint/) on your Helm chart files. [See caveats here](#helm-lint-caveats).
* **markdown-link-check** Automatically run [markdown-link-check](https://github.com/tcort/markdown-link-check) on
markdown doc files.
* **sentinel-fmt**: Automatically run `sentinel fmt` on all Sentinel code (`*.sentinel.*` files).




Expand Down
22 changes: 22 additions & 0 deletions hooks/sentinel-fmt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

#!/usr/bin/env bash

set -e

# OSX GUI apps do not pick up environment variables the same way as Terminal apps and there are no easy solutions,
# especially as Apple changes the GUI app behavior every release (see https://stackoverflow.com/q/135688/483528). As a
# workaround to allow GitHub Desktop to work, add this (hopefully harmless) setting here.
original_path=$PATH
export PATH=$PATH:/usr/local/bin

# Store and return last failure from fmt so this can validate every directory passed before exiting
FMT_ERROR=0

for file in "$@"; do
sentinel fmt -diff -check "$file" || FMT_ERROR=$?
done

# reset path to the original value
export PATH=$original_path

exit ${FMT_ERROR}

0 comments on commit ae4a77b

Please sign in to comment.