Merge pull request #515 from ruthoreaji-123/feat/wasm-size-optimizati… #50
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Contracts CI | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - "contracts/**" | |
| - ".github/workflows/contracts-ci.yml" | |
| pull_request: | |
| paths: | |
| - "contracts/**" | |
| - ".github/workflows/contracts-ci.yml" | |
| jobs: | |
| contract-checks: | |
| name: Build, Lint & Test Soroban Contract | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Install Rust toolchain | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: wasm32-unknown-unknown | |
| components: clippy | |
| - name: Cache Cargo registry and build artifacts | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| contracts/target | |
| key: ${{ runner.os }}-cargo-${{ hashFiles('contracts/Cargo.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-cargo- | |
| - name: Install cargo-audit | |
| run: cargo install cargo-audit --locked | |
| - name: Audit Cargo dependencies | |
| working-directory: contracts | |
| run: cargo audit 2>&1 | tee /tmp/cargo-audit.txt; exit ${PIPESTATUS[0]} | |
| - name: Upload cargo audit artifact | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: cargo-audit-report | |
| path: /tmp/cargo-audit.txt | |
| - name: Run clippy (deny all warnings) | |
| working-directory: contracts | |
| run: cargo clippy --all-targets --all-features -- -D warnings | |
| - name: Run contract tests | |
| working-directory: contracts | |
| run: cargo test --features testutils | |
| - name: Build WASM release binary (no testutils) | |
| working-directory: contracts | |
| run: cargo build --target wasm32-unknown-unknown --release --no-default-features | |
| - name: Verify testutils excluded from release binary | |
| working-directory: contracts | |
| run: | | |
| WASM_FILE=$(find target/wasm32-unknown-unknown/release -name "*.wasm" | head -1) | |
| if [ -z "$WASM_FILE" ]; then | |
| echo "ERROR: No WASM file found." >&2 | |
| exit 1 | |
| fi | |
| # Confirm the strings "testutils" or "register_stellar_asset" do not | |
| # appear in the release binary (they would only be present if test | |
| # utilities were compiled in). | |
| if strings "$WASM_FILE" | grep -qE "testutils|register_stellar_asset"; then | |
| echo "ERROR: Release binary contains test utility symbols. Ensure testutils feature is excluded from release builds." >&2 | |
| exit 1 | |
| fi | |
| echo "✅ Release binary does not contain test utility symbols." | |
| - name: Report WASM binary size | |
| working-directory: contracts | |
| run: | | |
| WASM_FILE=$(find target/wasm32-unknown-unknown/release -name "*.wasm" | head -1) | |
| if [ -n "$WASM_FILE" ]; then | |
| SIZE_BYTES=$(wc -c < "$WASM_FILE") | |
| SIZE_KB=$(echo "scale=2; $SIZE_BYTES / 1024" | bc) | |
| echo "### WASM Binary Size" >> $GITHUB_STEP_SUMMARY | |
| echo "| File | Size |" >> $GITHUB_STEP_SUMMARY | |
| echo "|------|------|" >> $GITHUB_STEP_SUMMARY | |
| echo "| \`$WASM_FILE\` | ${SIZE_KB} KB (${SIZE_BYTES} bytes) |" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "No WASM file found." >> $GITHUB_STEP_SUMMARY | |
| fi | |
| - name: Compare costs with baseline (if baseline exists) | |
| if: hashFiles('contracts/BASELINE_COSTS.md') != '' | |
| working-directory: contracts | |
| env: | |
| BASELINE_FILE: ../contracts/BASELINE_COSTS.md | |
| # CI doesn't have a live network, so we only validate the script compiles | |
| # and the comparison logic works. The --compare flag skips network calls. | |
| run: | | |
| echo "### Cost Comparison" >> $GITHUB_STEP_SUMMARY | |
| echo "Baseline file exists. To run a full cost comparison, deploy the contract" >> $GITHUB_STEP_SUMMARY | |
| echo "and run \`scripts/benchmark.sh\` with a configured SOURCE account." >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**Note:** On-chain cost benchmarking requires \`stellar contract invoke --cost\`" >> $GITHUB_STEP_SUMMARY | |
| echo "against a live network (testnet/localnet). This CI step validates the script" >> $GITHUB_STEP_SUMMARY | |
| echo "syntax and baseline file format." >> $GITHUB_STEP_SUMMARY | |
| # Verify the baseline file is valid markdown | |
| head -2 ../contracts/BASELINE_COSTS.md | grep -q "Baseline" && echo "✅ Baseline file valid" | |
| # Check scripts/benchmark.sh exists and is executable | |
| test -x ../scripts/benchmark.sh && echo "✅ benchmark.sh is executable" || echo "⚠️ benchmark.sh not found" |