forked from drwahl/puppet-git-hooks
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpre-receive
executable file
·62 lines (58 loc) · 2.65 KB
/
pre-receive
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
warned=0
final_ret=0
while read oldrev newrev refname; do
for puppetmodule in `git diff-tree --no-commit-id --name-only -r $newrev`; do
if [[ "$puppetmodule" =~ ^modules/ ]]; then
echo "skipping all checks for submodule $puppetmodule"
continue
fi
echo -e "\e[0;36m" "Checking $puppetmodule for science!" "\e[0m"
tmpdir=`mktemp -d`
tmpmodule="$tmpdir/$puppetmodule"
tmperror="$tmpdir/errors.txt"
mkdir -p $tmpmodule
rmdir $tmpmodule
git show $newrev:$puppetmodule > $tmpmodule
case $puppetmodule in
*.pp )
/var/lib/gems/1.8/bin/puppet parser validate --ignoreimport --storeconfigs true $tmpmodule 2&> $tmperror
rc=$?
if [[ $rc != 0 ]]; then
echo -e "\e[0;31m'puppet parser validate' failed on $puppetmodule - push denied. Run tests locally and confirm they pass before pushing. \e[0m"
cat $tmperror
rm -rf $tmpdir
final_ret=1
fi
# Check styleguide, but do not error if styleguide does not pass
/var/lib/gems/1.8/bin/puppet-lint --fail-on-warnings --no-quoted_booleans-check --no-80chars-check $tmpmodule > $tmperror
rc=$?
if [[ $rc != 0 ]]; then
if [[ $warned = 0 ]]; then
echo -e "\e[0;31m" "Please follow the puppet module styleguide (http://docs.puppetlabs.com/guides/style_guide.html)." "\e[0m"
echo -e "\e[0;31m" "The following ERROR/WARNING messages are informational only. The commit has been accepted. In the future, these will cause your commit to be refused." "\e[0m"
warned=1
fi
echo -e "\e[0;33m" "Style guide compliance errors in $puppetmodule:" "\e[0m"
echo -e "\e[0;33m"
cat $tmperror
echo -e "\e[0m"
fi
;;
*.erb )
cat $tmpmodule | erb -x -T - | ruby -c > /dev/null 2> $tmperror
rc=$?
if [[ $rc != 0 ]]; then
echo -e "\e[0;31m" "Ruby syntax checker failed on template $puppetmodule:" "\e[0m"
echo -e "\e[0;33m"
cat $tmperror
echo -e "\e[0m"
echo -e "\e[0;33m" "Commit accepted, but the above template will not expand properly" "\e[0m"
final_ret=1
fi
;;
esac
rm -rf $tmpdir
done
done
exit $final_ret