Skip to content

Commit

Permalink
Merge pull request #5 from qdrvm/ci/ci_build
Browse files Browse the repository at this point in the history
ci tests
  • Loading branch information
zerg-su authored Sep 3, 2024
2 parents f219f1e + 0207398 commit 53ea256
Show file tree
Hide file tree
Showing 9 changed files with 607 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .ci/build_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

cd ../

run_build() {
build_type=$1
build_dir=$2

echo "Building with BUILD_TYPE=$build_type..."

make -B build BUILD_TYPE="$build_type" BUILD_DIR="$build_dir"

if [ $? -ne 0 ]; then
echo "Error: Build failed for BUILD_TYPE=$build_type."
exit 1
else
echo "Success: Build completed successfully for BUILD_TYPE=$build_type."
fi
}

run_build Debug build-debug
run_build Release build

echo "All build tests completed successfully."
exit 0
24 changes: 24 additions & 0 deletions .ci/cargo_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

export HEADER_FILE="/dev/null"
export CBINDGEN_CONFIG="../../cbindgen.toml"

CRATES_DIR="../crates"

for dir in "$CRATES_DIR"/*; do
if [ -d "$dir" ]; then
echo "Entering directory: $dir"
cd "$dir" || exit

cargo test

if [ $? -ne 0 ]; then
echo "Error: cargo test failed in $dir"
exit 1
fi

cd - || exit
fi
done

echo "All tests completed successfully."
38 changes: 38 additions & 0 deletions .ci/check_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import os

required_structure = {
'install': {
'include': {
'arkworks': ['arkworks.h'],
'bandersnatch_vrfs': ['bandersnatch_vrfs.h'],
'schnorrkel': ['schnorrkel.h']
},
'lib': {
'cmake': {
'arkworks': ['arkworksConfig.cmake'],
'bandersnatch_vrfs': ['bandersnatch_vrfsConfig.cmake'],
'schnorrkel': ['schnorrkelConfig.cmake']
},
'': ['libarkworks_crust.a', 'libbandersnatch_vrfs_crust.a', 'libschnorrkel_crust.a']
}
}
}

def check_structure(base_path, structure):
for folder, contents in structure.items():
current_path = os.path.join(base_path, folder)

if isinstance(contents, dict):
if not os.path.isdir(current_path):
print(f"Missing directory: {current_path}")
else:
check_structure(current_path, contents)
else:
for file in contents:
file_path = os.path.join(base_path, folder, file)
if not os.path.isfile(file_path):
print(f"Missing file: {file_path}")

base_path = '../'

check_structure(base_path, required_structure)
34 changes: 34 additions & 0 deletions .ci/run_all_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

scripts=("build_test.sh" "check_files.py" "cargo_tests.sh")

error_found=0

for script in "${scripts[@]}"; do
echo "Running $script..."

if [[ "$script" == *.py ]]; then
python3 "$script"
elif [[ "$script" == *.sh ]]; then
bash "$script"
else
echo "Unknown file type for script: $script"
error_found=1
continue
fi

if [ $? -ne 0 ]; then
echo "Error: $script failed."
error_found=1
else
echo "Success: $script completed successfully."
fi
done

if [ $error_found -ne 0 ]; then
echo "One or more scripts failed."
exit 1
else
echo "All scripts ran successfully."
exit 0
fi
30 changes: 30 additions & 0 deletions .github/workflows/run_tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Run Tests

on:
push:
branches:
- master
pull_request:
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Cache folders
uses: actions/cache@v4
with:
path: |
build
build-debug
key: ${{ runner.os }}-build-${{ hashFiles('**/CMakeLists.txt') }}
restore-keys: |
${{ runner.os }}-build-
- name: Run tests
working-directory: .ci
run: bash run_all_tests.sh
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
target
/build
/generated
/install
/.idea
/build-*
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
BUILD_DIR ?= build
BUILD_TYPE ?= Release

BUILD_THREADS := $$(nproc 2>/dev/null || sysctl -n hw.ncpu)


build:
if [ "$$(uname)" = "Darwin" ]; then \
export SDKROOT=$$(xcrun --sdk macosx --show-sdk-path) ; \
fi ; \
cmake . -B"$(BUILD_DIR)" -DCMAKE_INSTALL_PREFIX=install -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) ; \
cmake --build "$(BUILD_DIR)" -- -j$(BUILD_THREADS) ; \
cmake --install "$(BUILD_DIR)"

run_tests:
cd .ci && ./run_all_tests.sh
Loading

0 comments on commit 53ea256

Please sign in to comment.