Skip to content

Commit 2f83bdb

Browse files
committed
ci: add shellcheck gh action and script, lint fixes
This commit made with the assistance of github copilot Signed-off-by: Morgan Rockett <[email protected]>
1 parent f6e5401 commit 2f83bdb

17 files changed

+404
-150
lines changed

.github/workflows/ci.yml

+21-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,25 @@ 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 shellcheck
79+
run: |
80+
sudo apt-get update
81+
sudo apt-get install -y shellcheck
82+
- name: Lint with Shellcheck
83+
run: ./scripts/shellcheck.sh
6984
unit-and-integration-test:
7085
name: Unit and Integration Tests
7186
runs-on: ubuntu-22.04
@@ -74,7 +89,7 @@ jobs:
7489
- uses: actions/checkout@v4
7590
with:
7691
submodules: recursive
77-
- name: Setup Build Env
92+
- name: Install Build Tools
7893
run: sudo ./scripts/install-build-tools.sh
7994
- name: Setup Local Dependencies
8095
run: ./scripts/setup-dependencies.sh
@@ -84,7 +99,7 @@ jobs:
8499
run: ./scripts/test.sh
85100
- name: Shorten SHA
86101
id: vars
87-
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
102+
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
88103
- uses: actions/upload-artifact@v4
89104
if: ${{ !env.ACT }}
90105
name: Archive Test Results
@@ -114,4 +129,3 @@ jobs:
114129
name: OpenCBDC Transaction Processor docs for ${{ steps.vars.outputs.sha_short }}
115130
path: ./doxygen_generated/html/*
116131
retention-days: 7
117-

scripts/benchmarks.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ done
6464
# to the location of this script, the user can run this script from any folder.
6565
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
6666
REPO_TOP_DIR="${SCRIPT_DIR}/.."
67+
BUILD_DIR=
6768
if [[ -z "${BUILD_DIR+x}" ]]
6869
then
6970
BUILD_DIR="${REPO_TOP_DIR}/build"
@@ -78,7 +79,8 @@ fi
7879
# If the build folder is a relative path, convert it to an absolute path
7980
# to avoid potential relative path errors and to improve readability
8081
# if the path is written to stdout.
81-
export BUILD_DIR=$(cd "$BUILD_DIR"; pwd)
82+
BUILD_DIR=$(cd "$BUILD_DIR"; pwd)
83+
export BUILD_DIR
8284
echo "Build folder: '${BUILD_DIR}'"
8385
echo
8486

scripts/build-docker.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ DOCKER_IMAGE_TAG_TWOPHASE=${DOCKER_IMAGE_TAG:-opencbdc-tx-twophase}
1212
git submodule init && git submodule update
1313

1414
# Build docker image
15-
docker build --target base -t $DOCKER_IMAGE_TAG_BASE -f $SCRIPT_DIR/../Dockerfile $SCRIPT_DIR/..
16-
docker build --target builder --build-arg BASE_IMAGE=base -t $DOCKER_IMAGE_TAG_BUILDER -f $SCRIPT_DIR/../Dockerfile $SCRIPT_DIR/..
17-
docker build --target twophase --build-arg BASE_IMAGE=base -t $DOCKER_IMAGE_TAG_TWOPHASE -f $SCRIPT_DIR/../Dockerfile $SCRIPT_DIR/..
18-
docker build --target atomizer --build-arg BASE_IMAGE=base -t $DOCKER_IMAGE_TAG_ATOMIZER -f $SCRIPT_DIR/../Dockerfile $SCRIPT_DIR/..
15+
docker build --target base -t "$DOCKER_IMAGE_TAG_BASE" -f "$SCRIPT_DIR"/../Dockerfile "$SCRIPT_DIR"/..
16+
docker build --target builder --build-arg BASE_IMAGE=base -t "$DOCKER_IMAGE_TAG_BUILDER" -f "$SCRIPT_DIR"/../Dockerfile "$SCRIPT_DIR"/..
17+
docker build --target twophase --build-arg BASE_IMAGE=base -t "$DOCKER_IMAGE_TAG_TWOPHASE" -f "$SCRIPT_DIR"/../Dockerfile "$SCRIPT_DIR"/..
18+
docker build --target atomizer --build-arg BASE_IMAGE=base -t "$DOCKER_IMAGE_TAG_ATOMIZER" -f "$SCRIPT_DIR"/../Dockerfile "$SCRIPT_DIR"/..

scripts/build.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if [ $# -gt 0 ]; then
2727
Profiling|--profiling|-p) CMAKE_BUILD_TYPE="Profiling";;
2828
Debug|--debug|-d) CMAKE_BUILD_TYPE="Debug";;
2929
--help|-h) help;;
30-
*) help $1;;
30+
*) help "$1";;
3131
esac
3232
fi
3333

@@ -37,11 +37,12 @@ echo "Building..."
3737
PREFIX="$(cd "$(dirname "$0")"/.. && pwd)/prefix"
3838

3939
if [ -z ${BUILD_DIR+x} ]; then
40-
export BUILD_DIR=build
40+
BUILD_DIR=build
41+
export BUILD_DIR
4142
fi
4243

43-
mkdir -p $BUILD_DIR
44-
cd $BUILD_DIR
44+
mkdir -p "$BUILD_DIR"
45+
cd "$BUILD_DIR"
4546

4647
CMAKE_FLAGS=-DCMAKE_PREFIX_PATH="${PREFIX}"
4748
CPUS=1
@@ -60,5 +61,4 @@ fi
6061

6162
echo "Building $CMAKE_BUILD_TYPE"
6263
eval "cmake -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} ${CMAKE_FLAGS} .."
63-
make -j$CPUS
64-
64+
make -j"$CPUS"

scripts/create-e2e-report.sh

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
set -e
3-
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
3+
44
TESTRUN_PATH=$1
55

66
function readAndFormatLogs() {
@@ -11,15 +11,15 @@ 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"
16-
logfile_content=$(cat $logfile_path)
16+
logfile_content=$(<"$logfile_path")
1717
message+="\n<details>\n<summary>$logfile</summary>\n\n\`\`\`\n$logfile_content\n\`\`\`\n</details>\n"
1818
done
1919
echo "$message"
2020
}
2121

22-
testrun_logs="\n<details>\n<summary>View Testrun</summary>\n\n\`\`\`\n$(cat $TESTRUN_PATH/testrun.log)\n\`\`\`\n</details>\n\n"
23-
container_logs=$(readAndFormatLogs $TESTRUN_PATH/logs)
22+
testrun_logs="\n<details>\n<summary>View Testrun</summary>\n\n\`\`\`\n$(cat "$TESTRUN_PATH"/testrun.log)\n\`\`\`\n</details>\n\n"
23+
container_logs=$(readAndFormatLogs "$TESTRUN_PATH"/logs)
2424

2525
printf "# E2E Results\n# TestRun Logs\n%b\n\n# Container Logs\n%b\n" "$testrun_logs" "$container_logs"

scripts/install-build-tools.sh

+11-11
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=''
@@ -60,7 +60,7 @@ create_venv_install_python() {
6060
if ! $SUDO apt install -y python3-pip; then
6161
echo "Failed to install python3-pip"
6262
wget https://bootstrap.pypa.io/get-pip.py
63-
$SUDO python${PY_VERSION} get-pip.py
63+
$SUDO python"$PY_VERSION" get-pip.py
6464
rm get-pip.py
6565
fi
6666
# add deadsnakes to download the python venv module
@@ -112,7 +112,6 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
112112
exit 1
113113
fi
114114

115-
CPUS=$(sysctl -n hw.ncpu)
116115
# ensure development environment is set correctly for clang
117116
$SUDO xcode-select -switch /Library/Developer/CommandLineTools
118117

@@ -121,7 +120,8 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
121120
exit 1
122121
fi
123122

124-
brew install llvm@14 googletest google-benchmark lcov make wget cmake bash bc
123+
CPUS=$(sysctl -n hw.ncpu)
124+
echo llvm@14 googletest google-benchmark lcov make wget cmake bash bc | xargs -n 1 -P "$CPUS" brew install
125125
brew upgrade bash
126126

127127
BREW_ROOT=$(brew --prefix)
@@ -132,7 +132,7 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
132132
fi
133133
GMAKE=/usr/local/bin/gmake
134134
if [[ ! -L "$GMAKE" ]]; then
135-
$SUDO ln -s $(xcode-select -p)/usr/bin/gnumake /usr/local/bin/gmake
135+
$SUDO ln -s "$(xcode-select -p)"/usr/bin/gnumake /usr/local/bin/gmake
136136
fi
137137

138138
# install valid python version if not installed yet
@@ -172,8 +172,8 @@ elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
172172

173173
$SUDO apt update -y
174174
$SUDO apt install -y clang-format-14 clang-tidy-14
175-
$SUDO ln -sf $(which clang-format-14) /usr/local/bin/clang-format
176-
$SUDO ln -sf $(which clang-tidy-14) /usr/local/bin/clang-tidy
175+
$SUDO ln -sf "$(which clang-format-14)" /usr/local/bin/clang-format
176+
$SUDO ln -sf "$(which clang-tidy-14)" /usr/local/bin/clang-tidy
177177

178178
# install valid python version if not installed yet
179179
if [[ -z "$PY_INSTALLED" ]]; then
@@ -194,9 +194,9 @@ elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
194194
MAX_RETRIES=2
195195
while [[ $MAX_RETRIES -gt 0 ]]; do
196196
# install python3 valid version and venv module
197-
if $SUDO apt install -y ${FULL_PY}; then
197+
if $SUDO apt install -y "$FULL_PY"; then
198198
echo "${FULL_PY} installed successfully"
199-
PY_INSTALLED=${PY_VERS}
199+
PY_INSTALLED="$PY_VERS"
200200
break
201201
fi
202202
MAX_RETRIES=$((MAX_RETRIES - 1))
@@ -215,8 +215,8 @@ if ! which "python${PY_INSTALLED}" &> /dev/null; then
215215
exit 1
216216
else
217217
# create virtual environment and install python packages for the valid python version
218-
PYTHON_PATH=$(which "python${PY_INSTALLED}")
219-
create_venv_install_python "${PYTHON_PATH}" ${PY_INSTALLED}
218+
PYTHON_PATH=$(which python"$PY_INSTALLED")
219+
create_venv_install_python "$PYTHON_PATH" "$PY_INSTALLED"
220220
fi
221221
echo "To activate the virtual env to run python, run 'source ./scripts/activate-venv.sh'"
222222

scripts/lint.sh

+8-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ if [ -n "$whitespace_files" ]; then
1414
printf '%s\n' "${whitespace_files[@]}"
1515
fi
1616

17+
# shellcheck disable=SC2016
1718
newline_files=$(printf '%s' "${check_files[@]}" | xargs -r -I {} bash -c 'test "$(tail -c 1 "{}" | wc -l)" -eq 0 && echo {}' | cat)
1819

1920
if [ -n "$newline_files" ] ; then
@@ -25,9 +26,12 @@ if [ -n "$whitespace_files" ] || [ -n "$newline_files" ] ; then
2526
exit 1
2627
fi
2728

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

3236
if ! command -v clang-tidy &>/dev/null; then
3337
echo "clang-tidy does not appear to be installed"
@@ -46,6 +50,6 @@ fi
4650

4751
# use python from the virtual environment for clang-tidy
4852
if source "./scripts/activate-venv.sh"; then
49-
python /usr/local/bin/run-clang-tidy.py -p ${BUILD_DIR} "tests/.*/.*\.cpp|src/.*/.*\.cpp|tools/.*/.*\.cpp"
53+
python /usr/local/bin/run-clang-tidy.py -p "$BUILD_DIR" "tests/.*/.*\.cpp|src/.*/.*\.cpp|tools/.*/.*\.cpp"
5054
deactivate
5155
fi

scripts/lua_bench.sh

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ for arg in "$@"; do
2929
fi
3030
done
3131
./build/tools/bench/parsec/lua/lua_bench --component_id=0 \
32-
--ticket_machine0_endpoint=$IP:7777 --ticket_machine_count=1 \
33-
--shard_count=1 --shard0_count=1 --shard00_endpoint=$IP:5556 \
34-
--agent_count=1 --agent0_endpoint=$IP:$PORT \
35-
--loglevel=$LOGLEVEL scripts/gen_bytecode.lua $N_WALLETS
36-
echo done
32+
--ticket_machine0_endpoint="$IP":7777 --ticket_machine_count=1 \
33+
--shard_count=1 --shard0_count=1 --shard00_endpoint="$IP":5556 \
34+
--agent_count=1 --agent0_endpoint="$IP":"$PORT" \
35+
--loglevel="$LOGLEVEL" scripts/gen_bytecode.lua $N_WALLETS
36+
echo "done"; echo

scripts/native-system-benchmark.sh

+15-12
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ case "$DURATION" in
107107
esac
108108

109109
if [[ -n "$_help" ]]; then
110-
printf "$usage" "$(basename $0)"
110+
# shellcheck disable=SC2059
111+
printf "$usage" "$(basename "$0")"
111112
exit "$_err"
112113
fi
113114

@@ -151,7 +152,7 @@ on_int() {
151152
printf 'Interrupting all components\n'
152153
trap '' SIGINT # avoid interrupting ourself
153154
for i in $PIDS; do # intentionally unquoted
154-
if [[ -n "RECORD" ]]; then
155+
if [[ -n "$RECORD" ]]; then
155156
kill -SIGINT -- "-$i"
156157
else
157158
kill -SIGINT -- "$i"
@@ -178,7 +179,7 @@ on_int() {
178179
if [[ -x "$(which flamegraph.pl)" && -x "$(which stackcollapse-perf.pl)" && -n "$(find "$TESTDIR" -maxdepth 1 -name '*.perf' -print -quit)" ]]; then
179180
printf 'Generating Flamegraphs\n'
180181
for i in "$TESTDIR"/*.perf; do
181-
waitpid -t 5 -e $(lsof -Qt "$i") &>/dev/null
182+
waitpid -t 5 -e "$(lsof -Qt "$i")" &>/dev/null
182183
perf script -i "$i" | stackcollapse-perf.pl > "${i/.perf/.folded}"
183184
flamegraph.pl "${i/.perf/.folded}" > "${i/.perf/.svg}"
184185
rm -- "${i/.perf/.folded}"
@@ -194,7 +195,7 @@ on_int() {
194195

195196
printf 'Terminating any remaining processes\n'
196197
for i in $PIDS; do # intentionally unquoted
197-
if [[ -n "RECORD" ]]; then
198+
if [[ -n "$RECORD" ]]; then
198199
kill -SIGTERM -- "-$i"
199200
else
200201
kill -SIGTERM -- "$i"
@@ -253,15 +254,15 @@ run() {
253254
COMP=
254255
case "$RECORD" in
255256
perf)
256-
$@ &> "$PROC_LOG" &
257+
"$@" &> "$PROC_LOG" &
257258
COMP="$!"
258259
perf record -F 99 -a -g -o "$PNAME".perf -p "$COMP" &> "$PERF_LOG" &
259260
PERFS="$PERFS $!";;
260261
debug)
261262
${DBG} "$@" &> "$PROC_LOG" &
262263
COMP="$!";;
263264
*)
264-
$@ &> "$PROC_LOG" &
265+
"$@" &> "$PROC_LOG" &
265266
COMP="$!";;
266267
esac
267268

@@ -287,9 +288,9 @@ seed() {
287288
if test ! -e "$SEEDDIR"/"$preseed_id"; then
288289
printf 'Creating %s\n' "$preseed_id"
289290
mkdir -p -- "$SEEDDIR"/"$preseed_id"
290-
pushd "$SEEDDIR"/"$preseed_id" &> /dev/null
291+
pushd "$SEEDDIR"/"$preseed_id" &> /dev/null || exit
291292
PID=$(PNAME=seeder BLOCK=1 run "$(getpath seeder)" "$CFG")
292-
popd &> /dev/null
293+
popd &> /dev/null || exit
293294
fi
294295

295296
printf 'Using %s as seed\n' "$preseed_id"
@@ -320,25 +321,27 @@ launch() {
320321
for node in $(seq 0 $(( "$raft" - 1 )) ); do
321322
export PNAME="$1${id}_$node"
322323
PID=$(run "$(getpath "$1")" "$CFG" "$id" "$node")
324+
# shellcheck disable=SC2013
323325
for ep in $(awk -F'[":]' "/$PNAME.*endpoint/ { print \$3 }" "$CFG"); do
324326
"$RT"/scripts/wait-for-it.sh -q -t 5 -h localhost -p "$ep"
325327
done
326328
printf 'Launched logical %s %d, replica %d [PID: %d]\n' "$1" "$id" "$node" "$PID"
327-
if [[ -n "RECORD" ]]; then
328-
PIDS="$PIDS $(getpgid $PID)"
329+
if [[ -n "$RECORD" ]]; then
330+
PIDS="$PIDS $(getpgid "$PID")"
329331
else
330332
PIDS="$PIDS $PID"
331333
fi
332334
done
333335
else
334336
export PNAME="$1${id}"
335337
PID=$(run "$(getpath "$1")" "$CFG" "$id")
338+
# shellcheck disable=SC2013
336339
for ep in $(awk -F'[":]' "/$PNAME.*endpoint/ { print \$3 }" "$CFG"); do
337340
"$RT"/scripts/wait-for-it.sh -q -t 5 -h localhost -p "$ep"
338341
done
339342
printf 'Launched %s %d [PID: %d]\n' "$1" "$id" "$PID"
340-
if [[ -n "RECORD" ]]; then
341-
PIDS="$PIDS $(getpgid $PID)"
343+
if [[ -n "$RECORD" ]]; then
344+
PIDS="$PIDS $(getpgid "$PID")"
342345
else
343346
PIDS="$PIDS $PID"
344347
fi

0 commit comments

Comments
 (0)