-
Notifications
You must be signed in to change notification settings - Fork 173
117 lines (103 loc) · 4.6 KB
/
Copy pathcontracts-ci.yml
File metadata and controls
117 lines (103 loc) · 4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
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: wasm32v1-none
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 wasm32v1-none --release --no-default-features
- name: Verify testutils excluded from release binary
working-directory: contracts
run: |
WASM_FILE=$(find target/wasm32v1-none/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/wasm32v1-none/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"