Created
December 14, 2012 13:57
pre-commit hook to validate and lint puppet manifests. also checks other files for whitespace errors (git diff --check)
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
#!/bin/sh -e | |
# | |
# install to .git/hooks/pre-commit to syntax-check and style-check puppet | |
# manifests | |
unset tmpd changed_filelist | |
cleanup() { | |
[ -d "$tmpd" ] && rm -rf "$tmpd" | |
} | |
tmpd=`mktemp -d /tmp/puppet-precommit.XXXXXX` | |
changed_filelist="${tmpd}/changed-files" | |
trap cleanup 0 INT HUP TERM QUIT | |
all_ok=true | |
git diff-index --cached --diff-filter=AM --name-only HEAD\ | |
| git checkout-index --stdin --prefix="${tmpd}/" | |
git --no-pager diff --cached --check || all_ok=false | |
cd "${tmpd}" | |
find . -type f -name '*.pp' > "$changed_filelist" | |
xargs -r puppet parser validate < "$changed_filelist" | |
extra_args='--no-80chars-check' | |
# puppet-lint only checks one file per invocation | |
while read manifest; do | |
case "$manifest" in | |
./modules/*) | |
;; | |
*) | |
extra_args="$extra_args --no-autoloader_layout-check" | |
;; | |
esac | |
puppet-lint --with-filename --fail-on-warnings $extra_args "$manifest" || all_ok=false | |
done < "$changed_filelist" | |
$all_ok |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment