-
Notifications
You must be signed in to change notification settings - Fork 179
238 lines (206 loc) · 7.89 KB
/
Copy pathperformance-ci.yml
File metadata and controls
238 lines (206 loc) · 7.89 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
name: Performance CI
on:
pull_request:
branches: [main]
push:
branches: [main]
env:
NODE_VERSION: '20'
jobs:
# ── 1. Frontend performance budget ──────────────────────────────────────────
performance-budget:
name: Frontend Performance Budget
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: ./.github/actions/setup-node
- name: Run performance budget check
run: npm run performance:ci
env:
# Point at the CI artifact if one was produced by a prior E2E run.
# Falls back gracefully when no report exists (validates config only).
PERFORMANCE_REPORT: ${{ github.workspace }}/artifacts/performance-report.json
- name: Upload performance budget config
if: always()
uses: actions/upload-artifact@v4
with:
name: performance-budget-${{ github.sha }}
path: performance-budget.json
retention-days: 30
# ── 2. Bundle size analysis ──────────────────────────────────────────────────
bundle-size:
name: Bundle Size Analysis
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: ./.github/actions/setup-node
- name: Run bundle size check
run: npx size-limit --json > bundle-size-report.json || true
- name: Post bundle size comment
if: github.event_name == 'pull_request'
continue-on-error: true
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
let report = [];
try {
report = JSON.parse(fs.readFileSync('bundle-size-report.json', 'utf8'));
} catch {
console.log('No bundle size report generated (no .size-limit.json entries matched)');
return;
}
if (!report.length) return;
const rows = report.map(r => {
const passed = r.passed !== false ? '✅' : '❌';
const size = r.size ? `${(r.size / 1024).toFixed(1)} KB` : '—';
const limit = r.sizeLimit ? `${(r.sizeLimit / 1024).toFixed(1)} KB` : '—';
return `| ${passed} | \`${r.name}\` | ${size} | ${limit} |`;
}).join('\n');
const body = [
'### 📦 Bundle Size Report',
'',
'| Status | Package | Size | Limit |',
'|--------|---------|------|-------|',
rows,
].join('\n');
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body,
});
- name: Upload bundle report
if: always()
uses: actions/upload-artifact@v4
with:
name: bundle-size-${{ github.sha }}
path: bundle-size-report.json
if-no-files-found: ignore
retention-days: 30
# ── 3. Soroban gas benchmarks ────────────────────────────────────────────────
gas-benchmarks:
name: Gas Benchmarks (Soroban)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Install Rust stable toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
components: clippy, rustfmt
- name: Cache Cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
contracts/target
key: cargo-${{ runner.os }}-${{ hashFiles('contracts/Cargo.lock') }}
restore-keys: |
cargo-${{ runner.os }}-
- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: '3.11'
- name: Restore gas baseline
uses: actions/cache@v4
with:
path: gas-benchmarks/baseline.json
key: gas-baseline-${{ hashFiles('contracts/subscription/src/**/*.rs', 'contracts/types/src/**/*.rs') }}
restore-keys: |
gas-baseline-
- name: Run gas benchmarks
id: gas_bench
run: bash scripts/gas-benchmark.sh
env:
GAS_REGRESSION_THRESHOLD: '0.10'
COMMIT_SHA: ${{ github.sha }}
COMMIT_TIME: ${{ github.event.head_commit.timestamp }}
continue-on-error: true
- name: Save updated baseline (main branch only)
if: github.ref == 'refs/heads/main'
uses: actions/cache@v4
with:
path: gas-benchmarks/baseline.json
key: gas-baseline-${{ hashFiles('contracts/subscription/src/**/*.rs', 'contracts/types/src/**/*.rs') }}
- name: Upload gas benchmark artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: gas-benchmarks-${{ github.sha }}
path: |
gas-benchmarks/baseline.json
gas-benchmarks/trends.json
gas-benchmarks/gas_trend.svg
if-no-files-found: ignore
retention-days: 90
- name: Post gas benchmark results to PR
if: github.event_name == 'pull_request' && always()
continue-on-error: true
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const trendsPath = 'gas-benchmarks/trends.json';
if (!fs.existsSync(trendsPath)) return;
const trends = JSON.parse(fs.readFileSync(trendsPath, 'utf8'));
const latest = trends[trends.length - 1];
if (!latest?.results) return;
const rows = Object.entries(latest.results)
.map(([fn, m]) => {
const cpu = m.instructions ?? 0;
return `| \`${fn}\` | ${cpu.toLocaleString()} |`;
})
.join('\n');
const body = [
'### ⛽ Gas Benchmark Results',
'',
'| Function | CPU Instructions |',
'|----------|-----------------|',
rows,
'',
`Commit: \`${latest.sha}\``,
].join('\n');
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body,
});
- name: Fail if gas regressions detected
if: steps.gas_bench.outcome == 'failure'
continue-on-error: true
run: |
echo "::warning::Gas benchmarks detected regressions exceeding the 10% threshold."
echo "Download the gas-benchmarks artifact to see the full report."
# ── 4. Contracts lint & test ─────────────────────────────────────────────────
contracts-ci:
name: Contracts (Clippy + Test)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Install Rust stable toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: stable
components: clippy, rustfmt
- name: Cache Cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
contracts/target
key: cargo-${{ runner.os }}-${{ hashFiles('contracts/Cargo.lock') }}
restore-keys: |
cargo-${{ runner.os }}-
- name: Cargo fmt check
continue-on-error: true
run: npm run contracts:fmt
- name: Cargo clippy
continue-on-error: true
run: npm run contracts:clippy
- name: Cargo test
continue-on-error: true
run: npm run contracts:test