diff --git a/.github/workflows/rust-wasm.yml b/.github/workflows/rust-wasm.yml new file mode 100644 index 0000000..4a4074a --- /dev/null +++ b/.github/workflows/rust-wasm.yml @@ -0,0 +1,86 @@ +name: Rust + WASM CI + +on: + pull_request: + paths: + - "contracts/**" + - "backend/**" + - "Cargo.toml" + - "Cargo.lock" + push: + branches: + - main + paths: + - "contracts/**" + - "backend/**" + - "Cargo.toml" + - "Cargo.lock" + +jobs: + rust-test: + name: Rust unit tests + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + components: clippy + profile: minimal + override: true + + - name: Cache Cargo registry + uses: actions/cache@v3 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo- + + - name: Run cargo fmt check + run: cargo fmt --all -- --check + + - name: Run clippy + run: cargo clippy --all-targets --all-features -- -D warnings + + - name: Run tests + run: cargo test --all-features --workspace --locked --quiet + working-directory: ./contracts + + wasm-build: + name: Build WASM artifacts + runs-on: ubuntu-latest + needs: rust-test + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Rust toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + - name: Add WASM target + run: rustup target add wasm32-unknown-unknown + + - name: Build all contract crates to WASM + run: | + cd contracts + cargo build --all --target wasm32-unknown-unknown --release + + - name: Collect built WASM + run: | + mkdir -p artifacts/wasm + find ./target/wasm32-unknown-unknown/release -name '*.wasm' -exec cp {} artifacts/wasm/ \; + + - name: Upload WASM artifacts + uses: actions/upload-artifact@v4 + with: + name: wasm-artifacts + path: artifacts/wasm \ No newline at end of file