Skip to content

Commit 7cb4c8b

Browse files
committed
Merge branch 'gh470_shellcheck'
Add support for scanning shell script by shellcheck. Fix #470
2 parents 5492488 + 1ac2b47 commit 7cb4c8b

File tree

6 files changed

+76
-24
lines changed

6 files changed

+76
-24
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ before_script:
2424
if [ "$TRAVIS_PULL_REQUEST" != 'false' ]; then
2525
gem install danger nokogiri --no-ri --no-rdoc;
2626
fi;
27+
sudo apt-get -qq update;
28+
sudo apt-get install -y shellcheck;
2729
fi
2830

2931
script:

Dangerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,32 @@ if File.file?(rflint_output)
270270
print_errors_summary 'rflint', errors_count, 'https://github.com/php-coder/mystamps/wiki/rflint'
271271
end
272272

273+
# Handle shellcheck output
274+
#
275+
# Example:
276+
# src/main/scripts/ci/deploy.sh:29:24: note: Double quote to prevent globbing and word splitting. [SC2086]
277+
# src/main/scripts/ci/common.sh:28:2: note: egrep is non-standard and deprecated. Use grep -E instead. [SC2196]
278+
#
279+
shellcheck_output = 'shellcheck.log'
280+
if File.file?(shellcheck_output)
281+
errors_count = 0
282+
File.readlines(shellcheck_output).each do |line|
283+
errors_count += 1
284+
285+
parsed = line.match(/^(?<file>[^:]+):(?<line>\d+):\d+:[^:]+: (?<msg>.+)/)
286+
file = parsed['file']
287+
lineno = parsed['line']
288+
msg = parsed['msg']
289+
msg, _, code = msg.rpartition('[')
290+
msg = msg.rstrip.sub(/\.$/, '')
291+
code = code.sub(/\]$/, '')
292+
file = github.html_link("#{file}#L#{lineno}")
293+
fail("shellcheck error in #{file}:\n[#{code}](https://github.com/koalaman/shellcheck/wiki/#{code}): #{msg}")
294+
end
295+
# TODO: add link to wiki page
296+
print_errors_summary 'shellcheck', errors_count
297+
end
298+
273299
# Handle `mvn enforcer:enforce` results
274300
#
275301
# Example:

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

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ if [ "${1:-}" = '--only-integration-tests' ]; then
1515
RUN_ONLY_INTEGRATION_TESTS=yes
1616
fi
1717

18+
# shellcheck source=src/main/scripts/ci/common.sh
1819
. "$(dirname "$0")/common.sh"
1920

2021
CS_STATUS=
@@ -23,6 +24,7 @@ LICENSE_STATUS=
2324
POM_STATUS=
2425
BOOTLINT_STATUS=
2526
RFLINT_STATUS=
27+
SHELLCHECK_STATUS=
2628
JASMINE_STATUS=
2729
HTML_STATUS=
2830
ENFORCER_STATUS=
@@ -32,7 +34,7 @@ FINDBUGS_STATUS=
3234
VERIFY_STATUS=
3335

3436
DANGER_STATUS=skip
35-
if [ "${SPRING_PROFILES_ACTIVE:-}" = 'travis' -a "${TRAVIS_PULL_REQUEST:-false}" != 'false' ]; then
37+
if [ "${SPRING_PROFILES_ACTIVE:-}" = 'travis' ] && [ "${TRAVIS_PULL_REQUEST:-false}" != 'false' ]; then
3638
DANGER_STATUS=
3739
fi
3840

@@ -46,20 +48,21 @@ if [ "$RUN_ONLY_INTEGRATION_TESTS" = 'no' ]; then
4648
if [ -n "${TRAVIS_COMMIT_RANGE:-}" ]; then
4749
echo "INFO: Range of the commits to be checked: $TRAVIS_COMMIT_RANGE"
4850
echo 'INFO: List of the files modified by this commits range:'
49-
git --no-pager diff --name-only $TRAVIS_COMMIT_RANGE -- | sed 's|^| |' || :
51+
git --no-pager diff --name-only "$TRAVIS_COMMIT_RANGE" -- | sed 's|^| |' || :
5052

51-
MODIFIED_FILES="$(git --no-pager diff --name-only $TRAVIS_COMMIT_RANGE -- 2>/dev/null || :)"
53+
MODIFIED_FILES="$(git --no-pager diff --name-only "$TRAVIS_COMMIT_RANGE" -- 2>/dev/null || :)"
5254

5355
if [ -n "$MODIFIED_FILES" ]; then
54-
AFFECTS_POM_XML="$(echo "$MODIFIED_FILES" | fgrep -xq 'pom.xml' || echo 'no')"
55-
AFFECTS_TRAVIS_CFG="$(echo "$MODIFIED_FILES" | fgrep -xq '.travis.yml' || echo 'no')"
56-
AFFECTS_CS_CFG="$(echo "$MODIFIED_FILES" | egrep -q '(checkstyle\.xml|checkstyle-suppressions\.xml)$' || echo 'no')"
56+
AFFECTS_POM_XML="$(echo "$MODIFIED_FILES" | grep -Fxq 'pom.xml' || echo 'no')"
57+
AFFECTS_TRAVIS_CFG="$(echo "$MODIFIED_FILES" | grep -Fxq '.travis.yml' || echo 'no')"
58+
AFFECTS_CS_CFG="$(echo "$MODIFIED_FILES" | grep -Eq '(checkstyle\.xml|checkstyle-suppressions\.xml)$' || echo 'no')"
5759
AFFECTS_FB_CFG="$(echo "$MODIFIED_FILES" | grep -q 'findbugs-filter\.xml$' || echo 'no')"
5860
AFFECTS_PMD_XML="$(echo "$MODIFIED_FILES" | grep -q 'pmd\.xml$' || echo 'no')"
5961
AFFECTS_JS_FILES="$(echo "$MODIFIED_FILES" | grep -q '\.js$' || echo 'no')"
6062
AFFECTS_HTML_FILES="$(echo "$MODIFIED_FILES" | grep -q '\.html$' || echo 'no')"
6163
AFFECTS_JAVA_FILES="$(echo "$MODIFIED_FILES" | grep -q '\.java$' || echo 'no')"
6264
AFFECTS_ROBOT_FILES="$(echo "$MODIFIED_FILES" | grep -q '\.robot$' || echo 'no')"
65+
AFFECTS_SHELL_FILES="$(echo "$MODIFIED_FILES" | grep -q '\.sh$' || echo 'no')"
6366
AFFECTS_GROOVY_FILES="$(echo "$MODIFIED_FILES" | grep -q '\.groovy$' || echo 'no')"
6467
AFFECTS_PROPERTIES="$(echo "$MODIFIED_FILES" | grep -q '\.properties$' || echo 'no')"
6568
AFFECTS_LICENSE_HEADER="$(echo "$MODIFIED_FILES" | grep -q 'license_header\.txt$' || echo 'no')"
@@ -70,9 +73,12 @@ if [ "$RUN_ONLY_INTEGRATION_TESTS" = 'no' ]; then
7073

7174
if [ "$AFFECTS_JAVA_FILES" = 'no' ]; then
7275
[ "$AFFECTS_FB_CFG" != 'no' ] || FINDBUGS_STATUS=skip
73-
[ "$AFFECTS_CS_CFG" != 'no' -o "$AFFECTS_PROPERTIES" != 'no' ] || CS_STATUS=skip
7476
[ "$AFFECTS_PMD_XML" != 'no' ] || PMD_STATUS=skip
7577

78+
if [ "$AFFECTS_CS_CFG" = 'no' ] && [ "$AFFECTS_PROPERTIES" = 'no' ]; then
79+
CS_STATUS=skip
80+
fi
81+
7682
if [ "$AFFECTS_GROOVY_FILES" = 'no' ]; then
7783
TEST_STATUS=skip
7884

@@ -90,6 +96,7 @@ if [ "$RUN_ONLY_INTEGRATION_TESTS" = 'no' ]; then
9096
HTML_STATUS=skip
9197
fi
9298
[ "$AFFECTS_ROBOT_FILES" != 'no' ] || RFLINT_STATUS=skip
99+
[ "$AFFECTS_SHELL_FILES" != 'no' ] || SHELLCHECK_STATUS=skip
93100
fi
94101
echo 'INFO: Some checks could be skipped'
95102
else
@@ -128,7 +135,7 @@ if [ "$RUN_ONLY_INTEGRATION_TESTS" = 'no' ]; then
128135
print_status "$POM_STATUS" 'Check sorting of pom.xml'
129136

130137
if [ "$BOOTLINT_STATUS" != 'skip' ]; then
131-
find src -type f -name '*.html' | xargs bootlint \
138+
find src -type f -name '*.html' -print0 | xargs -0 bootlint \
132139
>bootlint.log 2>&1 || BOOTLINT_STATUS=fail
133140
fi
134141
print_status "$BOOTLINT_STATUS" 'Run bootlint'
@@ -146,6 +153,16 @@ if [ "$RUN_ONLY_INTEGRATION_TESTS" = 'no' ]; then
146153
fi
147154
print_status "$RFLINT_STATUS" 'Run robot framework lint'
148155

156+
if [ "$SHELLCHECK_STATUS" != 'skip' ]; then
157+
SHELL_FILES=( $(find src/main/scripts -type f -name '*.sh') )
158+
shellcheck \
159+
--shell bash \
160+
--format gcc \
161+
"${SHELL_FILES[@]}" \
162+
>shellcheck.log 2>&1 || SHELLCHECK_STATUS=fail
163+
fi
164+
print_status "$SHELLCHECK_STATUS" 'Run shellcheck'
165+
149166
if [ "$JASMINE_STATUS" != 'skip' ]; then
150167
mvn --batch-mode jasmine:test \
151168
>jasmine.log 2>&1 || JASMINE_STATUS=fail
@@ -213,18 +230,19 @@ fi
213230
print_status "$DANGER_STATUS" 'Run danger'
214231

215232
if [ "$RUN_ONLY_INTEGRATION_TESTS" = 'no' ]; then
216-
[ "$CS_STATUS" = 'skip' ] || print_log cs.log 'Run CheckStyle'
217-
[ "$PMD_STATUS" = 'skip' ] || print_log pmd.log 'Run PMD'
218-
[ "$LICENSE_STATUS" = 'skip' ] || print_log license.log 'Check license headers'
219-
[ "$POM_STATUS" = 'skip' ] || print_log pom.log 'Check sorting of pom.xml'
220-
[ "$BOOTLINT_STATUS" = 'skip' ] || print_log bootlint.log 'Run bootlint'
221-
[ "$RFLINT_STATUS" = 'skip' ] || print_log rflint.log 'Run robot framework lint'
222-
[ "$JASMINE_STATUS" = 'skip' ] || print_log jasmine.log 'Run JavaScript unit tests'
223-
[ "$HTML_STATUS" = 'skip' ] || print_log validator.log 'Run html5validator'
224-
[ "$ENFORCER_STATUS" = 'skip' ] || print_log enforcer.log 'Run maven-enforcer-plugin'
225-
[ "$TEST_STATUS" = 'skip' ] || print_log test.log 'Run unit tests'
226-
[ "$CODENARC_STATUS" = 'skip' ] || print_log codenarc.log 'Run CodeNarc'
227-
[ "$FINDBUGS_STATUS" = 'skip' ] || print_log findbugs.log 'Run FindBugs'
233+
[ "$CS_STATUS" = 'skip' ] || print_log cs.log 'Run CheckStyle'
234+
[ "$PMD_STATUS" = 'skip' ] || print_log pmd.log 'Run PMD'
235+
[ "$LICENSE_STATUS" = 'skip' ] || print_log license.log 'Check license headers'
236+
[ "$POM_STATUS" = 'skip' ] || print_log pom.log 'Check sorting of pom.xml'
237+
[ "$BOOTLINT_STATUS" = 'skip' ] || print_log bootlint.log 'Run bootlint'
238+
[ "$RFLINT_STATUS" = 'skip' ] || print_log rflint.log 'Run robot framework lint'
239+
[ "$SHELLCHECK_STATUS" = 'skip' ] || print_log shellcheck.log 'Run shellcheck'
240+
[ "$JASMINE_STATUS" = 'skip' ] || print_log jasmine.log 'Run JavaScript unit tests'
241+
[ "$HTML_STATUS" = 'skip' ] || print_log validator.log 'Run html5validator'
242+
[ "$ENFORCER_STATUS" = 'skip' ] || print_log enforcer.log 'Run maven-enforcer-plugin'
243+
[ "$TEST_STATUS" = 'skip' ] || print_log test.log 'Run unit tests'
244+
[ "$CODENARC_STATUS" = 'skip' ] || print_log codenarc.log 'Run CodeNarc'
245+
[ "$FINDBUGS_STATUS" = 'skip' ] || print_log findbugs.log 'Run FindBugs'
228246
fi
229247

230248
print_log verify.log 'Run integration tests'
@@ -233,8 +251,8 @@ if [ "$DANGER_STATUS" != 'skip' ]; then
233251
print_log danger.log 'Run danger'
234252
fi
235253

236-
rm -f cs.log pmd.log license.log pom.log bootlint.log rflint.log jasmine.log validator.log enforcer.log test.log codenarc.log findbugs.log verify-raw.log verify.log danger.log
254+
rm -f cs.log pmd.log license.log pom.log bootlint.log rflint.log shellcheck.log jasmine.log validator.log enforcer.log test.log codenarc.log findbugs.log verify-raw.log verify.log danger.log
237255

238-
if echo "$CS_STATUS$PMD_STATUS$LICENSE_STATUS$POM_STATUS$BOOTLINT_STATUS$RFLINT_STATUS$JASMINE_STATUS$HTML_STATUS$ENFORCER_STATUS$TEST_STATUS$CODENARC_STATUS$FINDBUGS_STATUS$VERIFY_STATUS$DANGER_STATUS" | fgrep -qs 'fail'; then
256+
if echo "$CS_STATUS$PMD_STATUS$LICENSE_STATUS$POM_STATUS$BOOTLINT_STATUS$RFLINT_STATUS$SHELLCHECK_STATUS$JASMINE_STATUS$HTML_STATUS$ENFORCER_STATUS$TEST_STATUS$CODENARC_STATUS$FINDBUGS_STATUS$VERIFY_STATUS$DANGER_STATUS" | grep -Fqs 'fail'; then
239257
exit 1
240258
fi

src/main/scripts/ci/common.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ print_log() {
2525
echo
2626
printf "=====> \033[1;33m%s\033[0m\n" "$msg"
2727
echo
28-
egrep -v '^\[INFO\] Download(ing|ed):' "$log_file" || :
28+
grep -Ev '^\[INFO\] Download(ing|ed):' "$log_file" || :
2929
}

src/main/scripts/ci/deploy.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,13 @@ trap 'cleanup' EXIT SIGHUP SIGINT SIGTERM
2525
# See: http://docs.ansible.com/ansible/intro_getting_started.html#host-key-checking
2626
export ANSIBLE_HOST_KEY_CHECKING=False
2727

28+
if [ -z "${encrypted_bf07cb25089f_key:-}" ] || [ -z "${encrypted_bf07cb25089f_iv:-}" ] ; then
29+
echo >&2 'ERROR: encrypted_bf07cb25089f_key or encrypted_bf07cb25089f_iv were not defined!'
30+
exit 1
31+
fi
32+
2833
# Decrypt private key
29-
openssl aes-256-cbc -K $encrypted_bf07cb25089f_key -iv $encrypted_bf07cb25089f_iv -in "$PRIVATE_KEY.enc" -out "$PRIVATE_KEY" -d
34+
openssl aes-256-cbc -K "$encrypted_bf07cb25089f_key" -iv "$encrypted_bf07cb25089f_iv" -in "$PRIVATE_KEY.enc" -out "$PRIVATE_KEY" -d
3035
chmod 600 "$PRIVATE_KEY"
3136

3237
ansible-playbook --inventory-file="$INVENTORY" "$PLAYBOOK" --syntax-check

src/main/scripts/ci/publish-code-coverage.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ set -o errexit
1010
set -o pipefail
1111

1212

13+
# shellcheck source=src/main/scripts/ci/common.sh
1314
. "$(dirname "$0")/common.sh"
1415

1516
JACOCO_FAIL=

0 commit comments

Comments
 (0)