Last active
August 29, 2015 14:07
-
-
Save jarosite/e067b092deb9a4bbf235 to your computer and use it in GitHub Desktop.
Hook for mercurial server. Will check syntax of puppet files, yaml files for hiera and erb template files. Add on serrver to .hg/hgrc [hooks] pretxnchangegroup = .hg/puppet_syntax_check.rb
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
#!/usr/bin/ruby | |
def chk(file_to_check, cmd) | |
puts "checking '#{file_to_check}'" | |
if !system("hg cat -r tip '#{file_to_check}' | #{cmd} 2>&1") | |
print('!!! Syntax error in file: ' + file_to_check + "\n") | |
exit(1) | |
end | |
end | |
IO.popen('hg status --change tip -man | sort | uniq').readlines.each { |file| | |
file_to_check = file.strip | |
if file_to_check.match('.pp$') | |
chk(file_to_check, 'puppet parser validate') | |
elsif file_to_check.match('.yaml$') | |
chk(file_to_check, 'ruby -e "require \'yaml\'; YAML.load(ARGF.read)"') | |
elsif file_to_check.match('.erb$') | |
chk(file_to_check, 'erb -x -T - | ruby -c') | |
end | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment