-
-
Notifications
You must be signed in to change notification settings - Fork 0
498 lines (428 loc) · 21.6 KB
/
reports.yml
File metadata and controls
498 lines (428 loc) · 21.6 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
name: Generate Reports and Deploy to GitHub Pages
on:
workflow_call:
inputs:
cleanup-previews:
description: Remove stale pull request previews without publishing production reports.
required: false
type: boolean
default: false
workflow_dispatch:
inputs:
cleanup-previews:
description: Remove stale pull request previews without publishing production reports.
required: false
type: boolean
default: false
schedule:
- cron: '41 3 * * *'
pull_request:
types: [ "opened", "synchronize", "reopened", "closed" ]
push:
branches: [ "main" ]
permissions:
contents: read
concurrency:
group: ${{ github.event_name == 'pull_request' && format('reports-preview-pr-{0}', github.event.pull_request.number) || 'reports-pages' }}
cancel-in-progress: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }}
env:
FORCE_COLOR: '1'
jobs:
resolve_php:
name: Resolve PHP Version
runs-on: ubuntu-latest
outputs:
php-version: ${{ steps.resolve.outputs.php-version }}
php-version-source: ${{ steps.resolve.outputs.php-version-source }}
steps:
- uses: actions/checkout@v6
- name: Checkout dev-tools workflow action source
uses: actions/checkout@v6
with:
repository: php-fast-forward/dev-tools
ref: ${{ github.repository == 'php-fast-forward/dev-tools' && (github.event_name == 'pull_request_target' && github.event.pull_request.base.sha || github.sha) || 'main' }}
path: .dev-tools-actions
sparse-checkout: |
.github/actions
- name: Resolve workflow PHP version
id: resolve
uses: ./.dev-tools-actions/.github/actions/php/resolve-version
reports:
needs: resolve_php
if: github.event_name != 'schedule' && !(github.event_name == 'workflow_dispatch' && inputs.cleanup-previews) && (github.event_name != 'pull_request' || github.event.action != 'closed')
name: Generate Reports
runs-on: ubuntu-latest
outputs:
any_generated: ${{ steps.detect_reports.outputs.any_generated }}
coverage_generated: ${{ steps.detect_reports.outputs.coverage_generated }}
docs_generated: ${{ steps.detect_reports.outputs.docs_generated }}
metrics_generated: ${{ steps.detect_reports.outputs.metrics_generated }}
permissions:
contents: write
env:
REPORTS_TARGET: .dev-tools
REPORTS_ROOT_VERSION: ${{ github.event_name == 'pull_request' && format('dev-{0}', github.event.pull_request.head.ref) || 'dev-main' }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Checkout dev-tools workflow action source
uses: actions/checkout@v6
with:
repository: php-fast-forward/dev-tools
ref: ${{ github.repository == 'php-fast-forward/dev-tools' && (github.event_name == 'pull_request_target' && github.event.pull_request.base.sha || github.sha) || 'main' }}
path: .dev-tools-actions
- name: Setup PHP and install dependencies
uses: ./.dev-tools-actions/.github/actions/php/setup-composer
with:
php-version: ${{ needs.resolve_php.outputs.php-version }}
extensions: pcov, pcntl
coverage: pcov
root-version: ${{ env.REPORTS_ROOT_VERSION }}
- name: Generate reports
env:
COMPOSER_ROOT_VERSION: ${{ env.REPORTS_ROOT_VERSION }}
run: dev-tools reports --target="${REPORTS_TARGET}" --coverage="${REPORTS_TARGET}/coverage" --metrics="${REPORTS_TARGET}/metrics"
- name: Fix permissions
run: |
chmod -c -R +rX "${REPORTS_TARGET}/" | while IFS= read -r line; do
echo "::warning title=Invalid file permissions automatically fixed::$line"
done
- name: Add .nojekyll
run: touch "${REPORTS_TARGET}/.nojekyll"
- name: Remove repository-local caches from published output
run: rm -rf "${REPORTS_TARGET}/cache"
- name: Detect generated report surfaces
id: detect_reports
run: |
docs_generated=false
coverage_generated=false
metrics_generated=false
if [ -f "${REPORTS_TARGET}/index.html" ]; then
docs_generated=true
fi
if [ -f "${REPORTS_TARGET}/coverage/index.html" ]; then
coverage_generated=true
fi
if [ -f "${REPORTS_TARGET}/metrics/index.html" ]; then
metrics_generated=true
fi
any_generated=false
if [ "$docs_generated" = 'true' ] || [ "$coverage_generated" = 'true' ] || [ "$metrics_generated" = 'true' ]; then
any_generated=true
fi
{
echo "docs_generated=$docs_generated"
echo "coverage_generated=$coverage_generated"
echo "metrics_generated=$metrics_generated"
echo "any_generated=$any_generated"
} >> "$GITHUB_OUTPUT"
- name: Restore previews from gh-pages
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
uses: actions/checkout@v6
continue-on-error: true
with:
ref: gh-pages
path: gh-pages-current
- name: Copy existing previews into publish directory
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
uses: ./.dev-tools-actions/.github/actions/github-pages/restore-previews
with:
source: gh-pages-current
target: ${{ env.REPORTS_TARGET }}
- name: Deploy main reports
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: gh-pages
publish_dir: ./${{ env.REPORTS_TARGET }}/
destination_dir: .
keep_files: false
force_orphan: false
- name: Deploy PR preview
if: github.event_name == 'pull_request'
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: gh-pages
publish_dir: ./${{ env.REPORTS_TARGET }}/
destination_dir: previews/pr-${{ github.event.pull_request.number }}
keep_files: false
force_orphan: false
verify_main_reports:
if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && !(github.event_name == 'workflow_dispatch' && inputs.cleanup-previews)
name: Verify Main Reports Deployment
needs: reports
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Checkout dev-tools workflow action source
uses: actions/checkout@v6
with:
repository: php-fast-forward/dev-tools
ref: ${{ github.repository == 'php-fast-forward/dev-tools' && (github.event_name == 'pull_request_target' && github.event.pull_request.base.sha || github.sha) || 'main' }}
path: .dev-tools-actions
sparse-checkout: |
.github/actions
- name: Build deployment checks
id: build_checks
env:
COVERAGE_GENERATED: ${{ needs.reports.outputs.coverage_generated }}
DOCS_GENERATED: ${{ needs.reports.outputs.docs_generated }}
METRICS_GENERATED: ${{ needs.reports.outputs.metrics_generated }}
run: |
has_checks=false
{
echo 'checks<<EOF'
if [ "${DOCS_GENERATED}" = 'true' ]; then
echo '/|Reports index'
has_checks=true
fi
if [ "${COVERAGE_GENERATED}" = 'true' ]; then
echo '/coverage/|Coverage report'
has_checks=true
fi
if [ "${METRICS_GENERATED}" = 'true' ]; then
echo '/metrics/|Metrics report'
has_checks=true
fi
echo 'EOF'
echo "has_checks=$has_checks"
} >> "$GITHUB_OUTPUT"
- uses: ./.dev-tools-actions/.github/actions/github-pages/verify-deployment
if: steps.build_checks.outputs.has_checks == 'true'
with:
base-url: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}
title: Reports health check failed
checks: ${{ steps.build_checks.outputs.checks }}
verify_preview_reports:
if: github.event_name == 'pull_request' && github.event.action != 'closed'
name: Verify Pull Request Reports Preview
needs: reports
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Checkout dev-tools workflow action source
uses: actions/checkout@v6
with:
repository: php-fast-forward/dev-tools
ref: ${{ github.repository == 'php-fast-forward/dev-tools' && (github.event_name == 'pull_request_target' && github.event.pull_request.base.sha || github.sha) || 'main' }}
path: .dev-tools-actions
sparse-checkout: |
.github/actions
- name: Build preview deployment checks
id: build_checks
env:
COVERAGE_GENERATED: ${{ needs.reports.outputs.coverage_generated }}
DOCS_GENERATED: ${{ needs.reports.outputs.docs_generated }}
METRICS_GENERATED: ${{ needs.reports.outputs.metrics_generated }}
run: |
has_checks=false
{
echo 'checks<<EOF'
if [ "${DOCS_GENERATED}" = 'true' ]; then
echo '/|Preview reports index'
has_checks=true
fi
if [ "${COVERAGE_GENERATED}" = 'true' ]; then
echo '/coverage/|Preview coverage report'
has_checks=true
fi
if [ "${METRICS_GENERATED}" = 'true' ]; then
echo '/metrics/|Preview metrics report'
has_checks=true
fi
echo 'EOF'
echo "has_checks=$has_checks"
} >> "$GITHUB_OUTPUT"
- uses: ./.dev-tools-actions/.github/actions/github-pages/verify-deployment
if: steps.build_checks.outputs.has_checks == 'true'
with:
base-url: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/previews/pr-${{ github.event.pull_request.number }}
title: Preview health check failed
checks: ${{ steps.build_checks.outputs.checks }}
comment_preview:
if: github.event_name == 'pull_request' && github.event.action != 'closed'
name: Comment Pull Request Preview URLs
needs:
- reports
- verify_preview_reports
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Build preview comment
id: build_comment
env:
COVERAGE_GENERATED: ${{ needs.reports.outputs.coverage_generated }}
DOCS_GENERATED: ${{ needs.reports.outputs.docs_generated }}
METRICS_GENERATED: ${{ needs.reports.outputs.metrics_generated }}
run: |
has_links=false
{
echo 'message<<EOF'
echo '🚀 Preview is available for this pull request.'
echo
if [ "${DOCS_GENERATED}" = 'true' ]; then
echo "- Docs: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/previews/pr-${{ github.event.pull_request.number }}/"
has_links=true
fi
if [ "${COVERAGE_GENERATED}" = 'true' ]; then
echo "- Coverage: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/previews/pr-${{ github.event.pull_request.number }}/coverage/"
has_links=true
fi
if [ "${METRICS_GENERATED}" = 'true' ]; then
echo "- Metrics: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/previews/pr-${{ github.event.pull_request.number }}/metrics/"
has_links=true
fi
echo 'EOF'
echo "has_links=$has_links"
} >> "$GITHUB_OUTPUT"
- name: Comment preview URLs on pull request
if: steps.build_comment.outputs.has_links == 'true'
uses: marocchino/sticky-pull-request-comment@v3
with:
header: pr-preview
message: ${{ steps.build_comment.outputs.message }}
cleanup_preview:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
name: Cleanup Pull Request Preview
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.repository.default_branch }}
- name: Checkout dev-tools workflow action source
uses: actions/checkout@v6
with:
repository: php-fast-forward/dev-tools
ref: ${{ github.repository == 'php-fast-forward/dev-tools' && (github.event_name == 'pull_request_target' && github.event.pull_request.base.sha || github.sha) || 'main' }}
path: .dev-tools-actions
sparse-checkout: |
.github/actions
- name: Checkout gh-pages
uses: actions/checkout@v6
with:
ref: gh-pages
path: gh-pages
- uses: ./.dev-tools-actions/.github/actions/github-pages/remove-preview
with:
path: gh-pages
pull-request-number: ${{ github.event.pull_request.number }}
- name: Push changes
run: |
cd gh-pages
git push
cleanup_orphaned_previews:
if: github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && inputs.cleanup-previews)
name: Cleanup Orphaned Pull Request Previews
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: read
outputs:
deleted: ${{ steps.cleanup.outputs.deleted }}
skipped: ${{ steps.cleanup.outputs.skipped }}
unresolved: ${{ steps.cleanup.outputs.unresolved }}
steps:
- uses: actions/checkout@v6
- name: Checkout dev-tools workflow action source
uses: actions/checkout@v6
with:
repository: php-fast-forward/dev-tools
ref: ${{ github.repository == 'php-fast-forward/dev-tools' && (github.event_name == 'pull_request_target' && github.event.pull_request.base.sha || github.sha) || 'main' }}
path: .dev-tools-actions
sparse-checkout: |
.github/actions
- name: Checkout gh-pages
uses: actions/checkout@v6
with:
ref: gh-pages
path: gh-pages
- uses: ./.dev-tools-actions/.github/actions/github-pages/cleanup-orphaned-previews
id: cleanup
with:
path: gh-pages
- name: Push changes
run: |
cd gh-pages
git push
summarize:
if: ${{ always() }}
name: Summarize Reports Workflow
needs:
- resolve_php
- reports
- verify_main_reports
- verify_preview_reports
- cleanup_preview
- cleanup_orphaned_previews
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Checkout dev-tools workflow action source
uses: actions/checkout@v6
with:
repository: php-fast-forward/dev-tools
ref: ${{ github.repository == 'php-fast-forward/dev-tools' && (github.event_name == 'pull_request_target' && github.event.pull_request.base.sha || github.sha) || 'main' }}
path: .dev-tools-actions
sparse-checkout: |
.github/actions
- id: build_summary
env:
COVERAGE_GENERATED: ${{ needs.reports.outputs.coverage_generated }}
DOCS_GENERATED: ${{ needs.reports.outputs.docs_generated }}
METRICS_GENERATED: ${{ needs.reports.outputs.metrics_generated }}
TRIGGER_LABEL: ${{ github.event_name }}${{ github.event.action && format(':{0}', github.event.action) || '' }}
run: |
{
echo 'markdown<<EOF'
echo '## Reports Workflow Summary'
echo
echo "- Workflow PHP version: \`${{ needs.resolve_php.outputs.php-version }}\`"
echo "- PHP version source: \`${{ needs.resolve_php.outputs.php-version-source }}\`"
echo "- Reports job result: \`${{ needs.reports.result }}\`"
echo "- Main verification result: \`${{ needs.verify_main_reports.result }}\`"
echo "- Preview verification result: \`${{ needs.verify_preview_reports.result }}\`"
echo "- Closed-preview cleanup result: \`${{ needs.cleanup_preview.result }}\`"
echo "- Orphan cleanup result: \`${{ needs.cleanup_orphaned_previews.result }}\`"
echo "- Trigger: \`${TRIGGER_LABEL}\`"
if [ "${{ github.event_name }}" = "push" ] || { [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ inputs.cleanup-previews }}" != "true" ]; }; then
if [ "${DOCS_GENERATED}" = 'true' ]; then
echo "- Docs: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/"
fi
if [ "${COVERAGE_GENERATED}" = 'true' ]; then
echo "- Coverage: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/coverage/"
fi
if [ "${METRICS_GENERATED}" = 'true' ]; then
echo "- Metrics: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/metrics/"
fi
echo "- Deployment verification: \`${{ needs.verify_main_reports.result }}\`"
fi
if [ "${{ github.event_name }}" = "pull_request" ] && [ "${{ github.event.action }}" != "closed" ]; then
if [ "${DOCS_GENERATED}" = 'true' ]; then
echo "- Preview docs: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/previews/pr-${{ github.event.pull_request.number }}/"
fi
if [ "${COVERAGE_GENERATED}" = 'true' ]; then
echo "- Preview coverage: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/previews/pr-${{ github.event.pull_request.number }}/coverage/"
fi
if [ "${METRICS_GENERATED}" = 'true' ]; then
echo "- Preview metrics: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/previews/pr-${{ github.event.pull_request.number }}/metrics/"
fi
echo "- Preview verification: \`${{ needs.verify_preview_reports.result }}\`"
fi
if [ "${{ github.event_name }}" = "pull_request" ] && [ "${{ github.event.action }}" = "closed" ]; then
echo "- Deleted preview path: \`previews/pr-${{ github.event.pull_request.number }}\`"
echo "- Cleanup result: \`${{ needs.cleanup_preview.result }}\`"
fi
if [ "${{ github.event_name }}" = "schedule" ] || { [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ inputs.cleanup-previews }}" = "true" ]; }; then
echo "- Cleanup summary: deleted=${{ needs.cleanup_orphaned_previews.outputs.deleted || '0' }}, skipped=${{ needs.cleanup_orphaned_previews.outputs.skipped || '0' }}, unresolved=${{ needs.cleanup_orphaned_previews.outputs.unresolved || '0' }}"
fi
echo 'EOF'
} >> "$GITHUB_OUTPUT"
- uses: ./.dev-tools-actions/.github/actions/summary/write
with:
markdown: ${{ steps.build_summary.outputs.markdown }}