Repository navigation
70 lines (62 loc) · 3.55 KB
/
Copy pathphpstan.yml
File metadata and controls
70 lines (62 loc) · 3.55 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
on:
pull_request:
types: [ opened, labeled, synchronize ]
name: PHPStan Code Analysis
# Cancel superseded runs for the same branch. The group is named explicitly
# rather than derived from github.workflow: several files share the workflow
# name `Inspections` and would otherwise cancel each other.
concurrency:
group: formidable-phpstan-${{ github.ref }}-${{ ((contains(github.event.pull_request.labels.*.name, 'run analysis') || contains(github.event.pull_request.labels.*.name, 'full automated qa')) && (github.event.action != 'labeled' || github.event.label.name == 'run analysis' || github.event.label.name == 'full automated qa')) && 'active' || github.run_id }}
cancel-in-progress: true
jobs:
phpstan:
if: >-
(contains(github.event.pull_request.labels.*.name, 'run analysis') || contains(github.event.pull_request.labels.*.name, 'full automated qa'))
&& (github.event.action != 'labeled' || github.event.label.name == 'run analysis' || github.event.label.name == 'full automated qa')
name: PHPStan
runs-on: ubuntu-latest
steps:
- name: "📥 Fetching Repository Contents"
uses: actions/checkout@v4.1.1
- name: "💽 Installing PHP, Composer, CS2PR"
uses: shivammathur/setup-php@2.30.2
with:
php-version: 8.1
coverage: none
ini-values: display_errors = on, error_reporting = E_ALL
tools: composer
# Install only what this job runs, instead of every require-dev package.
# phpstan.neon bootstraps vendor/php-stubs/wordpress-stubs and stubs.php, and
# stubs.php references PHPUnit\Framework\TestCase - without phpunit-polyfills
# the run dies while loading the bootstrap file.
# The guard fails the job if a package is renamed or dropped from
# composer.json, rather than silently narrowing to nothing.
- name: Install PHPStan
run: |
NEED='phpstan/phpstan phpstan/extension-installer phpstan/phpstan-strict-rules php-stubs/wordpress-stubs yoast/phpunit-polyfills'
for pkg in $NEED; do
jq -e --arg pkg "$pkg" '."require-dev" | has($pkg)' composer.json > /dev/null \
|| { echo "::error::composer.json has no require-dev entry for $pkg"; exit 1; }
done
jq '{require, autoload, config, "require-dev": (."require-dev" | with_entries(select(.key as $k | $ARGS.positional | index($k))))}' \
composer.json --args $NEED > composer.ci.json
COMPOSER=composer.ci.json composer install --prefer-dist --no-progress
# PHPStan's result cache means only changed files get re-analysed.
# /tmp/phpstan is where it lands by default (sys_get_temp_dir() +
# '/phpstan'); this PHPStan build has no flag to relocate it, and pointing
# tmpDir into the working tree would make `analyze ./` walk its own
# cache. PHPStan
# validates the cache against its own version and the config, so a stale
# restore degrades to a full analysis rather than a wrong result. The sha
# suffix is needed because cache entries are immutable - without it the
# first entry would win forever and the cache would never advance.
- name: Cache PHPStan results
uses: actions/cache@v4
with:
path: /tmp/phpstan
key: formidable-phpstan-${{ hashFiles('composer.json', 'phpstan.neon') }}-${{ github.sha }}
restore-keys: |
formidable-phpstan-${{ hashFiles('composer.json', 'phpstan.neon') }}-
formidable-phpstan-
- name: "🧪 Test"
run: vendor/bin/phpstan analyze ./ --memory-limit=2G