Created
February 1, 2011 21:45
-
-
Save asuth/806757 to your computer and use it in GitHub Desktop.
We use this to check our puppet scripts as a git pre-commit hook.
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
#!/opt/local/bin/php | |
<?php | |
// Git pre-commit file to check Puppet for errors | |
$files = array(); | |
exec('git diff-index --cached --name-only HEAD', $files); | |
$exitcode = 0; | |
foreach($files as $file) { | |
$output = ''; | |
if (!preg_match('/\.pp$/i', $file)) | |
continue; | |
// file might be being removed | |
if (!file_exists($file)) | |
continue; | |
exec('puppet apply --parseonly '.escapeshellarg($file), $output, $return); | |
if (!$return) // gives a 0 error code if everything went well | |
continue; | |
$exitcode = 1; // abort the commit | |
echo "\n-------------- PUPPET PARSE ERRORS! ----------------\n"; | |
echo implode("\n", $output)."\n"; // an extra newline to make it look good | |
echo "-------------- FIX BEFORE COMMIT ----------------\n\n"; | |
} | |
exit($exitcode); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment