-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
453 lines (385 loc) · 13.8 KB
/
Copy pathpr.yml
File metadata and controls
453 lines (385 loc) · 13.8 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
name: PR Checks
on:
pull_request:
types: [opened, synchronize, reopened]
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
changes:
name: Detect Changes
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
outputs:
web: ${{ steps.filter.outputs.web }}
configs: ${{ steps.filter.outputs.configs }}
workflows: ${{ steps.filter.outputs.workflows }}
e2e: ${{ steps.filter.outputs.e2e }}
rules: ${{ steps.filter.outputs.rules }}
guides: ${{ steps.filter.outputs.guides }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v2
id: filter
with:
filters: |
web:
- 'apps/web/**'
- 'packages/**'
- 'configs/**'
configs:
- 'configs/**'
- '*.json'
- '*.yaml'
- '*.yml'
workflows:
- '.github/workflows/**'
e2e:
- 'apps/web/e2e/**'
- 'apps/web/playwright.config.ts'
rules:
- 'packages/content/rules/en/**/*.mdx'
guides:
- 'packages/content/guides/en/**/*.mdx'
quick-checks:
name: Quick Checks
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.33.0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Check commit messages
run: |
# Check if commits follow conventional commits
pnpm add -g @commitlint/cli @commitlint/config-conventional
echo "module.exports = {extends: ['@commitlint/config-conventional']}" > commitlint.config.js
git log --format=%s origin/${{ github.base_ref }}..HEAD | while read line; do
echo "$line" | commitlint || true
done
- name: Check for console.logs
run: |
if grep -r "console.log" apps/web/app apps/web/components apps/web/hooks apps/web/lib apps/web/providers apps/web/scripts apps/web/test-utils apps/web/utils apps/web/proxy.ts --exclude-dir=__tests__ --exclude-dir=e2e; then
echo "::warning::Found console.log statements in source code"
fi
- name: Check for TODO comments
run: |
if grep -r "TODO\|FIXME\|HACK" apps/web/app apps/web/components apps/web/hooks apps/web/lib apps/web/providers apps/web/scripts apps/web/test-utils apps/web/utils apps/web/proxy.ts; then
echo "::warning::Found TODO/FIXME/HACK comments in source code"
fi
lint-and-format:
name: Lint & Format
runs-on: ubuntu-latest
needs: changes
if: needs.changes.outputs.web == 'true' || needs.changes.outputs.configs == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.33.0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Run Biome checks
run: |
pnpm biome check --no-errors-on-unmatched .
pnpm run lint --filter=web
- name: Check for formatting issues
run: |
pnpm biome format . --check
if [ $? -ne 0 ]; then
echo "::error::Formatting issues found. Please run 'pnpm biome format . --write' locally"
exit 1
fi
type-safety:
name: Type Safety
runs-on: ubuntu-latest
needs: changes
if: needs.changes.outputs.web == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.33.0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build content collections
run: pnpm --filter web build:content
- name: TypeScript check
run: pnpm run typecheck --filter=web
- name: Check for any type usage
run: |
if grep -r ": any" apps/web/app apps/web/components apps/web/hooks apps/web/lib apps/web/providers apps/web/utils apps/web/test-utils apps/web/proxy.ts --exclude-dir=__tests__ --exclude-dir=e2e; then
echo "::warning::Found 'any' type usage in TypeScript files"
fi
test-coverage:
name: Test Coverage
runs-on: ubuntu-latest
needs: changes
if: needs.changes.outputs.web == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.33.0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build content collections
run: pnpm --filter web build:content
- name: Run tests with coverage
working-directory: ./apps/web
run: pnpm run test:ci
- name: Check coverage thresholds
working-directory: ./apps/web
run: pnpm run test:coverage:check
- name: Comment coverage on PR
uses: actions/github-script@v7
if: always()
with:
script: |
const fs = require('fs');
const coverage = fs.readFileSync('./apps/web/coverage/coverage-summary.json', 'utf8');
const coverageData = JSON.parse(coverage);
const total = coverageData.total;
const comment = `## 📊 Coverage Report
| Type | Coverage | Threshold |
|------|----------|-----------|
| Statements | ${total.statements.pct}% | 80% |
| Branches | ${total.branches.pct}% | 70% |
| Functions | ${total.functions.pct}% | 80% |
| Lines | ${total.lines.pct}% | 80% |
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
rule-structure:
name: Rule Structure
runs-on: ubuntu-latest
needs: changes
if: needs.changes.outputs.rules == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.33.0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Validate changed rule files
run: |
git fetch origin ${{ github.base_ref }} --depth=1
FILES=$(git diff --name-only --diff-filter=ACMRT origin/${{ github.base_ref }}...HEAD | grep '^packages/content/rules/en/.*\.mdx$' || true)
if [ -z "$FILES" ]; then
echo "No changed rule files to validate."
exit 0
fi
pnpm validate:rule-structure $FILES
guide-validation:
name: Guide Validation
runs-on: ubuntu-latest
needs: changes
if: needs.changes.outputs.guides == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.33.0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Validate changed guide files
run: |
git fetch origin ${{ github.base_ref }} --depth=1
FILES=$(git diff --name-only --diff-filter=ACMRT origin/${{ github.base_ref }}...HEAD | grep '^packages/content/guides/en/.*\.mdx$' || true)
if [ -z "$FILES" ]; then
echo "No changed guide files to validate."
exit 0
fi
pnpm validate:guide-structure $FILES
pnpm validate:guides $FILES
e2e-smoke:
name: E2E Smoke Tests
runs-on: ubuntu-latest
needs: changes
if: needs.changes.outputs.web == 'true' || needs.changes.outputs.e2e == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.33.0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Install Playwright
working-directory: ./apps/web
run: pnpm exec playwright install --with-deps chromium
- name: Build app
run: pnpm run build --filter=web
- name: Run smoke tests
working-directory: ./apps/web
run: |
pnpm run e2e \
--project=chromium \
--grep="@smoke" \
--reporter=github
env:
CI: true
- name: Upload failed test artifacts
if: failure()
uses: actions/upload-artifact@v4
with:
name: e2e-smoke-artifacts
path: |
apps/web/test-results/
apps/web/playwright-report/
retention-days: 3
bundle-analysis:
name: Bundle Analysis
runs-on: ubuntu-latest
needs: changes
if: needs.changes.outputs.web == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.33.0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build and analyze bundle
run: |
ANALYZE=true pnpm run build --filter=web
- name: Check bundle size
run: |
# Get JS bundle sizes
find apps/web/.next -name "*.js" -not -path "*/cache/*" -exec du -b {} + | \
awk '{total+=$1} END {print "Total JS bundle size: " total/1024/1024 " MB"}'
# Fail if bundle is too large (e.g., > 1MB)
total=$(find apps/web/.next -name "*.js" -not -path "*/cache/*" -exec du -b {} + | \
awk '{total+=$1} END {print total}')
if [ "$total" -gt 1048576 ]; then
echo "::warning::Bundle size exceeds 1MB threshold"
fi
pr-summary:
name: PR Summary
runs-on: ubuntu-latest
needs: [quick-checks, lint-and-format, type-safety, test-coverage, rule-structure, guide-validation, e2e-smoke]
if: always()
steps:
- name: Generate PR comment
uses: actions/github-script@v7
with:
script: |
const jobs = [
{ name: 'Quick Checks', status: '${{ needs.quick-checks.result }}' },
{ name: 'Lint & Format', status: '${{ needs.lint-and-format.result }}' },
{ name: 'Type Safety', status: '${{ needs.type-safety.result }}' },
{ name: 'Test Coverage', status: '${{ needs.test-coverage.result }}' },
{ name: 'Rule Structure', status: '${{ needs.rule-structure.result }}' },
{ name: 'Guide Validation', status: '${{ needs.guide-validation.result }}' },
{ name: 'E2E Smoke Tests', status: '${{ needs.e2e-smoke.result }}' }
];
const getEmoji = (status) => {
switch(status) {
case 'success': return '✅';
case 'failure': return '❌';
case 'skipped': return '⏭️';
default: return '⏳';
}
};
const summary = `## PR Check Summary
| Check | Status |
|-------|--------|
${jobs.map(job => `| ${job.name} | ${getEmoji(job.status)} ${job.status} |`).join('\n')}
${jobs.some(j => j.status === 'failure') ?
'⚠️ **Some checks failed. Please review the errors above.**' :
'✅ **All checks passed!**'}
`;
// Find and update existing comment or create new one
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' && comment.body.includes('PR Check Summary')
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: summary
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: summary
});
}