Skip to content

Commit

Permalink
Add test SDK to CI (nexus-xyz#252)
Browse files Browse the repository at this point in the history
Add test SDK to CI

Co-authored-by: duc-nx <>
  • Loading branch information
duc-nx authored Jul 26, 2024
1 parent c72bdcb commit e46d1ca
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,11 @@ jobs:
- run: rustup target add riscv32i-unknown-none-elf
- run: assets/scripts/smoke.sh examples/src/bin/fib3.rs
- run: assets/scripts/smoke.sh examples/src/bin/hello.rs

test-sdk:
needs: check-build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: rustup target add riscv32i-unknown-none-elf
- run: assets/scripts/test_sdk.sh examples/src/bin/hello.rs
59 changes: 59 additions & 0 deletions assets/scripts/test_sdk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash
# This script follows steps written in README.md
# Using the rust file specified as the unique argument.
# Call at the top directory of the nexus-zkvm project
# For example:
# ./assets/scripts/test_sdk.sh examples/src/bin/fib3.rs
# Every command needs to succeed
set -e

ORIGINAL_DIR=$(pwd)
PROJECT_NAME="/tmp/nexus-host-ci"

if [ "$#" -ne 1 ]; then
echo "Usage: $0 <file.rs>"
exit 1
fi

if [ ! -f "$1" ]; then
echo "Usage: $0 <file.rs>"
echo "where <file.rs> is a path to a file."
exit 1
fi

if [ -e "$PROJECT_NAME" ]; then
echo "Error: Directory '$PROJECT_NAME' already exists."
exit 1
fi

set -x

cleanup() {
cd "$ORIGINAL_DIR"
rm -rf "$PROJECT_NAME"
}

trap cleanup SIGINT

error_handler() {
echo "Error occurred in test_sdk.sh on line ${1}. Exiting."
cleanup
exit 1
}

trap 'error_handler $LINENO' ERR

# Builds current cargo-nexus tool from current commit
cargo build --release --package cargo-nexus --bin cargo-nexus
./target/release/cargo-nexus nexus host "$PROJECT_NAME"
# Copy the test source file to guest program
cp "$1" "$PROJECT_NAME/src/guest/src/main.rs"
cd "$PROJECT_NAME"

# Link the test program to the current sdk commit
sed -e "s#nexus-sdk = { git = \"https://github.com/nexus-xyz/nexus-zkvm.git\", version = \"0.2.0\" }#nexus-sdk = { path = \"$ORIGINAL_DIR/sdk\"}#" Cargo.toml > Cargo.tmp && mv Cargo.tmp Cargo.toml

cargo update
cargo run --release

cleanup

0 comments on commit e46d1ca

Please sign in to comment.