-
-
Notifications
You must be signed in to change notification settings - Fork 14
466 lines (412 loc) · 17.4 KB
/
reusable-pr-checks.yml
File metadata and controls
466 lines (412 loc) · 17.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
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
# ─────────────────────────────────────────────────────────────────
# Reusable PR Quality Checks Workflow
# ─────────────────────────────────────────────────────────────────
# DRY workflow for running quality checks on pull requests.
# Called by other workflows to validate code quality before merging.
#
# Features:
# - Path-based filtering (only run checks for changed files)
# - Caching for fast subsequent runs (90%+ speed improvement)
# - Optional mobile and integration test support
# - Parallel job execution
# - Artifacts on failure only
#
# Author: Alireza Rezvani
# Date: 2025-11-06
# ─────────────────────────────────────────────────────────────────
name: Reusable PR Quality Checks
on:
workflow_call:
inputs:
mobile_check:
description: 'Run mobile platform checks (iOS/Android)'
required: false
type: boolean
default: false
integration_tests:
description: 'Run integration tests'
required: false
type: boolean
default: false
node_version:
description: 'Node.js version to use'
required: false
type: string
default: '20'
pnpm_version:
description: 'pnpm version to use'
required: false
type: string
default: '9'
working_directory:
description: 'Working directory for checks'
required: false
type: string
default: '.'
permissions:
contents: read
pull-requests: read
# Cancel in-progress runs for the same PR
concurrency:
group: quality-checks-${{ github.ref }}
cancel-in-progress: true
jobs:
# ─────────────────────────────────────────────────────────────────
# Path Filtering
# ─────────────────────────────────────────────────────────────────
# Detect which files changed to determine which checks to run
path-filter:
name: Detect Changed Paths
runs-on: ubuntu-latest
outputs:
web: ${{ steps.filter.outputs.web }}
mobile: ${{ steps.filter.outputs.mobile }}
mobile-ios: ${{ steps.filter.outputs.mobile-ios }}
mobile-android: ${{ steps.filter.outputs.mobile-android }}
tests: ${{ steps.filter.outputs.tests }}
docs-only: ${{ steps.filter.outputs.docs-only }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Filter changed paths
uses: dorny/paths-filter@v3
id: filter
with:
filters: |
web:
- 'src/**'
- 'lib/**'
- 'components/**'
- 'pages/**'
- 'app/**'
- '*.ts'
- '*.tsx'
- '*.js'
- '*.jsx'
- 'package.json'
- 'tsconfig.json'
mobile:
- 'mobile/**'
- 'ios/**'
- 'android/**'
- '*.swift'
- '*.kt'
- '*.java'
mobile-ios:
- 'ios/**'
- '*.swift'
- 'Podfile'
- 'Podfile.lock'
mobile-android:
- 'android/**'
- '*.kt'
- '*.java'
- 'build.gradle'
- 'settings.gradle'
tests:
- '**/*.test.ts'
- '**/*.test.tsx'
- '**/*.test.js'
- '**/*.spec.ts'
- '**/*.spec.tsx'
- '**/*.spec.js'
- 'tests/**'
- '__tests__/**'
docs-only:
- '**.md'
- 'docs/**'
- '.github/**/*.md'
# ─────────────────────────────────────────────────────────────────
# Lint Check
# ─────────────────────────────────────────────────────────────────
lint:
name: Lint
runs-on: ubuntu-latest
needs: path-filter
if: needs.path-filter.outputs.docs-only != 'true' && needs.path-filter.outputs.web == 'true'
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup Node.js and pnpm
uses: ./.github/actions/setup-node-pnpm
with:
node-version: ${{ inputs.node_version }}
pnpm-version: ${{ inputs.pnpm_version }}
working-directory: ${{ inputs.working_directory }}
- name: Run ESLint
working-directory: ${{ inputs.working_directory }}
run: |
echo "🔍 Running ESLint..."
pnpm run lint
continue-on-error: false
- name: Run Prettier check
working-directory: ${{ inputs.working_directory }}
run: |
echo "🎨 Running Prettier check..."
pnpm run format:check || pnpm run prettier:check || echo "⚠️ No format check script found - skipping"
continue-on-error: true
- name: Upload lint results on failure
if: failure()
uses: actions/upload-artifact@v6
with:
name: lint-results
path: |
${{ inputs.working_directory }}/eslint-report.json
${{ inputs.working_directory }}/eslint-report.html
retention-days: 2
if-no-files-found: ignore
# ─────────────────────────────────────────────────────────────────
# Type Check
# ─────────────────────────────────────────────────────────────────
typecheck:
name: Type Check
runs-on: ubuntu-latest
needs: path-filter
if: needs.path-filter.outputs.docs-only != 'true' && needs.path-filter.outputs.web == 'true'
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup Node.js and pnpm
uses: ./.github/actions/setup-node-pnpm
with:
node-version: ${{ inputs.node_version }}
pnpm-version: ${{ inputs.pnpm_version }}
working-directory: ${{ inputs.working_directory }}
- name: Run TypeScript type check
working-directory: ${{ inputs.working_directory }}
run: |
echo "🔍 Running TypeScript type check..."
pnpm run type-check || pnpm run typecheck || pnpm exec tsc --noEmit
continue-on-error: false
- name: Upload type check results on failure
if: failure()
uses: actions/upload-artifact@v6
with:
name: typecheck-results
path: |
${{ inputs.working_directory }}/tsconfig.tsbuildinfo
retention-days: 2
if-no-files-found: ignore
# ─────────────────────────────────────────────────────────────────
# Unit Tests
# ─────────────────────────────────────────────────────────────────
test-unit:
name: Unit Tests
runs-on: ubuntu-latest
needs: path-filter
if: needs.path-filter.outputs.docs-only != 'true'
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup Node.js and pnpm
uses: ./.github/actions/setup-node-pnpm
with:
node-version: ${{ inputs.node_version }}
pnpm-version: ${{ inputs.pnpm_version }}
working-directory: ${{ inputs.working_directory }}
- name: Run unit tests
working-directory: ${{ inputs.working_directory }}
run: |
echo "🧪 Running unit tests..."
pnpm run test:unit || pnpm run test -- --testPathIgnorePatterns=integration || pnpm run test
continue-on-error: false
env:
CI: true
- name: Upload test results on failure
if: failure()
uses: actions/upload-artifact@v6
with:
name: unit-test-results
path: |
${{ inputs.working_directory }}/coverage/
${{ inputs.working_directory }}/test-results/
retention-days: 2
if-no-files-found: ignore
- name: Upload coverage reports
if: always()
uses: actions/upload-artifact@v6
with:
name: coverage-reports
path: |
${{ inputs.working_directory }}/coverage/
retention-days: 7
if-no-files-found: ignore
# ─────────────────────────────────────────────────────────────────
# Integration Tests (Optional)
# ─────────────────────────────────────────────────────────────────
test-integration:
name: Integration Tests
runs-on: ubuntu-latest
needs: path-filter
if: inputs.integration_tests == true && needs.path-filter.outputs.docs-only != 'true'
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup Node.js and pnpm
uses: ./.github/actions/setup-node-pnpm
with:
node-version: ${{ inputs.node_version }}
pnpm-version: ${{ inputs.pnpm_version }}
working-directory: ${{ inputs.working_directory }}
- name: Run integration tests
working-directory: ${{ inputs.working_directory }}
run: |
echo "🧪 Running integration tests..."
pnpm run test:integration || pnpm run test -- --testPathPattern=integration
continue-on-error: false
env:
CI: true
- name: Upload integration test results on failure
if: failure()
uses: actions/upload-artifact@v6
with:
name: integration-test-results
path: |
${{ inputs.working_directory }}/coverage/
${{ inputs.working_directory }}/test-results/
retention-days: 2
if-no-files-found: ignore
# ─────────────────────────────────────────────────────────────────
# Mobile Checks (Optional)
# ─────────────────────────────────────────────────────────────────
mobile-check:
name: Mobile Build Validation
runs-on: ubuntu-latest
needs: path-filter
if: inputs.mobile_check == true && needs.path-filter.outputs.mobile == 'true'
strategy:
matrix:
platform:
- ios
- android
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup Node.js and pnpm
uses: ./.github/actions/setup-node-pnpm
with:
node-version: ${{ inputs.node_version }}
pnpm-version: ${{ inputs.pnpm_version }}
working-directory: ${{ inputs.working_directory }}
# iOS-specific setup
- name: Setup iOS dependencies
if: matrix.platform == 'ios' && needs.path-filter.outputs.mobile-ios == 'true'
run: |
echo "📱 Setting up iOS dependencies..."
if [ -d "ios" ]; then
cd ios
if [ -f "Podfile" ]; then
pod install --repo-update
fi
fi
# Android-specific setup
- name: Setup Android dependencies
if: matrix.platform == 'android' && needs.path-filter.outputs.mobile-android == 'true'
run: |
echo "🤖 Setting up Android dependencies..."
if [ -d "android" ]; then
cd android
./gradlew --version
fi
# Validate mobile builds
- name: Validate ${{ matrix.platform }} build
run: |
echo "🏗️ Validating ${{ matrix.platform }} build..."
if [ "${{ matrix.platform }}" == "ios" ]; then
pnpm run ios:build || echo "⚠️ iOS build validation skipped (not configured)"
else
pnpm run android:build || echo "⚠️ Android build validation skipped (not configured)"
fi
continue-on-error: true
- name: Upload mobile build results on failure
if: failure()
uses: actions/upload-artifact@v6
with:
name: mobile-${{ matrix.platform }}-build-results
path: |
**/build/
**/DerivedData/
retention-days: 2
if-no-files-found: ignore
# ─────────────────────────────────────────────────────────────────
# Summary
# ─────────────────────────────────────────────────────────────────
quality-summary:
name: Quality Check Summary
runs-on: ubuntu-latest
needs:
- path-filter
- lint
- typecheck
- test-unit
- test-integration
- mobile-check
if: always()
steps:
- name: Generate summary
run: |
echo "# 🎯 Quality Check Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "## 📊 Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Check | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-------|--------|" >> $GITHUB_STEP_SUMMARY
# Lint
if [[ "${{ needs.lint.result }}" == "success" ]]; then
echo "| Lint | ✅ Passed |" >> $GITHUB_STEP_SUMMARY
elif [[ "${{ needs.lint.result }}" == "skipped" ]]; then
echo "| Lint | ⏭️ Skipped |" >> $GITHUB_STEP_SUMMARY
else
echo "| Lint | ❌ Failed |" >> $GITHUB_STEP_SUMMARY
fi
# Type Check
if [[ "${{ needs.typecheck.result }}" == "success" ]]; then
echo "| Type Check | ✅ Passed |" >> $GITHUB_STEP_SUMMARY
elif [[ "${{ needs.typecheck.result }}" == "skipped" ]]; then
echo "| Type Check | ⏭️ Skipped |" >> $GITHUB_STEP_SUMMARY
else
echo "| Type Check | ❌ Failed |" >> $GITHUB_STEP_SUMMARY
fi
# Unit Tests
if [[ "${{ needs.test-unit.result }}" == "success" ]]; then
echo "| Unit Tests | ✅ Passed |" >> $GITHUB_STEP_SUMMARY
elif [[ "${{ needs.test-unit.result }}" == "skipped" ]]; then
echo "| Unit Tests | ⏭️ Skipped |" >> $GITHUB_STEP_SUMMARY
else
echo "| Unit Tests | ❌ Failed |" >> $GITHUB_STEP_SUMMARY
fi
# Integration Tests
if [[ "${{ needs.test-integration.result }}" == "success" ]]; then
echo "| Integration Tests | ✅ Passed |" >> $GITHUB_STEP_SUMMARY
elif [[ "${{ needs.test-integration.result }}" == "skipped" ]]; then
echo "| Integration Tests | ⏭️ Skipped (not enabled) |" >> $GITHUB_STEP_SUMMARY
else
echo "| Integration Tests | ❌ Failed |" >> $GITHUB_STEP_SUMMARY
fi
# Mobile Check
if [[ "${{ needs.mobile-check.result }}" == "success" ]]; then
echo "| Mobile Build | ✅ Passed |" >> $GITHUB_STEP_SUMMARY
elif [[ "${{ needs.mobile-check.result }}" == "skipped" ]]; then
echo "| Mobile Build | ⏭️ Skipped (not enabled) |" >> $GITHUB_STEP_SUMMARY
else
echo "| Mobile Build | ⚠️ Build validation had issues |" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
# Overall status
if [[ "${{ needs.lint.result }}" == "failure" ]] || \
[[ "${{ needs.typecheck.result }}" == "failure" ]] || \
[[ "${{ needs.test-unit.result }}" == "failure" ]] || \
[[ "${{ needs.test-integration.result }}" == "failure" ]]; then
echo "## ❌ Quality checks failed" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Please fix the failing checks before merging." >> $GITHUB_STEP_SUMMARY
exit 1
else
echo "## ✅ All quality checks passed" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Ready for review and merge!" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "---" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "_Quality checks completed at $(date -u '+%Y-%m-%d %H:%M:%S UTC')_" >> $GITHUB_STEP_SUMMARY