-
Notifications
You must be signed in to change notification settings - Fork 174
Expand file tree
/
Copy pathshellcheck.sh
More file actions
executable file
·76 lines (60 loc) · 2.03 KB
/
shellcheck.sh
File metadata and controls
executable file
·76 lines (60 loc) · 2.03 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
75
76
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd)"
# shellcheck source=../../scripts/lib.sh
source "$ROOT/scripts/lib.sh"
if [[ "${CI:-}" == "true" ]]; then
# shellcheck source=../../scripts/ci/lib.sh
source "$ROOT/scripts/ci/lib.sh"
fi
known_failures_file="scripts/style/shellcheck_skip.txt"
retrieve_shell_scripts() {
git ls-files | grep -E '.(sh|bats)$'
}
run_shellcheck() {
info "Running shellcheck on all .sh files (excluding ${known_failures_file})"
pushd "$ROOT" > /dev/null
local output="shellcheck-reports"
local flag_failure="scripts/style/shellcheck_fail_flag"
rm -f "${output}/*" "${flag_failure}"
for shell in $(retrieve_shell_scripts | grep -v -x -f "${known_failures_file}"); do
if ! shellcheck --norc -P SCRIPTDIR -x "$shell"; then
if [[ "${CI:-}" == "true" ]]; then
mkdir -p "${output}"
local xmlout="${shell//.sh/.xml}"
xmlout="${xmlout//\//_}"
shellcheck -f checkstyle --norc -P SCRIPTDIR -x "$shell" | xmlstarlet tr scripts/style/checkstyle2junit.xslt > \
"${output}/${xmlout}" || true
fi
touch "${flag_failure}"
fi
done
popd > /dev/null
if [[ -e "${flag_failure}" ]]; then
rm -f "${flag_failure}"
if [[ "${CI:-}" == "true" ]]; then
store_test_results "${output}" "${output}"
fi
info "errors were detected"
exit 1
fi
}
update_failing_list() {
info "Will discover shell scripts that fail shellcheck and update ${known_failures_file}"
pushd "$ROOT" > /dev/null
for shell in $(retrieve_shell_scripts); do
if ! shellcheck --norc -P SCRIPTDIR -x "$shell" > /dev/null; then
echo "$shell" >> "$known_failures_file"
fi
done
popd > /dev/null
}
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
if [[ "$#" -lt 1 ]]; then
run_shellcheck "$@"
else
fn="$1"
shift
"$fn" "$@"
fi
fi