On Monday, December 10, 2012 4:27:26 PM UTC-6, Jakov Sosic wrote: > > Hi. > > I was wondering what kind of precommit hooks are you guys using? > > > Here is what I use:
#!/bin/bash # pre-commit git hook to check the validity of a puppet manifest # # Prerequisites: # gem install puppet-lint puppet # # Install: # /path/to/repo/.git/hooks/pre-comit # Source RVM if needed [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function* echo "### Checking puppet syntax, for science! ###" # for file in `git diff --name-only --cached | grep -E '\.(pp|erb)'` for file in `git diff --name-only --cached | grep -E '\.(pp)'` do # Only check new/modified files if [[ -f $file ]] then puppet-lint \ --error-level all \ --fail-on-warnings \ --no-80chars-check \ --no-class_parameter_defaults-check \ --with-filename $file # Set us up to bail if we receive any syntax errors if [[ $? -ne 0 ]] then syntax_is_bad=1 else echo "$file looks good" fi fi done echo "" echo "### Checking if puppet manifests are valid ###" # validating the whole manifest takes too long. uncomment this # if you want to test the whole shebang. # for file in `find . -name "*.pp"` # for file in `git diff --name-only --cached | grep -E '\.(pp|erb)'` for file in `git diff --name-only --cached | grep -E '\.(pp)'` do if [[ -f $file ]] then puppet parser validate --mode user --environment test $file if [[ $? -ne 0 ]] then echo "ERROR: puppet parser failed at: $file" syntax_is_bad=1 else echo "OK: $file looks valid" fi fi done echo "" if [[ $syntax_is_bad -eq 1 ]] then echo "FATAL: Syntax is bad. See above errors" echo "Bailing" exit 1 else echo "Everything looks good." fi -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/isWjIWaZjFEJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.