-
Notifications
You must be signed in to change notification settings - Fork 311
115 lines (96 loc) · 4.01 KB
/
Copy pathwasm-size.yml
File metadata and controls
115 lines (96 loc) · 4.01 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
name: WASM Size Budget
# Enforces per-contract WASM size budgets so accidental bloat is caught in CI
# before it reaches mainnet deployment. Budgets are intentionally conservative
# and should be updated via a deliberate PR if a contract genuinely needs more
# space (e.g. a new feature module).
#
# Budget table (release build, wasm32v1-none, opt-level=z + LTO):
# hello-world : 20 KB – toy example, must stay tiny
# governance-events : 24 KB – pure event types + emitters, no logic
# predictify-hybrid : 900 KB – full prediction-market contract
#
# The governance-events crate was added in FWC26 (Stellar Wave).
on:
push:
branches: [ "master", "main" ]
pull_request:
branches: [ "master", "main" ]
jobs:
check-size:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source $HOME/.cargo/env
rustup target add wasm32v1-none
- name: Install Stellar CLI
run: |
brew update
brew install stellar-cli
- name: Build contracts (release, wasm32v1-none)
run: |
source $HOME/.cargo/env
stellar contract build
# ── Per-contract size gates ──────────────────────────────────────────────
# Each WASM is checked against its own budget. Any file that does not
# match a known contract name triggers a strict 20 KB fallback so unknown
# contracts cannot sneak through with unbounded size.
- name: Check WASM sizes
run: |
set -euo pipefail
source $HOME/.cargo/env
# Budgets in bytes (release + opt-level=z + LTO)
BUDGET_HELLO_WORLD=20480 # 20 KB
BUDGET_GOVERNANCE_EVENTS=24576 # 24 KB (FWC26 governance-events crate)
BUDGET_PREDICTIFY_HYBRID=921600 # 900 KB
BUDGET_FALLBACK=20480 # 20 KB (any unknown contract)
FAIL=0
for wasm_file in target/wasm32v1-none/release/*.wasm; do
[ -f "$wasm_file" ] || continue
SIZE=$(stat -f%z "$wasm_file")
BASE=$(basename "$wasm_file" .wasm)
case "$BASE" in
hello_world)
BUDGET=$BUDGET_HELLO_WORLD ;;
governance_events)
BUDGET=$BUDGET_GOVERNANCE_EVENTS ;;
predictify_hybrid)
BUDGET=$BUDGET_PREDICTIFY_HYBRID ;;
*)
BUDGET=$BUDGET_FALLBACK ;;
esac
BUDGET_KB=$(( BUDGET / 1024 ))
SIZE_KB=$(echo "scale=1; $SIZE / 1024" | bc)
if [ "$SIZE" -gt "$BUDGET" ]; then
echo "::error file=$wasm_file::WASM size budget exceeded: $BASE = ${SIZE_KB} KB (budget ${BUDGET_KB} KB)"
FAIL=1
else
echo "OK $BASE: ${SIZE_KB} KB / ${BUDGET_KB} KB"
fi
done
if [ "$FAIL" -eq 1 ]; then
echo ""
echo "One or more contracts exceeded their WASM size budget."
echo "If the growth is intentional, update the budget table in"
echo ".github/workflows/wasm-size.yml with a justification comment."
exit 1
fi
echo ""
echo "All contracts are within their WASM size budgets."
# ── Size report (informational, never fails the build) ───────────────────
- name: Report WASM sizes
if: always()
run: |
echo "### WASM size report" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Contract | Size |" >> $GITHUB_STEP_SUMMARY
echo "|---|---|" >> $GITHUB_STEP_SUMMARY
for wasm_file in target/wasm32v1-none/release/*.wasm; do
[ -f "$wasm_file" ] || continue
SIZE=$(stat -f%z "$wasm_file")
SIZE_KB=$(echo "scale=1; $SIZE / 1024" | bc)
BASE=$(basename "$wasm_file" .wasm)
echo "| \`$BASE\` | ${SIZE_KB} KB |" >> $GITHUB_STEP_SUMMARY
done