-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathdev.sh
executable file
·226 lines (188 loc) · 5.36 KB
/
dev.sh
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/bin/bash
set -eu
# 1: cd dir
# 2: args and code dir
run_pylint() {
# we use the column command to format data, but not all shells/distributions have it
# so just make a passthrough alias
if ! command -v column >/dev/null; then
column() {
cat
}
fi
cd_dir="$1"
shift
args_and_code_dir="$*"
cd "$cd_dir"
set +e
# shellcheck disable=SC2086
output=$(pylint --rcfile ../.sanity-config.ini $args_and_code_dir)
exit_code="$?"
set -e
# shellcheck disable=SC2103
cd ..
echo "$output" \
| jq -r '.[] | .path + "|" + (.line|tostring) + ":" + (.column|tostring) + "|" + .obj + " |" + ."message-id" + "|" + .symbol + "|" + .message' \
| sort --unique \
| column -t -s "|"
return "$exit_code"
}
run_shellcheck() {
files="$(find . -type f -name "*.sh" -not -path "*.venv*")"
aggregate_exit_code="0"
while read -r line; do
set +e
shellcheck --format tty "$line"
exit_code="$?"
set -e
aggregate_exit_code="$((aggregate_exit_code + exit_code))"
done <<< "$files"
return "$aggregate_exit_code"
}
check_commit_messages() {
since=231884e0bb63e764ad23b2e55e5a1e726bc2c11e
echo "Checking git messages from $since to HEAD..."
commits="$(git log "${since}..HEAD" --pretty=format:"%H %s")"
echo "Found commits:"
echo "$commits"
echo
# shellcheck disable=SC1117
commits_with_trailing_period="$(echo -n "$commits" | grep -Ee ".*\.\s*$")"
if [ -z "$commits_with_trailing_period" ]; then
number_of_trailing_periods=0
else
number_of_trailing_periods="$(echo "$commits_with_trailing_period" | wc -l)"
fi
echo "Found $number_of_trailing_periods commits with a trailing period"
echo "$commits_with_trailing_period"
echo
if [ "$number_of_trailing_periods" -gt 0 ]; then
echo "Commits must not have a trailing period in their commit summary."
return 7
fi
return 0
}
run_sanity() {
set +e
echo "Running pylint (source)"
output_pylint_src=$(run_pylint src/ opera/)
code_pylint_src="$?"
echo "Running pylint (tests)"
output_pylint_test=$(run_pylint tests/ --disable no-self-use --disable expression-not-assigned unit/)
code_pylint_test="$?"
echo "Running flake8"
output_flake8=$(flake8 --statistics --config .sanity-config.ini)
code_flake8="$?"
echo "Running mypy"
output_mypy=$(mypy --config-file .sanity-config.ini src/opera/ tests/unit/)
code_mypy="$?"
echo "Running bandit"
output_bandit=$(bandit --recursive --aggregate file --format txt src/opera/ 2>&1)
code_bandit="$?"
echo "Running pydocstyle"
output_pydocstyle=$(pydocstyle --count --explain --config .sanity-config.ini src/opera/)
code_pydocstyle="$?"
echo "Running shellcheck"
output_shellcheck=$(run_shellcheck)
code_shellcheck="$?"
echo "Checking commit messages"
output_commit_messages=$(check_commit_messages)
code_commit_messages="$?"
set -e
echo "pylint (src) output"
echo "$code_pylint_src"
echo "$output_pylint_src"
echo "### pylint (tests) output ###"
echo "exit code: $code_pylint_test"
echo "$output_pylint_test"
echo "### flake8 output ###"
echo "exit code: $code_flake8"
echo "$output_flake8"
echo "### shellcheck output ###"
echo "exit code: $code_shellcheck"
echo "$output_shellcheck"
echo "### mypy output ###"
echo "exit code: $code_mypy"
echo "$output_mypy"
echo "### bandit output ###"
echo "exit code: $code_bandit"
echo "$output_bandit"
echo "### pydocstyle output ###"
echo "exit code: $code_pydocstyle"
echo "$output_pydocstyle"
echo "### shellcheck output ###"
echo "exit code: $code_shellcheck"
echo "$output_shellcheck"
echo "### commit message check output ###"
echo "exit code: $code_commit_messages"
echo "$output_commit_messages"
echo "Applied overrides:"
grep -rinEe "noqa:|pylint:|nosec|# shellcheck" \
--exclude-dir ".venv/" \
--exclude-dir ".eggs/" \
--exclude-dir ".git/" \
--exclude-dir ".mypy_cache/" \
--exclude-dir ".pytest_cache/" \
.
combined_exit_code="$((
code_pylint_src
+ code_pylint_test
+ code_flake8
+ code_mypy
+ code_bandit
+ code_pydocstyle
+ code_shellcheck
+ code_commit_messages
))"
exit "$combined_exit_code"
}
run_unit() {
pytest tests/unit/
}
run_coverage() {
pytest --cov=opera --cov-report=xml tests/unit/
}
run_integration() {
for dir in tests/integration/*/; do (cd "$dir" && ./runme.sh opera); done
}
run_help() {
cat <<EOF
usage:
./dev.sh <command>
commands:
sanity runs sanity tests
unit runs unit tests
integration runs integration tests
coverage calculates code coverage
help shows this help
EOF
}
if [ $# -ne 1 ]
then
echo -e "No arguments were supplied\n"
run_help
exit 1
fi
command="$1"
shift
case "$command" in
sanity)
run_sanity
;;
unit)
run_unit
;;
coverage)
run_coverage
;;
integration)
run_integration
;;
help)
run_help
;;
*)
echo -e "Invalid command: $command\n"
run_help
;;
esac