Skip to content

Commit 16a5ab5

Browse files
authored
Use caching for PHPStan
1 parent 3ada372 commit 16a5ab5

File tree

3 files changed

+111
-7
lines changed

3 files changed

+111
-7
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: run-phpstan-pull
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- 'master'
7+
- 'development'
8+
9+
jobs:
10+
test:
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
fail-fast: true
14+
matrix:
15+
os: [ubuntu-latest]
16+
php: [8.3]
17+
laravel: [11]
18+
stability: [prefer-dist]
19+
20+
name: PHPStan - P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
21+
env:
22+
extensionKey: phpextensions
23+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pcov, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
24+
25+
steps:
26+
- name: Checkout code
27+
uses: actions/checkout@v4
28+
29+
- name: Setup cache environment
30+
id: extcache
31+
uses: shivammathur/cache-extensions@v1
32+
with:
33+
php-version: ${{ matrix.php }}
34+
extensions: ${{ env.extensions }}
35+
key: ${{ env.extensionKey }}
36+
37+
- name: Cache extensions
38+
uses: actions/cache@v4
39+
with:
40+
path: ${{ steps.extcache.outputs.dir }}
41+
key: ${{ steps.extcache.outputs.key }}
42+
restore-keys: ${{ steps.extcache.outputs.key }}
43+
44+
- name: Setup PHP
45+
uses: shivammathur/setup-php@v2
46+
with:
47+
php-version: ${{ matrix.php }}
48+
extensions: ${{ env.extensions }}
49+
coverage: pcov
50+
tools: phpunit:9.5
51+
env:
52+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53+
54+
- name: Setup problem matchers for PHP
55+
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
56+
57+
- name: Get composer cache directory
58+
id: composer-cache
59+
run: |
60+
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
61+
62+
- uses: actions/cache@v4
63+
with:
64+
path: ${{ steps.composer-cache.outputs.dir }}
65+
key: ${{ runner.os }}-PHPStan-P${{ matrix.php }}-L${{ matrix.laravel }}-composer-${{ hashFiles('**/composer.json') }}
66+
restore-keys: ${{ runner.os }}-PHPStan-P${{ matrix.php }}-L${{ matrix.laravel }}-composer-
67+
68+
- name: Add token
69+
run: |
70+
composer config github-oauth.github.com ${{ secrets.GITHUB_TOKEN }}
71+
72+
- name: Install dependencies
73+
if: steps.composer-cache.outputs.cache-hit != 'true'
74+
run: composer require "laravel/framework:${{ matrix.laravel }}.*" --no-interaction --no-update
75+
76+
- name: Update dependencies
77+
if: steps.composer-cache.outputs.cache-hit != 'true'
78+
run: composer update --${{ matrix.stability }} --no-interaction
79+
80+
- name: Install PHPStan
81+
run: composer require larastan/larastan:^2.0 --dev --no-interaction
82+
83+
- name: Cache Larastan result cache
84+
uses: actions/cache@v4
85+
with:
86+
path: .phpstan.cache
87+
key: "phpstan-result-cache-${​{ github.run_id }}"
88+
restore-keys: |
89+
phpstan-result-cache-
90+
91+
- name: Run PHPStan Tests
92+
run: ./vendor/bin/phpstan analyse

.github/workflows/run-phpstan.yml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
name: run-phpstan
22

33
on:
4-
pull_request:
5-
branches:
6-
- 'master'
7-
- 'development'
84
push:
95
branches:
106
- '*' # matches every branch that doesn't contain a '/'
@@ -26,10 +22,18 @@ jobs:
2622

2723
name: PHPStan - P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
2824
env:
29-
extensionKey: phpextensions
25+
extensionKey: phpstan-phpextensions
3026
extensions: dom, curl, libxml, mbstring, zip, pcntl, pcov, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
3127

3228
steps:
29+
- name: Wait for styling to finish
30+
uses: lewagon/[email protected]
31+
with:
32+
ref: ${{ github.ref }}
33+
running-workflow-name: 'Fix PHP code style issues'
34+
repo-token: ${{ secrets.GITHUB_TOKEN }}
35+
wait-interval: 20
36+
3337
- name: Checkout code
3438
uses: actions/checkout@v4
3539

@@ -87,5 +91,13 @@ jobs:
8791
- name: Install PHPStan
8892
run: composer require larastan/larastan:^2.0 --dev --no-interaction
8993

94+
- name: Cache Larastan result cache
95+
uses: actions/cache@v4
96+
with:
97+
path: .phpstan.cache
98+
key: "phpstan-result-cache-${​{ github.run_id }}"
99+
restore-keys: |
100+
phpstan-result-cache-
101+
90102
- name: Run PHPStan Tests
91103
run: ./vendor/bin/phpstan analyse

.github/workflows/run-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
ref: ${{ github.ref }}
3333
running-workflow-name: 'Fix PHP code style issues'
3434
repo-token: ${{ secrets.GITHUB_TOKEN }}
35-
wait-interval: 90
35+
wait-interval: 20
3636

3737
- name: Checkout code
3838
uses: actions/checkout@v4
@@ -119,7 +119,7 @@ jobs:
119119
ref: ${{ github.ref }}
120120
running-workflow-name: 'Fix PHP code style issues'
121121
repo-token: ${{ secrets.GITHUB_TOKEN }}
122-
wait-interval: 90
122+
wait-interval: 20
123123

124124
- name: Checkout code
125125
uses: actions/checkout@v4

0 commit comments

Comments
 (0)