forked from drwahl/puppet-git-hooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre-receive
executable file
·74 lines (66 loc) · 2.46 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
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
failures=0
RC=0
subhook_root=hooks/commit_hooks
tmptree=$(mktemp -d)
while read oldrev newrev refname; do
git archive $newrev | tar x -C ${tmptree}
for changedfile in $(git diff --name-only $oldrev $newrev --diff-filter=ACM); do
tmpmodule="$tmptree/$changedfile"
#check puppet manifest syntax
if type puppet >/dev/null 2>&1; then
if [ $(echo $changedfile | grep -q '\.*.pp$'; echo $?) -eq 0 ]; then
${subhook_root}/puppet_manifest_syntax_check.sh $tmpmodule "${tmptree}/"
RC=$?
if [ "$RC" -ne 0 ]; then
failures=`expr $failures + 1`
fi
fi
else
echo "puppet not installed. Skipping puppet syntax checks..."
fi
if type ruby >/dev/null 2>&1; then
#check erb (template file) syntax
if type erb >/dev/null 2>&1; then
if [ $(echo $changedfile | grep -q '\.*.erb$'; echo $?) -eq 0 ]; then
${subhook_root}/erb_template_syntax_check.sh $tmpmodule "${tmptree}/"
RC=$?
if [ "$RC" -ne 0 ]; then
failures=`expr $failures + 1`
fi
fi
else
echo "erb not installed. Skipping erb template checks..."
fi
#check hiera data (yaml/yml) syntax
if [ $(echo $changedfile | grep -q '\.*.yaml$\|\.*.yml$'; echo $?) -eq 0 ]; then
${subhook_root}/yaml_syntax_check.sh $tmpmodule "${tmptree}/"
RC=$?
if [ "$RC" -ne 0 ]; then
failures=`expr $failures + 1`
fi
fi
else
echo "ruby not installed. Skipping erb/yaml checks..."
fi
#puppet manifest styleguide compliance
if type puppet-lint >/dev/null 2>&1; then
if [ $(echo $changedfile | grep -q '\.*.pp$' ; echo $?) -eq 0 ]; then
${subhook_root}/puppet_lint_checks.sh $tmpmodule "${tmptree}/"
RC=$?
if [ "$RC" -ne 0 ]; then
failures=`expr $failures + 1`
fi
fi
else
echo "puppet-lint not installed. Skipping puppet-lint tests..."
fi
done
done
rm -rf ${tmptree}
#summary
if [ "$failures" -ne 0 ]; then
echo -e "\x1B[0;31mError: $failures subhooks failed. Declining push.\x1B[0m"
exit 1
fi
exit 0