Skip to content

Commit

Permalink
ci: add shellcheck gh action, lint fixes
Browse files Browse the repository at this point in the history
This commit made with the assistance of github copilot

Signed-off-by: Morgan Rockett <[email protected]>
  • Loading branch information
rockett-m committed Aug 6, 2024
1 parent 4c91a6d commit 97bd28b
Show file tree
Hide file tree
Showing 10 changed files with 473 additions and 412 deletions.
18 changes: 16 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ jobs:
run: sudo ./scripts/install-build-tools.sh
- name: Lint with Pylint
run: ./scripts/pylint.sh
shellcheck:
name: Shellcheck
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install Shellcheck
run: |
sudo apt-get update
sudo apt-get install -y shellcheck
- name: Lint with Shellcheck
run: |
NUM_CORES=$(nproc)
find . -name '*.sh' -print0 | xargs -0 -n 1 -P $NUM_CORES shellcheck
unit-and-integration-test:
name: Unit and Integration Tests
runs-on: ubuntu-22.04
Expand All @@ -84,7 +99,7 @@ jobs:
run: ./scripts/test.sh
- name: Shorten SHA
id: vars
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- uses: actions/upload-artifact@v4
if: ${{ !env.ACT }}
name: Archive Test Results
Expand Down Expand Up @@ -114,4 +129,3 @@ jobs:
name: OpenCBDC Transaction Processor docs for ${{ steps.vars.outputs.sha_short }}
path: ./doxygen_generated/html/*
retention-days: 7

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ CMakeFiles/
plots/
.deps/
.libs/
.cache/

# Database
blocks.dat
Expand Down
16 changes: 8 additions & 8 deletions benchmarks/transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ void reset_wallets(cbdc::transaction::wallet& w1,
/// @brief Time an N-in, 1-out transaction.
/// @brief Note: handles benchmark timing, do not time outside function.
/// @param sender
/// @param reciever
/// @param receiver
/// @param n_in
/// @param state
/// @return
inline bool generate_Nto1_tx(cbdc::transaction::wallet& sender,
cbdc::transaction::wallet& reciever,
cbdc::transaction::wallet& receiver,
uint32_t n_in,
benchmark::State& state) {
std::optional<cbdc::transaction::full_tx> maybe_tx{};
state.ResumeTiming();
maybe_tx = sender.send_to(n_in * 2, reciever.generate_key(), true).value();
maybe_tx = sender.send_to(n_in * 2, receiver.generate_key(), true).value();
state.PauseTiming();
if(maybe_tx.has_value()) {
sender.confirm_transaction(*maybe_tx);
reciever.confirm_transaction(*maybe_tx);
receiver.confirm_transaction(*maybe_tx);
return true;
}
return false;
Expand All @@ -64,22 +64,22 @@ inline bool generate_Nto1_tx(cbdc::transaction::wallet& sender,
/// @brief Time an N-in, 2-out transaction.
/// @brief Note: handles benchmark timing, do not time outside function.
/// @param sender
/// @param reciever
/// @param receiver
/// @param n_in
/// @param state
/// @return
inline bool generate_Nto2_tx(cbdc::transaction::wallet& sender,
cbdc::transaction::wallet& reciever,
cbdc::transaction::wallet& receiver,
uint32_t n_in,
benchmark::State& state) {
std::optional<cbdc::transaction::full_tx> maybe_tx{};
state.ResumeTiming();
maybe_tx
= sender.send_to(n_in * 2 - 1, reciever.generate_key(), true).value();
= sender.send_to(n_in * 2 - 1, receiver.generate_key(), true).value();
state.PauseTiming();
if(maybe_tx.has_value()) {
sender.confirm_transaction(*maybe_tx);
reciever.confirm_transaction(*maybe_tx);
receiver.confirm_transaction(*maybe_tx);
return true;
}
return false;
Expand Down
12 changes: 6 additions & 6 deletions scripts/benchmarks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ do
-d|--build-dir)
shift
ARG="$1"
if [[ $ARG == "" || ${ARG:0:1} == "-" ]]
if [[ "${ARG}" == "" || ${ARG:0:1} == "-" ]]
then
echo -n "ERROR: The -d flag was used, "
echo "but a valid build folder was not given."
exit 1
fi
BUILD_DIR=$ARG
BUILD_DIR="${ARG}"
shift
;;
*)
Expand All @@ -69,7 +69,7 @@ then
BUILD_DIR="${REPO_TOP_DIR}/build"
fi

if [[ ! -d "$BUILD_DIR" ]]
if [[ ! -d "${BUILD_DIR}" ]]
then
echo "ERROR: The folder '${BUILD_DIR}' was not found."
exit 1
Expand All @@ -78,14 +78,14 @@ fi
# If the build folder is a relative path, convert it to an absolute path
# to avoid potential relative path errors and to improve readability
# if the path is written to stdout.
export BUILD_DIR=$(cd "$BUILD_DIR"; pwd)
export BUILD_DIR=$(cd "${BUILD_DIR}"; pwd)
echo "Build folder: '${BUILD_DIR}'"
echo

run_test_suite () {
cd "$BUILD_DIR"
cd "${BUILD_DIR}"
find . -name '*.gcda' -exec rm {} \;
"$PWD"/"$1" "${GTEST_FLAGS[@]}"
"${PWD}"/"$1" "${GTEST_FLAGS[@]}"
}

run_test_suite "benchmarks/run_benchmarks"
27 changes: 14 additions & 13 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e

help() {
if [ $# -gt 0 ]; then
if [[ $# -gt 0 ]]; then
printf 'Unexpected Argument (%s)\n' "$1"
fi
printf 'HELP: Usage: %s [Debug|Release|Profiling]\n' "$0"
Expand All @@ -13,15 +13,15 @@ help() {
# Note:
# CMAKE_BUILD_TYPE="Debug" adds "-O0 -g" flags by default
# CMAKE_BUILD_TYPE="Release" adds "-O3 -DNDEBUG" by default
if [[ "$BUILD_DEBUG" == "1" ]]; then
if [[ "${BUILD_DEBUG}" == "1" ]]; then
CMAKE_BUILD_TYPE="Debug"
elif [[ "$BUILD_RELEASE" == "1" ]]; then
elif [[ "${BUILD_RELEASE}" == "1" ]]; then
CMAKE_BUILD_TYPE="Release"
elif [[ "$BUILD_PROFILING" == "1" ]]; then
elif [[ "${BUILD_PROFILING}" == "1" ]]; then
CMAKE_BUILD_TYPE="Profiling"
fi

if [ $# -gt 0 ]; then
if [[ $# -gt 0 ]]; then
case "$1" in
Release|--release|-r) CMAKE_BUILD_TYPE="Release";;
Profiling|--profiling|-p) CMAKE_BUILD_TYPE="Profiling";;
Expand All @@ -36,29 +36,30 @@ echo "Building..."
# see PREFIX in ./scripts/setup-dependencies.sh
PREFIX="$(cd "$(dirname "$0")"/.. && pwd)/prefix"

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

mkdir -p $BUILD_DIR
cd $BUILD_DIR
mkdir -p "${BUILD_DIR}"
cd "${BUILD_DIR}"

CMAKE_FLAGS=-DCMAKE_PREFIX_PATH="${PREFIX}"
CPUS=1
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
if [[ "${OSTYPE}" == "linux-gnu"* ]]; then
CPUS=$(grep -c ^processor /proc/cpuinfo)
elif [[ "$OSTYPE" == "darwin"* ]]; then
elif [[ "${OSTYPE}" == "darwin"* ]]; then
CPUS=$(sysctl -n hw.ncpu)
XCODE_CMDLINE_DIR=$(xcode-select -p)
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"
fi

if [[ -z $CMAKE_BUILD_TYPE ]]; then
if [[ -z "${CMAKE_BUILD_TYPE}" ]]; then
echo "CMAKE_BUILD_TYPE not set, defaulting to debug"
CMAKE_BUILD_TYPE="Debug"
fi

echo "Building $CMAKE_BUILD_TYPE"
echo "Building ${CMAKE_BUILD_TYPE}"
eval "cmake -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} ${CMAKE_FLAGS} .."
make -j$CPUS
make "-j${CPUS}"

echo; echo "Build complete"; echo
Loading

0 comments on commit 97bd28b

Please sign in to comment.