Skip to content

Commit 185b74d

Browse files
simondezielcmeissner
authored andcommitted
Make check depend to yamllint or ruby
* Do not hardcode path to yamllint * Run yaml checks when yamllint or ruby is available
1 parent c15329e commit 185b74d

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

commit_hooks/yaml_syntax_check.sh

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ fi
2222

2323
# Check YAML file syntax
2424
$ERRORS_ONLY || echo -e "$(tput setaf 6)Checking yaml syntax for $module_path...$(tput sgr0)"
25-
if test -e /usr/bin/yamllint
26-
then
25+
if type yamllint > /dev/null 2>&1; then
2726
yamllint $YAMLLINT_CONFIG -f parsable $1 &> "$error_msg"
2827
else
2928
ruby -e "require 'yaml'; YAML.parse(File.open('$1'))" 2> "$error_msg" > /dev/null

pre-commit

+11-7
Original file line numberDiff line numberDiff line change
@@ -110,25 +110,29 @@ for changedfile in $files_to_check; do
110110
echo "erb not installed. Skipping erb template checks..."
111111
fi
112112

113-
#check hiera data (yaml/yml/eyaml/eyml) syntax
114-
if echo "$changedfile" | grep -iq '\.e\?ya\?ml$'; then
115-
${subhook_root}/yaml_syntax_check.sh "$changedfile"
113+
#check json (i.e. metadata.json) syntax
114+
if echo "$changedfile" | grep -iq '\.json$'; then
115+
${subhook_root}/json_syntax_check.sh "$changedfile"
116116
RC=$?
117117
if [[ "$RC" -ne 0 ]]; then
118118
failures=$((failures + 1))
119119
fi
120120
fi
121+
else
122+
echo "ruby not installed. Skipping erb/json checks..."
123+
fi
121124

122-
#check json (i.e. metadata.json) syntax
123-
if echo "$changedfile" | grep -iq '\.json$'; then
124-
${subhook_root}/json_syntax_check.sh "$changedfile"
125+
if type yamllint >/dev/null 2>&1 || type ruby >/dev/null 2>&1; then
126+
#check hiera data (yaml/yml/eyaml/eyml) syntax
127+
if echo "$changedfile" | grep -iq '\.e\?ya\?ml$'; then
128+
${subhook_root}/yaml_syntax_check.sh "$changedfile"
125129
RC=$?
126130
if [[ "$RC" -ne 0 ]]; then
127131
failures=$((failures + 1))
128132
fi
129133
fi
130134
else
131-
echo "ruby not installed. Skipping erb/yaml/json checks..."
135+
echo "yamllint nor ruby not installed. Skipping yaml checks..."
132136
fi
133137

134138
#puppet manifest styleguide compliance

pre-receive

+11-7
Original file line numberDiff line numberDiff line change
@@ -116,25 +116,29 @@ while read -r oldrev newrev refname; do
116116
echo "erb not installed. Skipping erb template checks..."
117117
fi
118118

119-
#check hiera data (yaml/yml) syntax
120-
if [[ $(echo "$changedfile" | grep -q '\.*\.yaml$\|\.*\.yml$'; echo $?) -eq 0 ]]; then
121-
${subhook_root}/yaml_syntax_check.sh "$tmpmodule" "${tmptree}/"
119+
#check hiera data (json) syntax
120+
if [[ $(echo "$changedfile" | grep -q '\.*\.json$'; echo $?) -eq 0 ]]; then
121+
${subhook_root}/json_syntax_check.sh "$tmpmodule" "${tmptree}/"
122122
RC=$?
123123
if [[ $RC -ne 0 ]]; then
124124
failures=$((failures + 1))
125125
fi
126126
fi
127+
else
128+
echo "ruby not installed. Skipping ruby/erb/json checks..."
129+
fi
127130

128-
#check hiera data (json) syntax
129-
if [[ $(echo "$changedfile" | grep -q '\.*\.json$'; echo $?) -eq 0 ]]; then
130-
${subhook_root}/json_syntax_check.sh "$tmpmodule" "${tmptree}/"
131+
if type yamllint >/dev/null 2>&1 || type ruby >/dev/null 2>&1; then
132+
#check hiera data (yaml/yml/eyaml/eyml) syntax
133+
if echo "$changedfile" | grep -iq '\.e\?ya\?ml$'; then
134+
${subhook_root}/yaml_syntax_check.sh "$tmpmodule" "${tmptree}/"
131135
RC=$?
132136
if [[ $RC -ne 0 ]]; then
133137
failures=$((failures + 1))
134138
fi
135139
fi
136140
else
137-
echo "ruby not installed. Skipping erb/yaml/ruby checks..."
141+
echo "yamllint nor ruby not installed. Skipping yaml checks..."
138142
fi
139143

140144
#puppet manifest styleguide compliance

0 commit comments

Comments
 (0)