-
Notifications
You must be signed in to change notification settings - Fork 103
579 lines (500 loc) · 19.2 KB
/
Copy pathci.yml
File metadata and controls
579 lines (500 loc) · 19.2 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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
name: CI/CD Pipeline
on:
push:
branches: [main, dev, develop, 'feature/*']
pull_request:
branches: [main, dev, develop, 'feature/*']
env:
NODE_VERSION: '20'
RUST_VERSION: '1.88'
jobs:
commitlint:
name: Conventional Commit Check
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Cache node modules
uses: actions/cache@v4
id: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-node-${{ env.NODE_VERSION }}-${{ hashFiles('package-lock.json') }}
- name: Install dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci --legacy-peer-deps
- name: Validate PR commits
run: npx commitlint --from=origin/${{ github.event.pull_request.base.ref }} --to=HEAD --verbose
# ─────────────────────────────────────────────────────────
# TypeScript / React Native Checks
# ─────────────────────────────────────────────────────────
typescript-lint:
name: TypeScript Lint & Format
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Cache node modules
uses: actions/cache@v4
id: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-node-${{ env.NODE_VERSION }}-${{ hashFiles('package-lock.json') }}
- name: Install dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci --legacy-peer-deps
- name: Check formatting (Prettier)
id: prettier-check
run: npm run format:check
continue-on-error: true
- name: Auto-fix formatting issues
if: steps.prettier-check.outcome == 'failure'
run: |
echo "Formatting inconsistencies detected. Executing auto-fixer..."
npm run format:write || npx prettier --write "src/**/*.{ts,tsx,js,json,md}"
- name: Commit and Push formatting fixes
if: steps.prettier-check.outcome == 'failure'
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: 'chore: automated code formatting fixes via CI pipeline'
commit_user_name: 'github-actions[bot]'
commit_user_email: 'github-actions[bot]@users.noreply.github.com'
- name: Enforce strict layout check
if: steps.prettier-check.outcome == 'failure'
run: |
echo "❌ Code styles were inconsistent. Automated modifications have been pushed to your branch."
echo "Please pull latest changes locally or wait for the subsequent workflow run execution pass."
exit 1
- name: Run ESLint
run: npm run lint
npm-audit:
name: NPM Audit (High/Critical)
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci --legacy-peer-deps
- name: Run NPM Audit
run: npx audit-ci --config audit-ci.json
typescript-typecheck:
name: TypeScript Type Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Cache node modules
uses: actions/cache@v4
id: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-node-${{ env.NODE_VERSION }}-${{ hashFiles('package-lock.json') }}
- name: Install dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci --legacy-peer-deps
- name: EVM ABI TypeChain (must match committed output)
run: npm run contracts:codegen:check
- name: Run TypeScript type check
run: npx tsc --noEmit
- name: Validate performance budgets
run: npm run performance:ci
typescript-tests:
name: TypeScript Tests (Sharded)
runs-on: ubuntu-latest
strategy:
matrix:
shard: [1, 2, 3]
env:
SHARD: ${{ matrix.shard }}
SHARD_COUNT: 3
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Cache node modules
uses: actions/cache@v4
id: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-node-${{ env.NODE_VERSION }}-${{ hashFiles('package-lock.json') }}
- name: Install dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci --legacy-peer-deps
- name: Run sharded tests with coverage
run: |
echo "Running shard $SHARD of $SHARD_COUNT"
npm run test:shard
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-report-${{ matrix.shard }}
path: coverage/lcov.info
typescript-build:
name: TypeScript Build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Cache node modules
uses: actions/cache@v4
id: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-node-${{ env.NODE_VERSION }}-${{ hashFiles('package-lock.json') }}
- name: Cache Expo build cache
uses: actions/cache@v4
with:
path: |
.expo
node_modules/.cache/expo
key: ${{ runner.os }}-expo-${{ hashFiles('package.json', 'app.json') }}
restore-keys: |
${{ runner.os }}-expo-
- name: Install dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci --legacy-peer-deps
- name: Patch metro exports for @expo/cli compatibility
run: |
node -e "
const fs=require('fs');
const p='node_modules/metro/package.json';
if(!fs.existsSync(p)) process.exit(0);
const m=JSON.parse(fs.readFileSync(p,'utf8'));
if(!m.exports||m.exports['./src/lib/TerminalReporter']) process.exit(0);
m.exports['./src/lib/TerminalReporter']='./src/lib/TerminalReporter.js';
fs.writeFileSync(p,JSON.stringify(m,null,2));
console.log('Patched metro exports to add ./src/lib/TerminalReporter');
"
- name: Run Expo export
run: npm run build
env:
EXPO_NO_TELEMETRY: 1
sonarcloud:
name: SonarCloud Analysis
runs-on: ubuntu-latest
needs: [typescript-tests]
if: github.event_name == 'pull_request' || github.ref == 'refs/heads/main'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download coverage report
uses: actions/download-artifact@v4
with:
name: coverage-report
path: coverage
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# ─────────────────────────────────────────────────────────
# Rust / Soroban Smart Contract Checks
# ─────────────────────────────────────────────────────────
rust-format:
name: Rust Format Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_VERSION }}
components: rustfmt
- name: Check Rust formatting
run: cd contracts && cargo fmt --check
rust-clippy:
name: Rust Clippy Lint
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_VERSION }}
components: clippy
- name: Cache Rust dependencies and target
uses: actions/cache@v4
with:
path: |
~/cargo/registry/index/
~/cargo/registry/cache/
~/cargo/git/db/
contracts/target/
key: ${{ runner.os }}-cargo-${{ env.RUST_VERSION }}-${{ hashFiles('contracts/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-${{ env.RUST_VERSION }}-
- name: Run Clippy
working-directory: ./contracts
run: cargo clippy --all-targets -- -D warnings
rust-tests:
name: Rust Tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_VERSION }}
- name: Cache Rust dependencies and target
uses: actions/cache@v4
with:
path: |
~/cargo/registry/index/
~/cargo/registry/cache/
~/cargo/git/db/
contracts/target/
key: ${{ runner.os }}-cargo-${{ env.RUST_VERSION }}-${{ hashFiles('contracts/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-${{ env.RUST_VERSION }}-
- name: Run Rust tests
working-directory: ./contracts
run: cargo test --verbose
rust-build:
name: Rust Build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_VERSION }}
- name: Cache Rust dependencies and target
uses: actions/cache@v4
with:
path: |
~/cargo/registry/index/
~/cargo/registry/cache/
~/cargo/git/db/
contracts/target/
key: ${{ runner.os }}-cargo-${{ env.RUST_VERSION }}-${{ hashFiles('contracts/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-${{ env.RUST_VERSION }}-
- name: Build Rust contracts
working-directory: ./contracts
run: cargo build --release
# ─────────────────────────────────────────────────────────
# Load Testing
# ─────────────────────────────────────────────────────────
load-test:
name: k6 Load Test
runs-on: ubuntu-latest
continue-on-error: true
strategy:
fail-fast: false
matrix:
scenario: [subscription, billing, contract]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Prepare reports directory
run: mkdir -p load-tests/reports
- name: Install k6
run: |
sudo gpg -k
sudo gpg --no-default-keyring --keyring /usr/share/keyrings/k6-archive-keyring.gpg \
--keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D69
echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" \
| sudo tee /etc/apt/sources.list.d/k6.list
sudo apt-get update
sudo apt-get install -y k6
- name: Run k6 Load Test (${{ matrix.scenario }})
run: k6 run load-tests/run.js --env SCENARIO=${{ matrix.scenario }} --quiet
- name: Rename report for this scenario
if: always()
run: |
for ext in json md html; do
if [ -f "load-tests/reports/summary.$ext" ]; then
mv "load-tests/reports/summary.$ext" "load-tests/reports/${{ matrix.scenario }}.$ext"
fi
done
- name: Upload load test report
if: always()
uses: actions/upload-artifact@v4
with:
name: load-test-report-${{ matrix.scenario }}
path: load-tests/reports/
if-no-files-found: ignore
# ─────────────────────────────────────────────────────────
# Bundle Size Monitoring
# ─────────────────────────────────────────────────────────
bundle-size:
name: Bundle Size Check
runs-on: ubuntu-latest
env:
EXPO_NO_TELEMETRY: 1
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci --legacy-peer-deps
- name: Patch metro exports for @expo/cli compatibility
run: |
node -e "
const fs=require('fs');
const p='node_modules/metro/package.json';
if(!fs.existsSync(p)) process.exit(0);
const m=JSON.parse(fs.readFileSync(p,'utf8'));
if(!m.exports||m.exports['./src/lib/TerminalReporter']) process.exit(0);
m.exports['./src/lib/TerminalReporter']='./src/lib/TerminalReporter.js';
fs.writeFileSync(p,JSON.stringify(m,null,2));
console.log('Patched metro exports to add ./src/lib/TerminalReporter');
"
- name: Check bundle size (PR)
if: github.event_name == 'pull_request'
run: npx size-limit
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build app
if: github.event_name != 'pull_request'
run: npm run build
- name: Check bundle size (Push)
if: github.event_name != 'pull_request'
run: npx size-limit --json > bundle-size-report.json
- name: Upload bundle size report
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
uses: actions/upload-artifact@v4
with:
name: bundle-size-report-${{ github.sha }}
path: bundle-size-report.json
# ─────────────────────────────────────────────────────────
# Performance Monitoring
# ─────────────────────────────────────────────────────────
performance:
name: Performance Budget Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Cache node modules
uses: actions/cache@v4
id: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-node-${{ env.NODE_VERSION }}-${{ hashFiles('package-lock.json') }}
- name: Install dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci --legacy-peer-deps
- name: Run performance benchmark
run: npm run performance:benchmark
# ─────────────────────────────────────────────────────────
# Merge Protection (only on PRs)
# ─────────────────────────────────────────────────────────
merge-protection:
name: Merge Protection Check
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
needs:
[
commitlint,
typescript-lint,
typescript-typecheck,
typescript-tests,
typescript-build,
sonarcloud,
rust-format,
rust-clippy,
rust-tests,
rust-build,
load-test,
bundle-size,
performance,
]
steps:
- name: All checks passed
run: echo "All quality gates passed!"
# ─────────────────────────────────────────────────────────
# Full CI Summary (runs after all jobs)
# ─────────────────────────────────────────────────────────
ci-success:
name: CI Complete
runs-on: ubuntu-latest
if: always()
needs:
[
commitlint,
typescript-lint,
typescript-typecheck,
typescript-tests,
typescript-build,
sonarcloud,
rust-format,
rust-clippy,
rust-tests,
rust-build,
load-test,
bundle-size,
performance,
]
steps:
- name: Check for failures
run: |
if [ "${{ github.event_name }}" = "pull_request" ] && [ "${{ needs.commitlint.result }}" != "success" ]; then
echo "Conventional commit check failed"
exit 1
fi
if [ "${{ needs.typescript-lint.result }}" != "success" ] || \
[ "${{ needs.typescript-typecheck.result }}" != "success" ] || \
[ "${{ needs.typescript-tests.result }}" != "success" ] || \
[ "${{ needs.typescript-build.result }}" != "success" ] || \
[ "${{ needs.sonarcloud.result }}" != "success" ] || \
[ "${{ needs.rust-format.result }}" != "success" ] || \
[ "${{ needs.rust-clippy.result }}" != "success" ] || \
[ "${{ needs.rust-tests.result }}" != "success" ] || \
[ "${{ needs.rust-build.result }}" != "success" ] || \
[ "${{ needs.load-test.result }}" != "success" ] || \
[ "${{ needs.bundle-size.result }}" != "success" ] || \
[ "${{ needs.performance.result }}" != "success" ]; then
echo "One or more CI checks failed"
exit 1
fi
echo "All CI checks passed successfully!"