-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathmanaged_script_check_style.sh
More file actions
executable file
·74 lines (61 loc) · 1.98 KB
/
managed_script_check_style.sh
File metadata and controls
executable file
·74 lines (61 loc) · 1.98 KB
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
#
# Script wich catches the modified files from the latest commit in a git repository and
# runs a puppet-lint check on them
#
# Variables to be set:
#
# PUPPET_SUBDIR
#
# PUPPET_LINT_THREADS, PUPPET_LINT_SKIP_TESTS, PUPPET_LINT_SKIP_EXAMPLES,
# PUPPET_LINT_BIN, PUPPET_LINT_FAILS_WARNING, PUPPET_LINT_FAILS_ERROR
#
# CHANGED_FILES: you can pass the list of files which have to be checked
GIT_PREVIOUS_COMMIT="${GIT_PREVIOUS_COMMIT-HEAD^}"
[ "$EXTRA_PATH" ] && export PATH="$EXTRA_PATH:$PATH";
# you can pass changed files in the variable/parameter CHANGED_FILES
[ -z "$CHANGED_FILES" ] && CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRTUXB HEAD ${GIT_PREVIOUS_COMMIT})
printenv | sort
manifests_exclude="${1-autoloader_layout}"
module_exclude="${2}"
style_script="$(cd $(dirname "$0"); pwd)/../check_puppet_style/check_puppet_style.sh"
# Catch the modified .pp manifests, puts them in an array and use that array to peform the puppet-style checks
declare -a files
for FILE in $(echo $CHANGED_FILES | tr ' ' '\n' | grep ".pp$");
do
files=("${files[@]}" $FILE)
done
if [ ${#files[@]} -eq 0 ];then
echo "No modified manifests to check"
else
for i in ${files[@]};
do
echo "Stylecheck on manifest $i:";
bash -e "${style_script}" -x "${manifests_exclude}" $i || manifests_failed=1
done
fi
# Catch the modified modules, puts them in an array and use that array to peform the puppet-style checks
declare -a modules
for MODULE in $(echo $CHANGED_FILES | tr ' ' '\n' | grep "^modules/");
do
modules=("${modules[@]}" $MODULE)
done
if [ ${#modules[@]} -eq 0 ];then
echo "No modified modules to check"
else
for i in ${modules[@]};
do
echo "Stylecheck on module $i:";
bash -e "${style_script}" -x "${module_exclude}" $i || module_failed=1
done
fi
failed=0
if [ "$manifests_failed" == "1" ]; then
echo "Style check on manifests dir failed";
failed=1;
fi
if [ "$module_failed" == "1" ]; then
echo "Style check on modules failed";
failed=1;
fi;
[ "$failed" == "0" ] || exit 1;