Skip to content

Commit 3d4a0cb

Browse files
committed
ci: add shellcheck gh action; fix fatal shellcheck errors
This commit made with the assistance of github copilot Signed-off-by: Morgan Rockett <[email protected]>
1 parent f6e5401 commit 3d4a0cb

8 files changed

+91
-20
lines changed

.github/workflows/ci.yml

+19-7
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- uses: actions/checkout@v4
2626
with:
2727
submodules: recursive
28-
- name: Setup Build Env
28+
- name: Install Build Tools
2929
run: sudo ./scripts/install-build-tools.sh
3030
- name: Setup Local Dependencies
3131
run: ./scripts/setup-dependencies.sh
@@ -38,7 +38,7 @@ jobs:
3838
- uses: actions/checkout@v4
3939
with:
4040
submodules: recursive
41-
- name: Setup Build Env
41+
- name: Install Build Tools
4242
run: sudo ./scripts/install-build-tools.sh
4343
- name: Setup Local Dependencies
4444
run: ./scripts/setup-dependencies.sh
@@ -50,7 +50,7 @@ jobs:
5050
name: Pylint
5151
runs-on: ubuntu-22.04
5252
continue-on-error: true
53-
timeout-minutes: 10
53+
timeout-minutes: 5
5454
strategy:
5555
matrix:
5656
python-version: ["3.10"]
@@ -62,10 +62,23 @@ jobs:
6262
uses: actions/setup-python@v5
6363
with:
6464
python-version: ${{ matrix.python-version }}
65-
- name: Setup Build Env
65+
- name: Install Build Tools
6666
run: sudo ./scripts/install-build-tools.sh
6767
- name: Lint with Pylint
6868
run: ./scripts/pylint.sh
69+
shellcheck:
70+
name: Shellcheck
71+
runs-on: ubuntu-22.04
72+
continue-on-error: true
73+
timeout-minutes: 5
74+
steps:
75+
- uses: actions/checkout@v4
76+
with:
77+
submodules: recursive
78+
- name: Install Build Tools
79+
run: sudo ./scripts/install-build-tools.sh
80+
- name: Lint with Shellcheck
81+
run: ./scripts/shellcheck.sh view
6982
unit-and-integration-test:
7083
name: Unit and Integration Tests
7184
runs-on: ubuntu-22.04
@@ -74,7 +87,7 @@ jobs:
7487
- uses: actions/checkout@v4
7588
with:
7689
submodules: recursive
77-
- name: Setup Build Env
90+
- name: Install Build Tools
7891
run: sudo ./scripts/install-build-tools.sh
7992
- name: Setup Local Dependencies
8093
run: ./scripts/setup-dependencies.sh
@@ -84,7 +97,7 @@ jobs:
8497
run: ./scripts/test.sh
8598
- name: Shorten SHA
8699
id: vars
87-
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
100+
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
88101
- uses: actions/upload-artifact@v4
89102
if: ${{ !env.ACT }}
90103
name: Archive Test Results
@@ -114,4 +127,3 @@ jobs:
114127
name: OpenCBDC Transaction Processor docs for ${{ steps.vars.outputs.sha_short }}
115128
path: ./doxygen_generated/html/*
116129
retention-days: 7
117-

scripts/create-e2e-report.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function readAndFormatLogs() {
1111
return
1212
fi
1313

14-
for logfile in $(ls $logdir); do
14+
for logfile in "$logdir"/*; do
1515
logfile_path="$logdir/$logfile"
1616
logfile_content=$(cat $logfile_path)
1717
message+="\n<details>\n<summary>$logfile</summary>\n\n\`\`\`\n$logfile_content\n\`\`\`\n</details>\n"

scripts/install-build-tools.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fi
1717

1818
# Supporting these versions for buildflow
1919
PYTHON_VERSIONS=("3.10" "3.11" "3.12")
20-
echo "Python3 versions supported: ${PYTHON_VERSIONS[@]}"
20+
echo "Python3 versions supported: ${PYTHON_VERSIONS[*]}"
2121

2222
# check if supported version of python3 is already installed, and save the version
2323
PY_INSTALLED=''

scripts/lint.sh

+6-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ if [ -n "$whitespace_files" ] || [ -n "$newline_files" ] ; then
2525
exit 1
2626
fi
2727

28-
check_format_files=$(git ls-files | grep -E "tools|tests|src|cmake-tests" \
29-
| grep -E "\..*pp")
30-
clang-format --style=file --Werror --dry-run ${check_format_files[@]}
28+
check_format_files=$(git ls-files | \
29+
grep -E "tools|tests|src|cmake-tests" | \
30+
grep -E "\..*pp")
31+
32+
echo "${check_format_files}" | \
33+
xargs -n1 -I{} clang-format --style=file --Werror --dry-run {}
3134

3235
if ! command -v clang-tidy &>/dev/null; then
3336
echo "clang-tidy does not appear to be installed"

scripts/native-system-benchmark.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ on_int() {
151151
printf 'Interrupting all components\n'
152152
trap '' SIGINT # avoid interrupting ourself
153153
for i in $PIDS; do # intentionally unquoted
154-
if [[ -n "RECORD" ]]; then
154+
if [[ -n "$RECORD" ]]; then
155155
kill -SIGINT -- "-$i"
156156
else
157157
kill -SIGINT -- "$i"
@@ -194,7 +194,7 @@ on_int() {
194194

195195
printf 'Terminating any remaining processes\n'
196196
for i in $PIDS; do # intentionally unquoted
197-
if [[ -n "RECORD" ]]; then
197+
if [[ -n "$RECORD" ]]; then
198198
kill -SIGTERM -- "-$i"
199199
else
200200
kill -SIGTERM -- "$i"
@@ -253,15 +253,15 @@ run() {
253253
COMP=
254254
case "$RECORD" in
255255
perf)
256-
$@ &> "$PROC_LOG" &
256+
"$@" &> "$PROC_LOG" &
257257
COMP="$!"
258258
perf record -F 99 -a -g -o "$PNAME".perf -p "$COMP" &> "$PERF_LOG" &
259259
PERFS="$PERFS $!";;
260260
debug)
261261
${DBG} "$@" &> "$PROC_LOG" &
262262
COMP="$!";;
263263
*)
264-
$@ &> "$PROC_LOG" &
264+
"$@" &> "$PROC_LOG" &
265265
COMP="$!";;
266266
esac
267267

@@ -324,7 +324,7 @@ launch() {
324324
"$RT"/scripts/wait-for-it.sh -q -t 5 -h localhost -p "$ep"
325325
done
326326
printf 'Launched logical %s %d, replica %d [PID: %d]\n' "$1" "$id" "$node" "$PID"
327-
if [[ -n "RECORD" ]]; then
327+
if [[ -n "$RECORD" ]]; then
328328
PIDS="$PIDS $(getpgid $PID)"
329329
else
330330
PIDS="$PIDS $PID"
@@ -337,7 +337,7 @@ launch() {
337337
"$RT"/scripts/wait-for-it.sh -q -t 5 -h localhost -p "$ep"
338338
done
339339
printf 'Launched %s %d [PID: %d]\n' "$1" "$id" "$PID"
340-
if [[ -n "RECORD" ]]; then
340+
if [[ -n "$RECORD" ]]; then
341341
PIDS="$PIDS $(getpgid $PID)"
342342
else
343343
PIDS="$PIDS $PID"

scripts/shellcheck.sh

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env bash
2+
3+
# Usage: ./scripts/shellcheck.sh
4+
ROOT="$(cd "$(dirname "$0")"/.. && pwd)"
5+
SHELLCHECK_REPORT="${ROOT}/shellcheck-report.txt"
6+
7+
NUM_CORES=1
8+
if [[ "${OSTYPE}" == "linux-gnu"* ]]; then
9+
NUM_CORES=$(grep -c ^processor /proc/cpuinfo)
10+
elif [[ "${OSTYPE}" == "darwin"* ]]; then
11+
NUM_CORES=$(sysctl -n hw.ncpu)
12+
fi
13+
14+
if ! command -v shellcheck &>/dev/null; then
15+
echo "shellcheck is not installed."
16+
echo "Run 'sudo ./scripts/install-build-tools.sh' to install shellcheck."
17+
exit 1
18+
fi
19+
20+
# run shellcheck in parallel on all tracked shell scripts
21+
# checking status of this run will give failure if even a warning is found by default
22+
# info/warnings/errors are treated as unsuccessful, so we need to search the report for
23+
# explicit errors messages to determine if there are any true errors
24+
git ls-files '*.sh' | xargs -n 1 -P "${NUM_CORES}" shellcheck > "${SHELLCHECK_REPORT}"
25+
26+
# if shell check report exists to determine if shellcheck run was successful
27+
if [[ -z "${SHELLCHECK_REPORT}" ]]; then
28+
echo "Shellcheck report ${SHELLCHECK_REPORT} not found. Exiting..."
29+
exit 1
30+
else
31+
echo "Shellcheck report: ${SHELLCHECK_REPORT}"
32+
if [[ ! -s "${SHELLCHECK_REPORT}" ]]; then
33+
echo "Shellcheck report is empty."
34+
echo "Either there are no info/warning/error messages across all shell scripts,"
35+
echo "or shellcheck failed to run successfully."
36+
exit 0
37+
fi
38+
fi
39+
40+
# view non-empty shellcheck report, includes info, warnings, errors
41+
if [[ "$#" -eq 1 && "$1" == "view" ]]; then
42+
echo "Shellcheck report: ${SHELLCHECK_REPORT}"
43+
cat "${SHELLCHECK_REPORT}"
44+
fi
45+
46+
# detect if fatal errors are in shellcheck report
47+
echo "Checking for fatal errors in shellcheck report..."
48+
if ! grep "(error):" "${SHELLCHECK_REPORT}"; then
49+
echo "Shellcheck found no fatal errors in report: ${SHELLCHECK_REPORT}"
50+
echo "Shellcheck passed."
51+
exit 0
52+
else
53+
echo "Shellcheck found fatal errors in report: ${SHELLCHECK_REPORT}"
54+
echo "Shellcheck failed."
55+
exit 1
56+
fi

scripts/test-e2e-minikube.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ BUILD_DOCKER=${TESTRUN_BUILD_DOCKER:-1}
77

88
# Make sure we have the necessary tools installed
99
required_executables=(minikube docker go helm kubectl)
10-
for e in ${required_executables[@]}; do
10+
for e in "${required_executables[@]}"; do
1111
if ! command -v $e &> /dev/null; then
1212
echo "'$e' command not be found! This is required to run. Please install it."
1313
exit 1

scripts/wait-for-it.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ if [[ $WAITFORIT_TIMEOUT_PATH =~ "busybox" ]]; then
150150
WAITFORIT_ISBUSY=1
151151
# Check if busybox timeout uses -t flag
152152
# (recent Alpine versions don't support -t anymore)
153-
if timeout &>/dev/stdout | grep -q -e '-t '; then
153+
if timeout |& tee /dev/stdout | grep -q -e '-t '; then
154154
WAITFORIT_BUSYTIMEFLAG="-t"
155155
fi
156156
else

0 commit comments

Comments
 (0)