Repository navigation
551 lines (488 loc) · 22.8 KB
/
Copy pathbuild.yml
File metadata and controls
551 lines (488 loc) · 22.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
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
name: build
on:
pull_request:
push:
branches:
- master
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
changes:
name: Relevant changes
runs-on: ubuntu-latest
outputs:
run: ${{ steps.filter.outputs.run }}
mutation: ${{ steps.filter.outputs.mutation }}
smoke: ${{ steps.filter.outputs.smoke }}
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
fetch-depth: 0
- name: Detect relevant changes
id: filter
env:
EVENT_NAME: ${{ github.event_name }}
BEFORE_SHA: ${{ github.event.before }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
run: |
if [ "$EVENT_NAME" = "pull_request" ]; then
BASE="$BASE_SHA"
elif [ "$BEFORE_SHA" = "0000000000000000000000000000000000000000" ]; then
# First push to a new branch: there is no base to diff against, so
# every filter says yes. Both outputs must be set here — an unset
# one reads as false downstream and silently skips its job.
echo "run=true" >> "$GITHUB_OUTPUT"
echo "mutation=true" >> "$GITHUB_OUTPUT"
echo "smoke=true" >> "$GITHUB_OUTPUT"
exit 0
else
BASE="$BEFORE_SHA"
fi
if git diff --quiet "$BASE" "$GITHUB_SHA" -- \
src tests config examples composer.json testo.php psalm.xml \
rector.php .php-cs-fixer.php infection.json5 \
.github/workflows/build.yml; then
echo "run=false" >> "$GITHUB_OUTPUT"
else
echo "run=true" >> "$GITHUB_OUTPUT"
fi
# Mutation is by far the most expensive job, so it gets a narrower
# filter than the rest: only what can change which mutants exist or
# which tests kill them. Style and static-analysis configs, examples
# and this workflow cannot. Explicit trade: editing the mutation STEP
# here no longer re-runs it — a break surfaces on the next source
# change or a manual re-run, which beats paying the full mutation run
# on every docs and CI edit.
if git diff --quiet "$BASE" "$GITHUB_SHA" -- \
src tests composer.json testo.php infection.json5; then
echo "mutation=false" >> "$GITHUB_OUTPUT"
else
echo "mutation=true" >> "$GITHUB_OUTPUT"
fi
# The consumer smoke installs a dist archive of this commit into a
# throwaway project, so what it can see changing is the distributed
# tree itself: the code, the manifest, the stubs it ships and the
# export-ignore list that decides what leaves the repository. Tests
# and analysis configs never reach a consumer.
if git diff --quiet "$BASE" "$GITHUB_SHA" -- \
src resources composer.json .gitattributes bin/consumer-smoke \
.github/workflows/build.yml; then
echo "smoke=false" >> "$GITHUB_OUTPUT"
else
echo "smoke=true" >> "$GITHUB_OUTPUT"
fi
# Not gated on 'changes' like the other jobs below: when a matrix job's own
# `if` is false, GitHub Actions skips it as ONE unit and posts a single
# check run named literally "PHP ${{ matrix.php }}" (the unexpanded
# template), never the per-version names ("PHP 8.3" etc.) that branch
# protection requires. Those required checks then sit in Pending forever
# and the PR is permanently unmergeable. Non-matrix jobs don't have this
# problem, so they stay gated.
build:
name: PHP ${{ matrix.php }}
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: false
matrix:
php:
- '8.3'
- '8.4'
- '8.5'
experimental: [false]
include:
# PHP 8.6 is not released yet: the job runs on the RC, is not a
# required check and cannot fail the workflow. composer.json still
# says "8.3 - 8.5", hence --ignore-platform-req=php+ below. It runs
# the tests only: php-cs-fixer refuses 8.6 and psalm crashes on the
# RC — style and static analysis are covered by 8.3–8.5. After GA:
# drop `experimental`, widen "php" to "8.3 - 8.6", run the full
# build and add "PHP 8.6" to templates/branch-protection.json.
- php: '8.6'
experimental: true
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- name: Setup PHP
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # v2
with:
php-version: ${{ matrix.php }}
coverage: none
extensions: json, mbstring
tools: composer:v2
- name: Cache Composer dependencies
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/.composer/cache
key: composer-${{ runner.os }}-${{ hashFiles('**/composer.json') }}
restore-keys: composer-${{ runner.os }}-
- name: Install dependencies
env:
PLATFORM_FLAGS: ${{ matrix.experimental && '--ignore-platform-req=php+' || '' }}
run: composer install --no-interaction --no-progress --prefer-dist $PLATFORM_FLAGS
- name: Build
env:
BUILD_SCRIPT: ${{ matrix.experimental && 'test' || 'build' }}
run: composer "$BUILD_SCRIPT"
prefer-lowest:
name: Prefer lowest
needs: changes
if: ${{ !cancelled() && (needs.changes.result != 'success' || needs.changes.outputs.run == 'true') }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- name: Setup PHP
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # v2
with:
php-version: '8.3'
coverage: none
extensions: json, mbstring
tools: composer:v2
- name: Cache Composer dependencies
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/.composer/cache
key: composer-${{ runner.os }}-${{ hashFiles('**/composer.json') }}
restore-keys: composer-${{ runner.os }}-
- name: Install dependencies
run: composer update --prefer-lowest --prefer-stable --no-interaction --no-progress
- name: Build
run: composer build
windows:
name: Windows
needs: changes
if: ${{ !cancelled() && (needs.changes.result != 'success' || needs.changes.outputs.run == 'true') }}
runs-on: windows-latest
# The same shape the other packages in the monorepo use. It earns its place
# here for a reason of its own: `Bypass\FileWrapper` stands in front of
# `file://`, and paths, separators and symlink privileges are where the two
# platforms disagree. Tests only — cs, psalm and rector answer the same on
# any OS.
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- name: Setup PHP
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # v2
with:
php-version: '8.4'
coverage: none
extensions: json, mbstring, tokenizer
tools: composer:v2
- name: Install dependencies
run: composer install --no-interaction --no-progress --prefer-dist
- name: Test
run: composer test
# The reason this job exists at all now lives in the Integration suite:
# `Bypass\FileWrapper` stands in front of `file://`, and paths,
# separators and symlink privileges are where the two platforms disagree.
# Running only `composer test` here would leave that unclaimed on Windows.
- name: Integration tests
run: composer test:integration
bypass:
name: Bypass acceptance
needs: changes
if: ${{ !cancelled() && (needs.changes.result != 'success' || needs.changes.outputs.run == 'true') }}
runs-on: ubuntu-latest
# Deliberately not a matrix. A matrix job skipped by its own `if:` reports
# one check under the raw name rather than the expanded ones, and a PR with
# those names in required checks then waits forever; the environments are
# cheap enough to walk inside one job instead.
#
# What it adds over `PHP 8.x`: those run without a coverage driver and with
# OPcache off for the CLI, which is exactly the configuration in which the
# wrapper has the least to trip over. Here it has both.
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- name: Setup PHP
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # v2
with:
php-version: '8.4'
coverage: pcov
extensions: json, mbstring, tokenizer
ini-values: opcache.enable_cli=1, phar.readonly=0
tools: composer:v2
- name: Install dependencies
run: composer install --no-interaction --no-progress --prefer-dist
- name: Confirm the drivers this job exists for are actually loaded
run: |
php -r 'exit(extension_loaded("pcov") ? 0 : 1);' \
|| { echo "pcov is missing: this job would pass without proving anything"; exit 1; }
php -r 'exit(extension_loaded("Zend OPcache") && ini_get("opcache.enable_cli") ? 0 : 1);' \
|| { echo "OPcache is off for the CLI: same problem"; exit 1; }
- name: Bypass scenarios under a coverage driver and a warm opcode cache
run: composer test:integration
# Composer resolves a class to a path out of a static map and includes it
# without stat'ing first, which is a different route to the same read.
# The wrapper has to be on it too, and the only way to say so is to run
# the suite with the autoloader actually in that mode.
- name: Re-run under an authoritative classmap
run: |
composer dump-autoload --classmap-authoritative --no-interaction
php -r 'require "vendor/autoload.php";
foreach (spl_autoload_functions() as $f) {
if (is_array($f) && $f[0] instanceof Composer\Autoload\ClassLoader && $f[0]->isClassMapAuthoritative()) {
exit(0);
}
}
fwrite(STDERR, "the autoloader is not authoritative: this step would prove nothing\n");
exit(1);'
composer test:integration
consumer-smoke:
name: Consumer smoke
needs: changes
if: ${{ !cancelled() && (needs.changes.result != 'success' || needs.changes.outputs.smoke == 'true') }}
runs-on: ubuntu-latest
# Everything else in this file runs the package inside its own checkout,
# with its dev dependencies present and its autoloader rooted here. None of
# that survives a `composer require`, and the one defect that reached users
# so far — a 116K spike directory in the 0.1.0 archive — was invisible to
# every job above by construction: they read the working tree, and a
# consumer downloads what `export-ignore` left.
#
# The core leg only. The adapter legs of the same script need the adapters,
# and each of them gates its own in its own repository; asking for them here
# would make an intentional core break unmergeable until the adapters are
# released, which cannot happen before the core is. The whole family from
# local checkouts at once is `bin/understudy-consumer-smoke` in the
# workspace repository, run before a release.
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
# The archive is made with `git archive HEAD`, and the version the
# path repository claims falls back to the latest tag when the
# CHANGELOG heading is still Unreleased.
fetch-depth: 0
- name: Install the engine from a dist archive and use it
run: bin/consumer-smoke --only=core
adapters:
name: Adapter contract suite (${{ matrix.adapter }})
# Keep this matrix unconditional. A matrix job skipped by its own `if:`
# reports one raw check name instead of the expanded names that branch
# protection requires, leaving each adapter context pending on docs-only
# changes. The four adapter suites are cheap compared with mutation.
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
adapter:
- testo
- psalm
- phpunit
- phpstan
steps:
- name: Checkout core
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
path: core
- name: Checkout adapter
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
repository: rasuvaeff/understudy-${{ matrix.adapter }}
persist-credentials: false
path: adapter
- name: Setup PHP
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # v2
with:
php-version: '8.4'
coverage: none
extensions: json, mbstring
tools: composer:v2
- name: Cache Composer dependencies
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/.composer/cache
key: composer-${{ runner.os }}-${{ hashFiles('**/composer.json') }}
restore-keys: composer-${{ runner.os }}-
- name: Point the adapter at this checkout of core
working-directory: adapter
run: |
composer config repositories.core '{"type":"path","url":"../core","options":{"versions":{"rasuvaeff/understudy":"1.0.0"}}}'
composer update --no-interaction --no-progress
- name: Verify core resolved to the path repository
working-directory: adapter
run: |
composer show rasuvaeff/understudy | tee /tmp/core-source.txt
grep -qE '^path +: +' /tmp/core-source.txt
- name: Adapter test suite
working-directory: adapter
run: composer test
coverage:
name: Coverage & Mutation
needs: changes
if: ${{ !cancelled() && (needs.changes.result != 'success' || needs.changes.outputs.mutation == 'true') }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- name: Setup PHP
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # v2
with:
php-version: '8.4'
coverage: pcov
extensions: json, mbstring
tools: composer:v2
- name: Cache Composer dependencies
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/.composer/cache
key: composer-${{ runner.os }}-${{ hashFiles('**/composer.json') }}
restore-keys: composer-${{ runner.os }}-
- name: Install dependencies
run: composer install --no-interaction --no-progress --prefer-dist
# restore and save are separate on purpose. The combined actions/cache
# declares post-if: success(), so its save never runs on a red job — and
# a red job is exactly what writes to PROPERTY_DB, because the property
# that just falsified is what produced the counterexample. Splitting them
# is what upstream recommends since save-always was deprecated.
- name: Restore property regression corpus
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: build/property-db
# run_attempt is part of the key because a re-run reuses run_id, and
# saving to an existing key is a warning that silently saves nothing.
key: property-db-${{ github.run_id }}-${{ github.run_attempt }}
restore-keys: property-db-
- name: Test with coverage
env:
PROPERTY_DB: ${{ github.workspace }}/build/property-db
run: composer test:coverage:ci
- name: Save property regression corpus
if: ${{ !cancelled() }}
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: build/property-db
key: property-db-${{ github.run_id }}-${{ github.run_attempt }}
- name: Mutation testing
run: composer mutation
compatibility:
name: Backward compatibility
needs: changes
if: ${{ !cancelled() && (needs.changes.result != 'success' || needs.changes.outputs.run == 'true') }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
fetch-depth: 0
- name: Setup PHP
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # v2
with:
php-version: '8.4'
coverage: none
extensions: json, mbstring, bcmath, intl
tools: composer:v2
- name: Cache Composer dependencies
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/.composer/cache
key: composer-${{ runner.os }}-${{ hashFiles('**/composer.json') }}
restore-keys: composer-${{ runner.os }}-
- name: Install dependencies
run: composer install --no-interaction --no-progress --prefer-dist
- name: Backward compatibility check
# Real breaks pass only across an intentional compatibility boundary:
# a higher major after 1.0, or a higher minor while the package is
# still below 1.0. The top version heading in CHANGELOG.md declares
# that boundary; patch releases stay gated on a clean report.
#
# A report made up ENTIRELY of "[BC] SKIPPED: ..." lines is also a
# pass: SKIPPED means roave/better-reflection could not statically
# parse a construct (observed for enum-case and `new Expr()` default
# values in promoted constructor properties) - it is not a detected
# break. Once a class contains this pattern, EVERY future run reports
# the identical SKIPPED finding against ANY --from tag, including a
# diff against itself, so gating on it would permanently block every
# subsequent PR regardless of content. A single genuine
# "[BC] CHANGED:"/"[BC] REMOVED:"/"[BC] ADDED:" line anywhere in the
# report still fails the build.
#
# A report made up ENTIRELY of return-type widenings from void is a
# pass when the top version heading in CHANGELOG.md is a MINOR above
# the latest tag and every named class is final: that is the widening
# the compatibility policy in README.md admits in a minor release.
# Roave's TypeIsCovariant hard-codes "nothing is covariant to void"
# from subclass-override semantics and does not look at finality, so
# it reports void -> int even where no subclass can exist and no
# caller could have read a return value that never was one (observed
# on verifyAll(): void -> int in the 1.1.0 line). Finality is not
# trusted from the finding's wording - it is reflected against this
# checkout - and any other finding in the same report still fails.
run: |
LATEST="$(git describe --tags --abbrev=0 2>/dev/null || true)"
if [ -z "$LATEST" ]; then
echo "No previous tag - skipping BC check"
exit 0
fi
CODE=0
OUTPUT="$(composer bc-check -- --from="$LATEST" --install-development-dependencies 2>&1)" || CODE=$?
printf '%s\n' "$OUTPUT"
if [ "$CODE" -eq 0 ]; then
exit 0
fi
NEXT="$(grep -m1 -oE '## [0-9]+\.[0-9]+\.[0-9]+' CHANGELOG.md | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)"
LATEST_VERSION="${LATEST#v}"
LATEST_MAJOR="${LATEST_VERSION%%.*}"
LATEST_MINOR="${LATEST_VERSION#*.}"; LATEST_MINOR="${LATEST_MINOR%%.*}"
NEXT_MAJOR="${NEXT%%.*}"
NEXT_MINOR="${NEXT#*.}"; NEXT_MINOR="${NEXT_MINOR%%.*}"
# Only code 3 means "breaks detected". Anything else is roave itself
# failing (128 when it cannot clone or resolve the old tag), and a
# crash must never be waved through by a CHANGELOG heading or a
# SKIPPED-only report.
if [ "$CODE" -eq 3 ] && [ -n "$NEXT_MAJOR" ] && {
[ "$NEXT_MAJOR" -gt "$LATEST_MAJOR" ] ||
{ [ "$LATEST_MAJOR" -eq 0 ] && [ "$NEXT_MAJOR" -eq 0 ] && [ "$NEXT_MINOR" -gt "$LATEST_MINOR" ]; }
}; then
echo "CHANGELOG declares $NEXT - an intentional compatibility boundary over $LATEST; BC breaks are expected, treating as pass."
exit 0
fi
if [ "$CODE" -eq 3 ]; then
TOTAL="$(printf '%s\n' "$OUTPUT" | { grep -cE '^\[BC\] ' || true; })"
SKIPPED="$(printf '%s\n' "$OUTPUT" | { grep -cE '^\[BC\] SKIPPED:' || true; })"
if [ "$TOTAL" -gt 0 ] && [ "$TOTAL" -eq "$SKIPPED" ]; then
echo "All $TOTAL finding(s) are roave/better-reflection SKIPPED entries (a static-analysis limitation, not a detected break); treating as pass."
exit 0
fi
WIDENED="$(printf '%s\n' "$OUTPUT" | { grep -cE '^\[BC\] CHANGED: The return type of .+::.+\(\) changed from void to the non-covariant ' || true; })"
if [ "$TOTAL" -gt 0 ] && [ "$TOTAL" -eq "$WIDENED" ] \
&& [ "$CODE" -eq 3 ] && [ -n "$NEXT_MAJOR" ] \
&& [ "$NEXT_MAJOR" -eq "$LATEST_MAJOR" ] \
&& [ "$NEXT_MINOR" -gt "$LATEST_MINOR" ]; then
PASS=1
while IFS= read -r FINDING; do
CLASS="$(printf '%s\n' "$FINDING" | sed -E 's/^\[BC\] CHANGED: The return type of (.+)::.+$/\1/')"
if ! php -r 'require "vendor/autoload.php"; exit(class_exists($argv[1]) && (new ReflectionClass($argv[1]))->isFinal() ? 0 : 1);' "$CLASS"; then
echo "Finding is a void widening but $CLASS is not final (or not loadable):"
printf '%s\n' "$FINDING"
PASS=0
break
fi
done <<< "$(printf '%s\n' "$OUTPUT" | grep -E '^\[BC\] ')"
if [ "$PASS" -eq 1 ]; then
echo "All $TOTAL finding(s) are return-type widenings from void on final classes, and CHANGELOG declares the minor $NEXT the compatibility policy admits them in; treating as pass."
exit 0
fi
fi
fi
exit "$CODE"