Skip to content

Commit 6695813

Browse files
committed
ci: cache PHPStan results
1 parent 47894ce commit 6695813

2 files changed

Lines changed: 21 additions & 9 deletions

File tree

.github/workflows/reusable-php-static-analysis.yml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ jobs:
2525
# - Checks out the repository.
2626
# - Sets up PHP.
2727
# - Logs debug information.
28-
# - Configures caching for PHP static analysis scans.
29-
# - Validates the composer.json file.
3028
# - Installs Composer dependencies.
29+
# - Configures caching for PHP static analysis scans.
3130
# - Make Composer packages available globally.
3231
# - Runs PHPStan static analysis (with Pull Request annotations).
32+
# - Saves the PHPStan result cache.
3333
# - Ensures version-controlled files are not modified or deleted.
3434
phpstan:
3535
name: Run PHP static analysis
@@ -62,12 +62,6 @@ jobs:
6262
id: get-date
6363
run: echo "date=$(/bin/date -u --date='last Mon' "+%F")" >> "$GITHUB_OUTPUT"
6464

65-
- name: Cache PHP Static Analysis scan cache
66-
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
67-
with:
68-
path: .cache/phpcompat.json
69-
key: ${{ runner.os }}-date-${{ steps.get-date.outputs.date }}-php-${{ inputs.php-version }}-phpcompat-cache-${{ hashFiles('**/composer.json', 'phpcompat.xml.dist') }}
70-
7165
# Since Composer dependencies are installed using `composer update` and no lock file is in version control,
7266
# passing a custom cache suffix ensures that the cache is flushed at least once per week.
7367
- name: Install Composer dependencies
@@ -78,9 +72,24 @@ jobs:
7872
- name: Make Composer packages available globally
7973
run: echo "${PWD}/vendor/bin" >> "$GITHUB_PATH"
8074

75+
- name: Cache PHP Static Analysis scan cache
76+
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
77+
with:
78+
path: .cache # This is defined in the base.neon file.
79+
key: "phpstan-result-cache-${{ github.run_id }}"
80+
restore-keys: |
81+
phpstan-result-cache-
82+
8183
- name: Run PHP static analysis tests
8284
id: phpstan
83-
run: phpstan analyse -vv --error-format=checkstyle |cs2pr
85+
run: phpstan analyse -vv --error-format=checkstyle | cs2pr
86+
87+
- name: "Save result cache"
88+
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
89+
if: ${{ !cancelled() }}
90+
with:
91+
path: .cache
92+
key: "phpstan-result-cache-${{ github.run_id }}"
8493

8594
- name: Ensure version-controlled files are not modified or deleted
8695
run: git diff --exit-code

tests/phpstan/base.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
# https://phpstan.org/config-reference
66

77
parameters:
8+
# Cache is stored locally, so it's available for CI.
9+
tmpDir: ../../.cache
10+
811
# What directories and files should be scanned.
912
paths:
1013
- ../../src

0 commit comments

Comments
 (0)