Skip to content

Commit

Permalink
ci: add shellcheck gh action, lint fixes, parallel acts
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 <morgan.rockett@tufts.edu>
  • Loading branch information
rockett-m committed Aug 7, 2024
1 parent 4c91a6d commit bc19c19
Show file tree
Hide file tree
Showing 19 changed files with 691 additions and 576 deletions.
26 changes: 19 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Setup Build Env
- name: Install Build Tools
run: sudo ./scripts/install-build-tools.sh
- name: Setup Local Dependencies
run: ./scripts/setup-dependencies.sh
Expand All @@ -38,7 +38,7 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Setup Build Env
- name: Install Build Tools
run: sudo ./scripts/install-build-tools.sh
- name: Setup Local Dependencies
run: ./scripts/setup-dependencies.sh
Expand All @@ -50,7 +50,7 @@ jobs:
name: Pylint
runs-on: ubuntu-22.04
continue-on-error: true
timeout-minutes: 10
timeout-minutes: 5
strategy:
matrix:
python-version: ["3.10"]
Expand All @@ -62,10 +62,23 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Setup Build Env
- name: Install Build Tools
run: sudo ./scripts/install-build-tools.sh
- name: Lint with Pylint
run: ./scripts/pylint.sh
shellcheck:
name: Shellcheck
runs-on: ubuntu-22.04
continue-on-error: true
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install Build Tools
run: sudo ./scripts/install-build-tools.sh
- name: Lint with Shellcheck
run: ./scripts/shellcheck.sh view
unit-and-integration-test:
name: Unit and Integration Tests
runs-on: ubuntu-22.04
Expand All @@ -74,7 +87,7 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Setup Build Env
- name: Install Build Tools
run: sudo ./scripts/install-build-tools.sh
- name: Setup Local Dependencies
run: ./scripts/setup-dependencies.sh
Expand All @@ -84,7 +97,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 +127,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
15 changes: 8 additions & 7 deletions scripts/benchmarks.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# Exit script on failure.
set -e

Expand Down 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,15 @@ 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)
BUILD_DIR=$(cd "${BUILD_DIR}"; pwd)
export BUILD_DIR
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"
8 changes: 4 additions & 4 deletions scripts/build-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ DOCKER_IMAGE_TAG_TWOPHASE=${DOCKER_IMAGE_TAG:-opencbdc-tx-twophase}
git submodule init && git submodule update

# Build docker image
docker build --target base -t $DOCKER_IMAGE_TAG_BASE -f $SCRIPT_DIR/../Dockerfile $SCRIPT_DIR/..
docker build --target builder --build-arg BASE_IMAGE=base -t $DOCKER_IMAGE_TAG_BUILDER -f $SCRIPT_DIR/../Dockerfile $SCRIPT_DIR/..
docker build --target twophase --build-arg BASE_IMAGE=base -t $DOCKER_IMAGE_TAG_TWOPHASE -f $SCRIPT_DIR/../Dockerfile $SCRIPT_DIR/..
docker build --target atomizer --build-arg BASE_IMAGE=base -t $DOCKER_IMAGE_TAG_ATOMIZER -f $SCRIPT_DIR/../Dockerfile $SCRIPT_DIR/..
docker build --target base -t "${DOCKER_IMAGE_TAG_BASE}" -f "${SCRIPT_DIR}/../Dockerfile" "${SCRIPT_DIR}/.."
docker build --target builder --build-arg BASE_IMAGE=base -t "${DOCKER_IMAGE_TAG_BUILDER}" -f "${SCRIPT_DIR}/../Dockerfile" "${SCRIPT_DIR}/.."
docker build --target twophase --build-arg BASE_IMAGE=base -t "${DOCKER_IMAGE_TAG_TWOPHASE}" -f "${SCRIPT_DIR}/../Dockerfile" "${SCRIPT_DIR}}/.."
docker build --target atomizer --build-arg BASE_IMAGE=base -t "${DOCKER_IMAGE_TAG_ATOMIZER}" -f "${SCRIPT_DIR}/../Dockerfile" "${SCRIPT_DIR}}/.."
36 changes: 20 additions & 16 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash
#!/usr/bin/env bash

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,21 +13,21 @@ 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";;
Debug|--debug|-d) CMAKE_BUILD_TYPE="Debug";;
--help|-h) help;;
*) help $1;;
*) help "$1";;
esac
fi

Expand All @@ -36,29 +36,33 @@ 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"
CMAKE_FLAGS+=" -DCMAKE_C_COMPILER=${XCODE_CMDLINE_DIR}/usr/bin/clang"
CMAKE_FLAGS+=" -DCMAKE_CXX_COMPILER=${XCODE_CMDLINE_DIR}/usr/bin/clang++"
CMAKE_FLAGS+=" -DCMAKE_CXX_FLAGS=-isystem\ /usr/local/include"
CMAKE_FLAGS+=" -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
20 changes: 9 additions & 11 deletions scripts/create-e2e-report.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
#!/usr/bin/env bash
set -e
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
TESTRUN_PATH=$1

function readAndFormatLogs() {
logdir="$1"
message=""
if [[ ! -d $logdir ]]; then
echo "$logdir does not exist"
if [[ ! -d "${logdir}" ]]; then
echo "${logdir} does not exist"
return
fi

for logfile in $(ls $logdir); do
logfile_path="$logdir/$logfile"
logfile_content=$(cat $logfile_path)
message+="\n<details>\n<summary>$logfile</summary>\n\n\`\`\`\n$logfile_content\n\`\`\`\n</details>\n"
for logfile in "${logdir}"/*; do
logfile_content=$(cat "${logfile}")
message+="\n<details>\n<summary>${logfile}</summary>\n\n\`\`\`\n${logfile_content}\n\`\`\`\n</details>\n"
done
echo "$message"
echo "${message}"
}

testrun_logs="\n<details>\n<summary>View Testrun</summary>\n\n\`\`\`\n$(cat $TESTRUN_PATH/testrun.log)\n\`\`\`\n</details>\n\n"
container_logs=$(readAndFormatLogs $TESTRUN_PATH/logs)
testrun_logs="\n<details>\n<summary>View Testrun</summary>\n\n\`\`\`\n$(cat "${TESTRUN_PATH}/testrun.log")\n\`\`\`\n</details>\n\n"
container_logs=$(readAndFormatLogs "${TESTRUN_PATH}/logs")

printf "# E2E Results\n# TestRun Logs\n%b\n\n# Container Logs\n%b\n" "$testrun_logs" "$container_logs"
printf "# E2E Results\n# TestRun Logs\n%b\n\n# Container Logs\n%b\n" "${testrun_logs}" "${container_logs}"
Loading

0 comments on commit bc19c19

Please sign in to comment.