-
Notifications
You must be signed in to change notification settings - Fork 41
/
runtests
executable file
·114 lines (98 loc) · 2.29 KB
/
runtests
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env bash
set -o errexit
set -o pipefail
main() {
local force env_file
while [[ "${1}" ]]; do
case "${1}" in
'--force' | '-f')
force=1
shift
continue
;;
'--env' | '-e')
env_file="${2}"
shift 2
continue
;;
'--')
shift
break
;;
*)
echo "Unknown option '${1}'" >&2
exit 1
;;
esac
done
if [[ ! "${force}" ]]; then
__assert_no_changes
fi
local terraform
terraform="$(make -f terraform-common.mk .echo-tf)"
if [[ "${env_file}" ]]; then
echo "Running isolated with env ${env_file}"
local exec_opts
if [[ "${force}" ]]; then
exec_opts='--force'
fi
exec env -i \
HOME="${HOME}" \
PATH="${PATH}" \
TERM="${TERM}" \
LANG="${LANG}" \
GEM_HOME="${GEM_HOME}" \
GEM_PATH="${GEM_PATH}" \
bash -c "source '${env_file}' && bash ${BASH_SOURCE[0]} ${exec_opts}"
fi
for f in $(git ls-files '*.json'); do
echo -en "$f "
python -m json.tool <"${f}" >/dev/null
echo "✓"
done
for f in $(git ls-files '*/Makefile'); do
echo -en "${f} "
make -C "$(dirname "${f}")" -p >/dev/null
echo "✓"
done
echo 'Running shellcheck'
shfmt -l . | xargs shellcheck
echo 'Running shfmt'
shfmt -i 2 -w .
echo 'Running bats'
for f in $(git ls-files '*.bats'); do
echo "${f}"
bats -t "${f}"
done
echo 'Running rubocop'
bundle exec rubocop
for d in $(git ls-files '*.tf' | xargs -n1 dirname | LC_ALL=C sort | uniq); do
echo -en "${d} "
if [[ -f "${d}/Makefile" ]]; then
terraform="$(make -f "${d}/Makefile" .echo-tf)"
else
terraform="$(make -f terraform-common.mk .echo-tf)"
fi
if [[ -f "${d}/.terraform-validate-flags" ]]; then
# shellcheck disable=SC2046
"${terraform}" validate $(cat "${d}/.terraform-validate-flags") "${d}"
else
"${terraform}" validate -check-variables=false "${d}"
fi
echo "✓"
done
echo 'Running terraform fmt'
"${terraform}" fmt
}
__assert_no_changes() {
# abort if there are uncommitted local changes
if ! git diff-index --quiet HEAD --; then
cat <<EOF
You have uncommitted changes.
Not proceeding, as this script changes some files in place.
(Use --force to override)
EOF
exit 1
fi
}
main "$@"