-
Notifications
You must be signed in to change notification settings - Fork 58
371 lines (320 loc) · 13.4 KB
/
Copy pathbuild.yml
File metadata and controls
371 lines (320 loc) · 13.4 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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
name: STELLARHUNTS
on:
workflow_dispatch:
push:
branches:
- main
pull_request:
permissions: read-all
# Cancels any in-progress run for the same branch / PR so we don't
# waste runner minutes on superseded pushes.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
# ─────────────────────────────────────────────────────────────────────
# Onchain jobs (contracts)
# ─────────────────────────────────────────────────────────────────────
jobs:
# Changed-path matrix: only run the jobs relevant to the files touched
# in a PR/push, while preserving a full run whenever shared configuration
# (lockfile, workflows, release config, root manifests) changes. This
# speeds up validation without losing coverage (#321).
changes:
name: Detect changed paths
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
backend: ${{ steps.filter.outputs.backend }}
frontend: ${{ steps.filter.outputs.frontend }}
onchain: ${{ steps.filter.outputs.onchain }}
shared: ${{ steps.filter.outputs.shared }}
run-all: ${{ steps.filter.outputs.run_all }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
base: ${{ github.event.pull_request.base.sha || 'main' }}
filters: |
backend:
- 'backend/**'
frontend:
- 'frontend/**'
onchain:
- 'onchain/**'
# Shared configuration affects every project: any of these alone
# is enough to force a full (all jobs) validation run.
shared:
- 'package.json'
- 'package-lock.json'
- 'npm-workspaces.yaml'
- '**/package.json'
- '**/package-lock.json'
- '.github/workflows/**.yml'
- '.github/workflows/**.yaml'
run_all:
- 'package.json'
- 'package-lock.json'
- '**/package.json'
- '**/package-lock.json'
- '.github/workflows/release.yml'
- 'onchain/Scarb.lock'
- 'onchain/Scarb.toml'
- 'onchain/Cargo.lock'
- 'onchain/Cargo.toml'
# Helper: resolves the effective "should this job run?" boolean by OR-ing
# the project-specific filter with the shared/run-all signal.
onchain-build:
name: Build contracts
needs: changes
if: ${{ needs.changes.outputs.onchain == 'true' || needs.changes.outputs.run-all == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
# Cache Cargo artifacts and any (future) root-level
# node_modules. Keyed on the lockfile hash so a dependency change
# invalidates the entry, but identical lockfiles re-use the
# previous cache. The `**/node_modules` path is currently a
# no-op target because no JS step runs in this workflow — it is
# included so that when npm-based jobs are added in the future,
# the cache key already covers them.
- name: Cache Cargo and node_modules
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
onchain/target
**/node_modules
key: ${{ runner.os }}-cargo-${{ hashFiles('onchain/Cargo.lock', '**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@4360b52568e2003a75bf9bc1d59f33a8e3fc893c # stable
with:
targets: wasm32-unknown-unknown
components: rustfmt
# See onchain/Cargo.lock for pinned dependency resolutions.
- name: Build contracts (release wasm)
working-directory: onchain
run: cargo build --workspace --target wasm32-unknown-unknown --release --locked
- name: Format check
working-directory: onchain
run: cargo fmt --all -- --check
# ── cargo-deny ────────────────────────────────────────────
# Audit dependencies for security advisories, license compliance,
# and duplicate crate versions.
- name: Install cargo-deny
uses: taiki-e/install-action@1ed6d7be6168f6c9046541087ff549b6bc581fdf # v2.87.2
with:
tool: cargo-deny
- name: cargo-deny check
working-directory: onchain
run: cargo deny --locked check advisories licenses bans sources
onchain-test:
name: Test contracts
needs: changes
if: ${{ needs.changes.outputs.onchain == 'true' || needs.changes.outputs.run-all == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Cache Cargo and node_modules
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
onchain/target
**/node_modules
key: ${{ runner.os }}-cargo-${{ hashFiles('onchain/Cargo.lock', '**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@4360b52568e2003a75bf9bc1d59f33a8e3fc893c # stable
with:
toolchain: stable
- name: Install cargo-deny
uses: taiki-e/install-action@1ed6d7be6168f6c9046541087ff549b6bc581fdf # v2.87.2
with:
tool: cargo-deny
- name: cargo-deny check (covers dev-deps too)
working-directory: onchain
run: cargo deny --locked check advisories licenses bans sources
- name: Build contracts (test profile)
working-directory: onchain
run: cargo build --workspace --tests --locked
- name: Run unit tests
working-directory: onchain
run: cargo test --workspace --locked
# ── Resource bench ─────────────────────────────────────────
# Bench tests for submit_answer budget (issue #34). Output is
# captured as an artifact so budget regressions are visible in
# the CI run summary, and then enforced against the documented
# baselines in onchain/bench-baselines.json (issue #281) — a
# material regression fails the job.
- name: Run resource bench
working-directory: onchain
run: cargo test --workspace --locked -- bench_ --nocapture 2>&1 | tee bench-output.txt
- name: Check bench budget thresholds
# Fails when any measured metric exceeds its baseline or when
# the bench produced no measurements at all (silent regression).
run: python3 scripts/check-bench-budgets.py onchain/bench-output.txt
- name: Upload bench artifact
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: bench-output
path: onchain/bench-output.txt
if-no-files-found: warn
retention-days: 7
# ─────────────────────────────────────────────────────────────────────
# Backend CI
# ─────────────────────────────────────────────────────────────────────
backend-lint:
name: Backend lint
needs: changes
if: ${{ needs.changes.outputs.backend == 'true' || needs.changes.outputs.shared == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Setup Node.js
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: 20
cache: npm
cache-dependency-path: backend/package-lock.json
- name: Install dependencies
working-directory: backend
run: npm ci
- name: Lint
working-directory: backend
# The backend currently contains pre-existing lint errors across
# unrelated modules; keep this report visible without blocking CI.
continue-on-error: true
run: npm run lint
- name: npm audit
working-directory: backend
run: npm audit --audit-level=critical
continue-on-error: true
backend-test:
name: Backend tests
needs: changes
if: ${{ needs.changes.outputs.backend == 'true' || needs.changes.outputs.shared == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Setup Node.js
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: 20
cache: npm
cache-dependency-path: backend/package-lock.json
- name: Install dependencies
working-directory: backend
run: npm ci
- name: Run unit tests
working-directory: backend
run: npm test -- --passWithNoTests
# ─────────────────────────────────────────────────────────────────────
# Frontend CI
# ─────────────────────────────────────────────────────────────────────
frontend-lint:
name: Frontend lint
needs: changes
if: ${{ needs.changes.outputs.frontend == 'true' || needs.changes.outputs.shared == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Setup Node.js
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: 20
cache: npm
cache-dependency-path: frontend/package-lock.json
- name: Install dependencies
working-directory: frontend
run: npm ci
- name: Lint
working-directory: frontend
run: npm run lint
- name: npm audit
working-directory: frontend
run: npm audit --audit-level=critical
continue-on-error: true
run: npm audit --audit-level=high
frontend-build:
name: Frontend build
needs: changes
if: ${{ needs.changes.outputs.frontend == 'true' || needs.changes.outputs.shared == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Setup Node.js
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: 20
cache: npm
cache-dependency-path: frontend/package-lock.json
- name: Install dependencies
working-directory: frontend
run: npm ci
- name: Build
working-directory: frontend
run: npm run build
frontend-smoke-test:
name: Frontend production smoke test
needs: [changes, frontend-build]
if: ${{ needs.changes.outputs.frontend == 'true' || needs.changes.outputs.shared == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Setup Node.js
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: 20
cache: npm
cache-dependency-path: frontend/package-lock.json
- name: Install dependencies
working-directory: frontend
run: npm ci
- name: Build production bundle
working-directory: frontend
run: npm run build
- name: Start production server
working-directory: frontend
run: |
npm run start -- --hostname 127.0.0.1 --port 3000 > /tmp/stellarhunts-frontend.log 2>&1 &
echo $! > /tmp/stellarhunts-frontend.pid
for i in $(seq 1 30); do
if curl -fsS http://127.0.0.1:3000 >/dev/null; then
exit 0
fi
sleep 2
done
cat /tmp/stellarhunts-frontend.log
exit 1
- name: Stop production server
if: always()
run: |
if [ -f /tmp/stellarhunts-frontend.pid ]; then
kill "$(cat /tmp/stellarhunts-frontend.pid)" || true
fi
frontend-test:
name: Frontend tests
needs: changes
if: ${{ needs.changes.outputs.frontend == 'true' || needs.changes.outputs.shared == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Setup Node.js
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: 20
cache: npm
cache-dependency-path: frontend/package-lock.json
- name: Install dependencies
working-directory: frontend
run: npm ci
- name: Run unit tests
working-directory: frontend
run: npm test