Skip to content

Commit 62d116b

Browse files
committed
ci: add shellcheck gh action, lint fixes, parallel acts
This commit made with the assistance of github copilot Signed-off-by: Morgan Rockett <[email protected]>
1 parent 4c91a6d commit 62d116b

18 files changed

+648
-570
lines changed

.github/workflows/ci.yml

+31-3
Original file line numberDiff line numberDiff line change
@@ -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"]
@@ -66,6 +66,35 @@ jobs:
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: |
84+
git ls-files '*.sh' |
85+
xargs -n 1 -P $(nproc) shellcheck > shellcheck-report.txt || true
86+
- name: Show Shellcheck report
87+
run: |
88+
echo "Shellcheck report: shellcheck-report.txt"
89+
cat shellcheck-report.txt
90+
- name: Detect Shellcheck errors
91+
run: |
92+
if grep -qE "error" shellcheck-report.txt; then
93+
echo "Shellcheck found errors in report: shellcheck-report.txt"
94+
exit 1
95+
else
96+
echo "Shellcheck found no fatal errors in report: shellcheck-report.txt"
97+
fi
6998
unit-and-integration-test:
7099
name: Unit and Integration Tests
71100
runs-on: ubuntu-22.04
@@ -84,7 +113,7 @@ jobs:
84113
run: ./scripts/test.sh
85114
- name: Shorten SHA
86115
id: vars
87-
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
116+
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
88117
- uses: actions/upload-artifact@v4
89118
if: ${{ !env.ACT }}
90119
name: Archive Test Results
@@ -114,4 +143,3 @@ jobs:
114143
name: OpenCBDC Transaction Processor docs for ${{ steps.vars.outputs.sha_short }}
115144
path: ./doxygen_generated/html/*
116145
retention-days: 7
117-

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ CMakeFiles/
5050
plots/
5151
.deps/
5252
.libs/
53+
.cache/
5354

5455
# Database
5556
blocks.dat

benchmarks/transactions.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,21 @@ void reset_wallets(cbdc::transaction::wallet& w1,
4141
/// @brief Time an N-in, 1-out transaction.
4242
/// @brief Note: handles benchmark timing, do not time outside function.
4343
/// @param sender
44-
/// @param reciever
44+
/// @param receiver
4545
/// @param n_in
4646
/// @param state
4747
/// @return
4848
inline bool generate_Nto1_tx(cbdc::transaction::wallet& sender,
49-
cbdc::transaction::wallet& reciever,
49+
cbdc::transaction::wallet& receiver,
5050
uint32_t n_in,
5151
benchmark::State& state) {
5252
std::optional<cbdc::transaction::full_tx> maybe_tx{};
5353
state.ResumeTiming();
54-
maybe_tx = sender.send_to(n_in * 2, reciever.generate_key(), true).value();
54+
maybe_tx = sender.send_to(n_in * 2, receiver.generate_key(), true).value();
5555
state.PauseTiming();
5656
if(maybe_tx.has_value()) {
5757
sender.confirm_transaction(*maybe_tx);
58-
reciever.confirm_transaction(*maybe_tx);
58+
receiver.confirm_transaction(*maybe_tx);
5959
return true;
6060
}
6161
return false;
@@ -64,22 +64,22 @@ inline bool generate_Nto1_tx(cbdc::transaction::wallet& sender,
6464
/// @brief Time an N-in, 2-out transaction.
6565
/// @brief Note: handles benchmark timing, do not time outside function.
6666
/// @param sender
67-
/// @param reciever
67+
/// @param receiver
6868
/// @param n_in
6969
/// @param state
7070
/// @return
7171
inline bool generate_Nto2_tx(cbdc::transaction::wallet& sender,
72-
cbdc::transaction::wallet& reciever,
72+
cbdc::transaction::wallet& receiver,
7373
uint32_t n_in,
7474
benchmark::State& state) {
7575
std::optional<cbdc::transaction::full_tx> maybe_tx{};
7676
state.ResumeTiming();
7777
maybe_tx
78-
= sender.send_to(n_in * 2 - 1, reciever.generate_key(), true).value();
78+
= sender.send_to(n_in * 2 - 1, receiver.generate_key(), true).value();
7979
state.PauseTiming();
8080
if(maybe_tx.has_value()) {
8181
sender.confirm_transaction(*maybe_tx);
82-
reciever.confirm_transaction(*maybe_tx);
82+
receiver.confirm_transaction(*maybe_tx);
8383
return true;
8484
}
8585
return false;

scripts/benchmarks.sh

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
# Exit script on failure.
33
set -e
44

@@ -42,13 +42,13 @@ do
4242
-d|--build-dir)
4343
shift
4444
ARG="$1"
45-
if [[ $ARG == "" || ${ARG:0:1} == "-" ]]
45+
if [[ "${ARG}" == "" || ${ARG:0:1} == "-" ]]
4646
then
4747
echo -n "ERROR: The -d flag was used, "
4848
echo "but a valid build folder was not given."
4949
exit 1
5050
fi
51-
BUILD_DIR=$ARG
51+
BUILD_DIR="${ARG}"
5252
shift
5353
;;
5454
*)
@@ -69,7 +69,7 @@ then
6969
BUILD_DIR="${REPO_TOP_DIR}/build"
7070
fi
7171

72-
if [[ ! -d "$BUILD_DIR" ]]
72+
if [[ ! -d "${BUILD_DIR}" ]]
7373
then
7474
echo "ERROR: The folder '${BUILD_DIR}' was not found."
7575
exit 1
@@ -78,14 +78,15 @@ fi
7878
# If the build folder is a relative path, convert it to an absolute path
7979
# to avoid potential relative path errors and to improve readability
8080
# if the path is written to stdout.
81-
export BUILD_DIR=$(cd "$BUILD_DIR"; pwd)
81+
BUILD_DIR=$(cd "${BUILD_DIR}"; pwd)
82+
export BUILD_DIR
8283
echo "Build folder: '${BUILD_DIR}'"
8384
echo
8485

8586
run_test_suite () {
86-
cd "$BUILD_DIR"
87+
cd "${BUILD_DIR}"
8788
find . -name '*.gcda' -exec rm {} \;
88-
"$PWD"/"$1" "${GTEST_FLAGS[@]}"
89+
"${PWD}"/"$1" "${GTEST_FLAGS[@]}"
8990
}
9091

9192
run_test_suite "benchmarks/run_benchmarks"

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

+20-16
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
set -e
44

55
help() {
6-
if [ $# -gt 0 ]; then
6+
if [[ $# -gt 0 ]]; then
77
printf 'Unexpected Argument (%s)\n' "$1"
88
fi
99
printf 'HELP: Usage: %s [Debug|Release|Profiling]\n' "$0"
@@ -13,21 +13,21 @@ help() {
1313
# Note:
1414
# CMAKE_BUILD_TYPE="Debug" adds "-O0 -g" flags by default
1515
# CMAKE_BUILD_TYPE="Release" adds "-O3 -DNDEBUG" by default
16-
if [[ "$BUILD_DEBUG" == "1" ]]; then
16+
if [[ "${BUILD_DEBUG}" == "1" ]]; then
1717
CMAKE_BUILD_TYPE="Debug"
18-
elif [[ "$BUILD_RELEASE" == "1" ]]; then
18+
elif [[ "${BUILD_RELEASE}" == "1" ]]; then
1919
CMAKE_BUILD_TYPE="Release"
20-
elif [[ "$BUILD_PROFILING" == "1" ]]; then
20+
elif [[ "${BUILD_PROFILING}" == "1" ]]; then
2121
CMAKE_BUILD_TYPE="Profiling"
2222
fi
2323

24-
if [ $# -gt 0 ]; then
24+
if [[ $# -gt 0 ]]; then
2525
case "$1" in
2626
Release|--release|-r) CMAKE_BUILD_TYPE="Release";;
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

@@ -36,29 +36,33 @@ echo "Building..."
3636
# see PREFIX in ./scripts/setup-dependencies.sh
3737
PREFIX="$(cd "$(dirname "$0")"/.. && pwd)/prefix"
3838

39-
if [ -z ${BUILD_DIR+x} ]; then
39+
if [[ -z ${BUILD_DIR+x} ]]; then
4040
export BUILD_DIR=build
4141
fi
4242

43-
mkdir -p $BUILD_DIR
44-
cd $BUILD_DIR
43+
mkdir -p "${BUILD_DIR}"
44+
cd "${BUILD_DIR}"
4545

4646
CMAKE_FLAGS=-DCMAKE_PREFIX_PATH="${PREFIX}"
4747
CPUS=1
48-
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
48+
if [[ "${OSTYPE}" == "linux-gnu"* ]]; then
4949
CPUS=$(grep -c ^processor /proc/cpuinfo)
50-
elif [[ "$OSTYPE" == "darwin"* ]]; then
50+
elif [[ "${OSTYPE}" == "darwin"* ]]; then
5151
CPUS=$(sysctl -n hw.ncpu)
5252
XCODE_CMDLINE_DIR=$(xcode-select -p)
53-
CMAKE_FLAGS+=" -DCMAKE_C_COMPILER=${XCODE_CMDLINE_DIR}/usr/bin/clang -DCMAKE_CXX_COMPILER=${XCODE_CMDLINE_DIR}/usr/bin/clang++ -DCMAKE_CXX_FLAGS=-isystem\ /usr/local/include -DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
53+
CMAKE_FLAGS+=" -DCMAKE_C_COMPILER=${XCODE_CMDLINE_DIR}/usr/bin/clang"
54+
CMAKE_FLAGS+=" -DCMAKE_CXX_COMPILER=${XCODE_CMDLINE_DIR}/usr/bin/clang++"
55+
CMAKE_FLAGS+=" -DCMAKE_CXX_FLAGS=-isystem\ /usr/local/include"
56+
CMAKE_FLAGS+=" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
5457
fi
5558

56-
if [[ -z $CMAKE_BUILD_TYPE ]]; then
59+
if [[ -z "${CMAKE_BUILD_TYPE}" ]]; then
5760
echo "CMAKE_BUILD_TYPE not set, defaulting to debug"
5861
CMAKE_BUILD_TYPE="Debug"
5962
fi
6063

61-
echo "Building $CMAKE_BUILD_TYPE"
64+
echo "Building ${CMAKE_BUILD_TYPE}"
6265
eval "cmake -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} ${CMAKE_FLAGS} .."
63-
make -j$CPUS
66+
make "-j${CPUS}"
6467

68+
echo; echo "Build complete"; echo

scripts/create-e2e-report.sh

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

65
function readAndFormatLogs() {
76
logdir="$1"
87
message=""
9-
if [[ ! -d $logdir ]]; then
10-
echo "$logdir does not exist"
8+
if [[ ! -d "${logdir}" ]]; then
9+
echo "${logdir} does not exist"
1110
return
1211
fi
1312

14-
for logfile in $(ls $logdir); do
15-
logfile_path="$logdir/$logfile"
16-
logfile_content=$(cat $logfile_path)
17-
message+="\n<details>\n<summary>$logfile</summary>\n\n\`\`\`\n$logfile_content\n\`\`\`\n</details>\n"
13+
for logfile in "${logdir}"/*; do
14+
logfile_content=$(cat "${logfile}")
15+
message+="\n<details>\n<summary>${logfile}</summary>\n\n\`\`\`\n${logfile_content}\n\`\`\`\n</details>\n"
1816
done
19-
echo "$message"
17+
echo "${message}"
2018
}
2119

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)
20+
testrun_logs="\n<details>\n<summary>View Testrun</summary>\n\n\`\`\`\n$(cat "${TESTRUN_PATH}/testrun.log")\n\`\`\`\n</details>\n\n"
21+
container_logs=$(readAndFormatLogs "${TESTRUN_PATH}/logs")
2422

25-
printf "# E2E Results\n# TestRun Logs\n%b\n\n# Container Logs\n%b\n" "$testrun_logs" "$container_logs"
23+
printf "# E2E Results\n# TestRun Logs\n%b\n\n# Container Logs\n%b\n" "${testrun_logs}" "${container_logs}"

0 commit comments

Comments
 (0)