Skip to content

Commit b25f012

Browse files
committed
refactor: introduce execute-command.sh script for a real command encapsulation
Now it became easy to run a particular check locally with exactly the same parameters as on CI.
1 parent 25a82d8 commit b25f012

File tree

2 files changed

+173
-61
lines changed

2 files changed

+173
-61
lines changed

src/main/scripts/ci/check-build-and-verify.sh

+19-61
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ if [ "${SPRING_PROFILES_ACTIVE:-}" = 'travis' ] && [ "${TRAVIS_PULL_REQUEST:-fal
6565
DANGER_STATUS=
6666
fi
6767

68+
CURDIR="$(dirname "$0")"
69+
EXEC_CMD="$CURDIR/../execute-command.sh"
70+
6871
echo
6972

7073
if [ "$RUN_ONLY_INTEGRATION_TESTS" = 'no' ]; then
@@ -144,130 +147,85 @@ if [ "$RUN_ONLY_INTEGRATION_TESTS" = 'no' ]; then
144147
echo
145148

146149
if [ "$CS_STATUS" != 'skip' ]; then
147-
mvn --batch-mode checkstyle:check -Dcheckstyle.violationSeverity=warning \
148-
>cs.log 2>&1 || CS_STATUS=fail
150+
"$EXEC_CMD" checkstyle >cs.log 2>&1 || CS_STATUS=fail
149151
fi
150152
print_status "$CS_STATUS" 'Run CheckStyle'
151153

152154
if [ "$PMD_STATUS" != 'skip' ]; then
153-
mvn --batch-mode pmd:check \
154-
>pmd.log 2>&1 || PMD_STATUS=fail
155+
"$EXEC_CMD" pmd >pmd.log 2>&1 || PMD_STATUS=fail
155156
fi
156157
print_status "$PMD_STATUS" 'Run PMD'
157158

158159
if [ "$LICENSE_STATUS" != 'skip' ]; then
159-
mvn --batch-mode license:check \
160-
>license.log 2>&1 || LICENSE_STATUS=fail
160+
"$EXEC_CMD" check-license >license.log 2>&1 || LICENSE_STATUS=fail
161161
fi
162162
print_status "$LICENSE_STATUS" 'Check license headers'
163163

164164
if [ "$POM_STATUS" != 'skip' ]; then
165-
mvn --batch-mode sortpom:verify -Dsort.verifyFail=stop \
166-
>pom.log 2>&1 || POM_STATUS=fail
165+
"$EXEC_CMD" check-pom >pom.log 2>&1 || POM_STATUS=fail
167166
fi
168167
print_status "$POM_STATUS" 'Check sorting of pom.xml'
169168

170169
if [ "$BOOTLINT_STATUS" != 'skip' ]; then
171-
find src/main -type f -name '*.html' -print0 | xargs -0 bootlint --disable W013 \
172-
>bootlint.log 2>&1 || BOOTLINT_STATUS=fail
170+
"$EXEC_CMD" bootlint >bootlint.log 2>&1 || BOOTLINT_STATUS=fail
173171
fi
174172
print_status "$BOOTLINT_STATUS" 'Run bootlint'
175173

176174
if [ "$RFLINT_STATUS" != 'skip' ]; then
177-
rflint \
178-
--error=all \
179-
--ignore TooFewKeywordSteps \
180-
--configure LineTooLong:130 \
181-
src/test/robotframework \
182-
>rflint.log 2>&1 || RFLINT_STATUS=fail
175+
"$EXEC_CMD" rflint >rflint.log 2>&1 || RFLINT_STATUS=fail
183176
fi
184177
print_status "$RFLINT_STATUS" 'Run robot framework lint'
185178

186179
if [ "$SHELLCHECK_STATUS" != 'skip' ]; then
187-
# Shellcheck doesn't support recursive scanning: https://github.com/koalaman/shellcheck/issues/143
188-
# Also I don't want to invoke it many times (slower, more code for handling failures), so I prefer this way.
189-
# shellcheck disable=SC2207
190-
SHELL_FILES=( $(find src/main/scripts -type f -name '*.sh') )
191-
shellcheck \
192-
--shell bash \
193-
--format gcc \
194-
"${SHELL_FILES[@]}" \
195-
>shellcheck.log 2>&1 || SHELLCHECK_STATUS=fail
180+
"$EXEC_CMD" shellcheck >shellcheck.log 2>&1 || SHELLCHECK_STATUS=fail
196181
fi
197182
print_status "$SHELLCHECK_STATUS" 'Run shellcheck'
198183

199184
if [ "$JASMINE_STATUS" != 'skip' ]; then
200-
mvn --batch-mode jasmine:test \
201-
>jasmine.log 2>&1 || JASMINE_STATUS=fail
185+
"$EXEC_CMD" jasmine >jasmine.log 2>&1 || JASMINE_STATUS=fail
202186
fi
203187
print_status "$JASMINE_STATUS" 'Run JavaScript unit tests'
204188

205189
if [ "$HTML_STATUS" != 'skip' ]; then
206-
# FIXME: remove ignoring of error about alt attribute after resolving #314
207-
# @todo #109 Check src/main/config/nginx/503.*html by html5validator
208-
# @todo #695 /series/import/request/{id}: use divs instead of table for elements aligning
209-
html5validator \
210-
--root src/main/webapp/WEB-INF/views \
211-
--no-langdetect \
212-
--ignore-re \
213-
'Attribute “(th|sec|togglz|xmlns):[a-z]+” not allowed' \
214-
'Attribute “th:[-a-z]+” not allowed on element "body" at this point' \
215-
'Attribute “(th|sec|togglz):[-a-z]+” is not serializable' \
216-
'Attribute with the local name “xmlns:[a-z]+” is not serializable' \
217-
--ignore \
218-
'An "img" element must have an "alt" attribute' \
219-
'Element "option" without attribute "label" must not be empty' \
220-
'The "width" attribute on the "td" element is obsolete' \
221-
--show-warnings \
222-
>validator.log 2>&1 || HTML_STATUS=fail
190+
"$EXEC_CMD" html5validator >validator.log 2>&1 || HTML_STATUS=fail
223191
fi
224192
print_status "$HTML_STATUS" 'Run html5validator'
225193

226194
if [ "$ENFORCER_STATUS" != 'skip' ]; then
227-
mvn --batch-mode enforcer:enforce \
228-
>enforcer.log 2>&1 || ENFORCER_STATUS=fail
195+
"$EXEC_CMD" enforcer >enforcer.log 2>&1 || ENFORCER_STATUS=fail
229196
fi
230197
print_status "$ENFORCER_STATUS" 'Run maven-enforcer-plugin'
231198

232199
if [ "$TEST_STATUS" != 'skip' ]; then
233-
mvn --batch-mode test -Denforcer.skip=true -DskipMinify=true -DdisableXmlReport=false -Dskip.npm -Dskip.installnodenpm \
234-
>test.log 2>&1 || TEST_STATUS=fail
200+
"$EXEC_CMD" unit-tests >test.log 2>&1 || TEST_STATUS=fail
235201
fi
236202
print_status "$TEST_STATUS" 'Run unit tests'
237203

238204
if [ "$CODENARC_STATUS" != 'skip' ]; then
239205
# run after tests for getting compiled sources
240-
mvn --batch-mode codenarc:codenarc -Dcodenarc.maxPriority1Violations=0 -Dcodenarc.maxPriority2Violations=0 -Dcodenarc.maxPriority3Violations=0 \
241-
>codenarc.log 2>&1 || CODENARC_STATUS=fail
206+
"$EXEC_CMD" codenarc >codenarc.log 2>&1 || CODENARC_STATUS=fail
242207
fi
243208
print_status "$CODENARC_STATUS" 'Run CodeNarc'
244209

245210
if [ "$SPOTBUGS_STATUS" != 'skip' ]; then
246211
# run after tests for getting compiled sources
247-
mvn --batch-mode spotbugs:check \
248-
>spotbugs.log 2>&1 || SPOTBUGS_STATUS=fail
212+
"$EXEC_CMD" spotbugs >spotbugs.log 2>&1 || SPOTBUGS_STATUS=fail
249213
fi
250214
print_status "$SPOTBUGS_STATUS" 'Run SpotBugs'
251215

252216
if [ "$ANSIBLE_LINT_STATUS" != 'skip' ]; then
253-
ansible-lint \
254-
infra/vagrant/provisioning/prod.yml \
255-
infra/vagrant/provisioning/vagrant.yml \
256-
infra/vagrant/provisioning/bootstrap.yml \
257-
src/main/scripts/ci/ansible/deploy.yml \
258-
>ansible_lint.log 2>&1 || ANSIBLE_LINT_STATUS=fail
217+
"$EXEC_CMD" ansible-lint >ansible_lint.log 2>&1 || ANSIBLE_LINT_STATUS=fail
259218
fi
260219
print_status "$ANSIBLE_LINT_STATUS" 'Run Ansible Lint'
261220
fi
262221

263-
mvn --batch-mode --activate-profiles frontend,native2ascii verify -Denforcer.skip=true -DskipUnitTests=true \
264-
>verify.log 2>&1 || VERIFY_STATUS=fail
222+
"$EXEC_CMD" integration-tests >verify.log 2>&1 || VERIFY_STATUS=fail
265223

266224
print_status "$VERIFY_STATUS" 'Run integration tests'
267225

268226

269227
if [ "$DANGER_STATUS" != 'skip' ]; then
270-
danger >danger.log 2>&1 || DANGER_STATUS=fail
228+
"$EXEC_CMD" danger >danger.log 2>&1 || DANGER_STATUS=fail
271229
fi
272230
print_status "$DANGER_STATUS" 'Run danger'
273231

src/main/scripts/execute-command.sh

+154
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
#!/bin/bash
2+
3+
# Treat unset variables and parameters as an error when performing parameter expansion
4+
set -o nounset
5+
6+
# Exit immediately if command returns a non-zero status
7+
set -o errexit
8+
9+
# Return value of a pipeline is the value of the last command to exit with a non-zero status
10+
set -o pipefail
11+
12+
ROOTDIR="$(dirname "$0")/../../.."
13+
14+
MVN=mvn
15+
16+
case ${1:-} in
17+
'ansible-lint')
18+
exec ansible-lint \
19+
"$ROOTDIR/infra/vagrant/provisioning/prod.yml" \
20+
"$ROOTDIR/infra/vagrant/provisioning/vagrant.yml" \
21+
"$ROOTDIR/infra/vagrant/provisioning/bootstrap.yml" \
22+
"$ROOTDIR/src/main/scripts/ci/ansible/deploy.yml"
23+
;;
24+
'bootlint')
25+
find "$ROOTDIR/src/main" \
26+
-type f \
27+
-name '*.html' \
28+
-print0 \
29+
| xargs -0 bootlint --disable W013
30+
;;
31+
'check-license')
32+
exec "$MVN" \
33+
--batch-mode \
34+
license:check
35+
;;
36+
'check-pom')
37+
exec "$MVN" \
38+
--batch-mode \
39+
sortpom:verify \
40+
-Dsort.verifyFail=stop
41+
;;
42+
'checkstyle')
43+
exec "$MVN" \
44+
--batch-mode \
45+
checkstyle:check \
46+
-Dcheckstyle.violationSeverity=warning
47+
;;
48+
'codenarc')
49+
exec "$MVN" \
50+
--batch-mode \
51+
codenarc:codenarc \
52+
-Dcodenarc.maxPriority1Violations=0 \
53+
-Dcodenarc.maxPriority2Violations=0 \
54+
-Dcodenarc.maxPriority3Violations=0
55+
;;
56+
'danger')
57+
exec danger
58+
;;
59+
'enforcer')
60+
exec "$MVN" \
61+
--batch-mode \
62+
enforcer:enforce
63+
;;
64+
'html5validator')
65+
# FIXME: remove ignoring of error about alt attribute after resolving #314
66+
# @todo #109 Check src/main/config/nginx/503.*html by html5validator
67+
# @todo #695 /series/import/request/{id}: use divs instead of table for elements aligning
68+
exec html5validator \
69+
--root "$ROOTDIR/src/main/webapp/WEB-INF/views" \
70+
--no-langdetect \
71+
--ignore-re \
72+
'Attribute “(th|sec|togglz|xmlns):[a-z]+” not allowed' \
73+
'Attribute “th:[-a-z]+” not allowed on element "body" at this point' \
74+
'Attribute “(th|sec|togglz):[-a-z]+” is not serializable' \
75+
'Attribute with the local name “xmlns:[a-z]+” is not serializable' \
76+
--ignore \
77+
'An "img" element must have an "alt" attribute' \
78+
'Element "option" without attribute "label" must not be empty' \
79+
'The "width" attribute on the "td" element is obsolete' \
80+
--show-warnings
81+
;;
82+
'integration-tests')
83+
exec "$MVN" \
84+
--batch-mode \
85+
--activate-profiles frontend,native2ascii \
86+
verify \
87+
-Denforcer.skip=true \
88+
-DskipUnitTests=true
89+
;;
90+
'jasmine')
91+
exec "$MVN" \
92+
--batch-mode \
93+
jasmine:test
94+
;;
95+
'pmd')
96+
exec "$MVN" \
97+
--batch-mode \
98+
pmd:check
99+
;;
100+
'rflint')
101+
exec rflint \
102+
--error=all \
103+
--ignore TooFewKeywordSteps \
104+
--configure LineTooLong:130 \
105+
"$ROOTDIR/src/test/robotframework"
106+
;;
107+
'shellcheck')
108+
# Shellcheck doesn't support recursive scanning: https://github.com/koalaman/shellcheck/issues/143
109+
# Also I don't want to invoke it many times (slower, more code for handling failures), so I prefer this way.
110+
# shellcheck disable=SC2207
111+
SHELL_FILES=( $(find "$ROOTDIR/src/main/scripts" -type f -name '*.sh') )
112+
exec shellcheck \
113+
--shell bash \
114+
--format gcc \
115+
"${SHELL_FILES[@]}"
116+
;;
117+
'spotbugs')
118+
exec "$MVN" \
119+
--batch-mode \
120+
spotbugs:check
121+
;;
122+
'unit-tests')
123+
exec "$MVN" \
124+
--batch-mode \
125+
test \
126+
-Denforcer.skip=true \
127+
-DskipMinify=true \
128+
-DdisableXmlReport=false \
129+
-Dskip.npm \
130+
-Dskip.installnodenpm
131+
;;
132+
*)
133+
echo >&2 "Usage: $0 <command>"
134+
echo >&2
135+
echo >&2 "Where <command> is one of:"
136+
echo >&2 '- ansible-lint'
137+
echo >&2 '- bootlint'
138+
echo >&2 '- check-license'
139+
echo >&2 '- check-pom'
140+
echo >&2 '- checkstyle'
141+
echo >&2 '- codenarc'
142+
echo >&2 '- danger'
143+
echo >&2 '- enforcer'
144+
echo >&2 '- html5validator'
145+
echo >&2 '- integration-tests'
146+
echo >&2 '- jasmine'
147+
echo >&2 '- pmd'
148+
echo >&2 '- rflint'
149+
echo >&2 '- shellcheck'
150+
echo >&2 '- spotbugs'
151+
echo >&2 '- unit-tests'
152+
exit 1
153+
;;
154+
esac

0 commit comments

Comments
 (0)