Skip to content

Commit 2f6311c

Browse files
author
David Wahlstrom
committed
provide more friendly output for server-side hooks
1 parent 984646c commit 2f6311c

File tree

6 files changed

+46
-14
lines changed

6 files changed

+46
-14
lines changed

commit_hooks/erb_template_syntax_check.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
#!/bin/bash
22

33
# This script expects $1 to be passed and for $1 to be the filesystem location
4-
# to an ERB file for which it will run syntax checks against.
4+
# to an ERB file for which it will run syntax checks against. If $2 is passed,
5+
# it will be stripped off of the path to provide prettier output, which is
6+
# particularly useful for server-side hooks when tempdirs are created.
57

68
syntax_errors=0
79
error_msg=$(mktemp /tmp/error_msg_erb-syntax.XXXXX)
810

11+
if [ $2 ]; then
12+
module_path=$(echo $1 | sed -e 's|'$2'||')
13+
else
14+
module_path=$1
15+
fi
16+
917
# Check ERB template syntax
10-
echo -e "\e[0;36mChecking erb template syntax for $1...\e[0m"
18+
echo -e "\e[0;36mChecking erb template syntax for $module_path...\e[0m"
1119
cat $1 | erb -x -T - | ruby -c 2>&1 > $error_msg
1220
if [ $? -ne 0 ]; then
1321
echo -en "\e[0;31m"
1422
cat $error_msg
1523
syntax_errors=`expr $syntax_errors + 1`
16-
echo -e "Error: erb syntax error in $1 (see above)\e[0m"
24+
echo -e "Error: erb syntax error in $module_path (see above)\e[0m"
1725
fi
1826
rm $error_msg
1927

commit_hooks/puppet_lint_checks.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,21 @@
66
syntax_errors=0
77
error_msg=$(mktemp /tmp/error_msg_puppet-lint.XXXXX)
88

9+
if [ $2 ]; then
10+
module_path=$(echo $1 | sed -e 's|'$2'||')
11+
else
12+
module_path=$1
13+
fi
14+
915
# De-lint puppet manifests
10-
echo -e "\e[0;36mChecking puppet style guide compliance for $1...\e[0m"
16+
echo -e "\e[0;36mChecking puppet style guide compliance for $module_path...\e[0m"
1117
puppet-lint --fail-on-warnings --with-filename --no-80chars-check $1 2>&1 > $error_msg
1218
RC=$?
1319
if [ $RC -ne 0 ]; then
1420
echo -en "\e[0;31m"
1521
syntax_errors=$(expr $syntax_errors + 1)
1622
cat $error_msg
17-
echo -e "Error: styleguide violation in $1 (see above)\e[0m"
23+
echo -e "Error: styleguide violation in $module_path (see above)\e[0m"
1824
fi
1925
rm -f $error_msg
2026

commit_hooks/puppet_manifest_syntax_check.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,21 @@
66
syntax_errors=0
77
error_msg=$(mktemp /tmp/error_msg_puppet-syntax.XXXXX)
88

9+
if [ $2 ]; then
10+
module_path=$(echo $1 | sed -e 's|'$2'||')
11+
else
12+
module_path=$1
13+
fi
14+
915
# Get list of new/modified manifest and template files to check (in git index)
1016
# Check puppet manifest syntax
11-
echo -e "\e[0;36mChecking puppet manifest syntax for $1...\e[0m"
17+
echo -e "\e[0;36mChecking puppet manifest syntax for $module_path...\e[0m"
1218
puppet parser validate --color=false $1 2>&1 > $error_msg
1319
if [ $? -ne 0 ]; then
1420
echo -en "\e[0;31m"
1521
syntax_errors=`expr $syntax_errors + 1`
1622
cat $error_msg
17-
echo -e "Error: puppet syntax error in $1 (see above)\e[0m"
23+
echo -e "Error: puppet syntax error in $module_path (see above)\e[0m"
1824
fi
1925
rm -f $error_msg
2026

commit_hooks/rspec_puppet_checks.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ git_root=`git rev-parse --show-toplevel`
44
syntax_errors=0
55
error_msg=$(mktemp /tmp/error_msg_rspec-puppet.XXXXX)
66

7+
if [ $2 ]; then
8+
module_path=$(echo $1 | sed -e 's|'$2'||')
9+
else
10+
module_path=$1
11+
fi
12+
713
# Run rspec-puppet tests
814
oldpwd=$(pwd)
915
tmpchangedmodules=''
@@ -22,7 +28,7 @@ changedmodules=$(echo -e "$tmpchangedmodules" | sort -u)
2228
for module_dir in $changedmodules; do
2329
#only run rspec if the "spec" directory exists
2430
if [ -d "${module_dir}/spec" ]; then
25-
echo -e "\e[0;36mRunning rspec-puppet tests for module $1...\e[0m"
31+
echo -e "\e[0;36mRunning rspec-puppet tests for module $module_path...\e[0m"
2632
cd $module_dir
2733
#this will run rspec for every test in the module
2834
rspec > $error_msg

commit_hooks/yaml_syntax_check.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,21 @@
66
syntax_errors=0
77
error_msg=$(mktemp /tmp/error_msg_yaml-syntax.XXXXX)
88

9+
if [ $2 ]; then
10+
module_path=$(echo $1 | sed -e 's|'$2'||')
11+
else
12+
module_path=$1
13+
fi
14+
915
# Get list of new/modified manifest and template files to check (in git index)
1016
# Check YAML file syntax
11-
echo -e "\e[0;36mChecking yaml syntax for $1...\e[0m"
17+
echo -e "\e[0;36mChecking yaml syntax for $module_path...\e[0m"
1218
ruby -e "require 'yaml'; YAML.parse(File.open('$1'))" 2> $error_msg > /dev/null
1319
if [ $? -ne 0 ]; then
1420
echo -en "\e[0;31m"
1521
cat $error_msg
1622
syntax_errors=`expr $syntax_errors + 1`
17-
echo -e "Error: yaml syntax error in $1 (see above)\e[0m"
23+
echo -e "Error: yaml syntax error in $module_path (see above)\e[0m"
1824
fi
1925
rm -f $error_msg
2026

pre-receive

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ while read oldrev newrev refname; do
1313
#check puppet manifest syntax
1414
if type puppet >/dev/null 2>&1; then
1515
if [ $(echo $changedfile | grep -q '\.*.pp$'; echo $?) -eq 0 ]; then
16-
${subhook_root}/puppet_manifest_syntax_check.sh $tmpmodule
16+
${subhook_root}/puppet_manifest_syntax_check.sh $tmpmodule "${tmptree}/"
1717
RC=$?
1818
if [ "$RC" -ne 0 ]; then
1919
failures=`expr $failures + 1`
@@ -27,7 +27,7 @@ while read oldrev newrev refname; do
2727
#check erb (template file) syntax
2828
if type erb >/dev/null 2>&1; then
2929
if [ $(echo $changedfile | grep -q '\.*.erb$'; echo $?) -eq 0 ]; then
30-
${subhook_root}/erb_template_syntax_check.sh $tmpmodule
30+
${subhook_root}/erb_template_syntax_check.sh $tmpmodule "${tmptree}/"
3131
RC=$?
3232
if [ "$RC" -ne 0 ]; then
3333
failures=`expr $failures + 1`
@@ -39,7 +39,7 @@ while read oldrev newrev refname; do
3939

4040
#check hiera data (yaml/yml) syntax
4141
if [ $(echo $changedfile | grep -q '\.*.yaml$\|\.*.yml$'; echo $?) -eq 0 ]; then
42-
${subhook_root}/yaml_syntax_check.sh $tmpmodule
42+
${subhook_root}/yaml_syntax_check.sh $tmpmodule "${tmptree}/"
4343
RC=$?
4444
if [ "$RC" -ne 0 ]; then
4545
failures=`expr $failures + 1`
@@ -52,7 +52,7 @@ while read oldrev newrev refname; do
5252
#puppet manifest styleguide compliance
5353
if type puppet-lint >/dev/null 2>&1; then
5454
if [ $(echo $changedfile | grep -q '\.*.pp$' ; echo $?) -eq 0 ]; then
55-
${subhook_root}/puppet_lint_checks.sh $tmpmodule
55+
${subhook_root}/puppet_lint_checks.sh $tmpmodule "${tmptree}/"
5656
RC=$?
5757
if [ "$RC" -ne 0 ]; then
5858
failures=`expr $failures + 1`

0 commit comments

Comments
 (0)