Skip to content

Commit 0c69fed

Browse files
committed
Refactor CI workflows for tools-based checks
1 parent 31aae1c commit 0c69fed

2 files changed

Lines changed: 97 additions & 13 deletions

File tree

.github/workflows/ci.yml

Lines changed: 82 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ on:
66
- "src/**"
77
- "tests/**"
88
- "composer.json"
9+
- ".phive/phars.xml"
910
- "phpstan.neon.dist"
1011
- "phpunit.xml.dist"
1112
- ".php-cs-fixer.dist.php"
1213
- "rector.php"
13-
- "composer-dependency-analyser.php"
14+
- "tools/**"
1415
- ".github/workflows/ci.yml"
1516
- ".github/workflows/secure-tests.yml"
1617
push:
@@ -19,11 +20,12 @@ on:
1920
- "src/**"
2021
- "tests/**"
2122
- "composer.json"
23+
- ".phive/phars.xml"
2224
- "phpstan.neon.dist"
2325
- "phpunit.xml.dist"
2426
- ".php-cs-fixer.dist.php"
2527
- "rector.php"
26-
- "composer-dependency-analyser.php"
28+
- "tools/**"
2729
- ".github/workflows/ci.yml"
2830
- ".github/workflows/secure-tests.yml"
2931
workflow_dispatch:
@@ -113,16 +115,75 @@ jobs:
113115
- name: Install dependencies with Composer
114116
run: composer install --no-interaction --no-progress --ansi --ignore-platform-req=ext-grpc
115117

118+
- name: Cache PHPStan dependencies
119+
uses: actions/cache@v5
120+
with:
121+
path: tools/.phpstan/vendor
122+
key: ${{ runner.os }}-phpstan-tools-${{ hashFiles('tools/.phpstan/composer.lock') }}
123+
124+
- name: Install PHPStan dependencies
125+
run: composer --working-dir=tools/.phpstan install --no-interaction --no-progress --ansi
126+
116127
- name: Setup problem matchers for PHP
117128
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
118129

119130
- name: Run PHPStan
120-
run: XDEBUG_MODE=off vendor/bin/phpstan analyse --no-progress --error-format=github
131+
run: XDEBUG_MODE=off tools/phpstan analyse --no-progress --error-format=github
132+
133+
lint:
134+
name: Lint
135+
needs:
136+
- dependency-validation
137+
runs-on: ubuntu-latest
138+
timeout-minutes: 20
139+
140+
steps:
141+
- name: Checkout code
142+
uses: actions/checkout@v6
143+
144+
- name: Setup PHP
145+
uses: shivammathur/setup-php@v2
146+
with:
147+
php-version: "8.5"
148+
tools: composer, pecl
149+
coverage: none
150+
151+
- name: Get Composer cache directory
152+
id: composer-cache
153+
shell: bash
154+
run: |
155+
echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT"
156+
157+
- name: Cache Composer cache directory
158+
uses: actions/cache@v5
159+
with:
160+
path: ${{ steps.composer-cache.outputs.dir }}
161+
key: ${{ runner.os }}-composer-${{ hashFiles('composer.json', 'composer.lock') }}
162+
restore-keys: ${{ runner.os }}-composer-
163+
164+
- name: Install dependencies with Composer
165+
run: composer install --no-interaction --no-progress --ansi --ignore-platform-req=ext-grpc
166+
167+
- name: Cache Rector dependencies
168+
uses: actions/cache@v5
169+
with:
170+
path: tools/.rector/vendor
171+
key: ${{ runner.os }}-rector-tools-${{ hashFiles('tools/.rector/composer.lock') }}
172+
173+
- name: Install Rector dependencies
174+
run: composer --working-dir=tools/.rector install --no-interaction --no-progress --ansi
175+
176+
- name: Run linter suite
177+
run: |
178+
tools/rector --ansi --dry-run
179+
tools/php-cs-fixer check --ansi --diff --verbose
180+
tools/composer-normalize --ansi --dry-run
121181
122182
tests:
123183
name: "PHP ${{ matrix.php }}, ${{ matrix.dependencies }} deps"
124184
needs:
125185
- static-analysis
186+
- lint
126187
runs-on: ubuntu-latest
127188
timeout-minutes: 20
128189

@@ -176,7 +237,7 @@ jobs:
176237
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
177238

178239
- name: Run PHPUnit
179-
run: vendor/bin/phpunit --testsuite=unit --testdox
240+
run: tools/phpunit --testsuite=unit --testdox
180241

181242
code-coverage:
182243
name: Unit Test Coverage (PHP 8.5)
@@ -218,8 +279,21 @@ jobs:
218279
- name: Setup Problem Matchers for PHPUnit
219280
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
220281

221-
- name: Run PHPUnit with coverage
222-
run: vendor/bin/phpunit --testsuite=unit --coverage-clover=coverage.xml --log-junit=test-report.xml --testdox
282+
- name: Cache PHPUnit static analysis cache
283+
uses: actions/cache@v5
284+
with:
285+
path: .phpunit.cache/code-coverage
286+
key: ${{ runner.os }}-phpunit-code-coverage-${{ github.ref }}-
287+
restore-keys: |
288+
${{ runner.os }}-phpunit-code-coverage-${{ github.ref }}-
289+
290+
- name: Warm PHPUnit static analysis cache
291+
run: tools/phpunit --warm-coverage-cache
292+
293+
- name: Collect code coverage with PHPUnit
294+
run: |
295+
mkdir -p build
296+
tools/phpunit --testsuite=unit --log-junit build/test-results.xml --coverage-clover build/code-coverage.xml --testdox
223297
224298
- name: Upload test results to Codecov
225299
if: ${{ !cancelled() }}
@@ -228,14 +302,15 @@ jobs:
228302
token: ${{ secrets.CODECOV_TOKEN }}
229303
flags: unit
230304
report_type: test_results
305+
files: ./build/test-results.xml
231306
fail_ci_if_error: false
232307

233308
- name: Upload coverage to Codecov
234309
if: ${{ !cancelled() }}
235310
uses: codecov/codecov-action@v5
236311
with:
237312
token: ${{ secrets.CODECOV_TOKEN }}
238-
files: ./coverage.xml
313+
files: ./build/code-coverage.xml
239314
flags: unit
240315
fail_ci_if_error: false
241316

.github/workflows/secure-tests.yml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ jobs:
105105
TEST_FIREBASE_TENANT_ID: ${{secrets.TEST_FIREBASE_TENANT_ID}}
106106
TEST_REGISTRATION_TOKENS: ${{secrets.TEST_REGISTRATION_TOKENS}}
107107
XDEBUG_MODE: coverage
108-
run: vendor/bin/phpunit --testsuite=integration --exclude-group grpc --coverage-clover=coverage.xml --log-junit=test-report.xml --testdox
108+
run: |
109+
mkdir -p build
110+
tools/phpunit --testsuite=integration --exclude-group grpc --coverage-clover=build/coverage.xml --log-junit=build/test-report.xml --testdox
109111
110112
- name: Upload integration test results to Codecov
111113
if: ${{ !cancelled() }}
@@ -114,14 +116,15 @@ jobs:
114116
token: ${{ secrets.CODECOV_TOKEN }}
115117
flags: integration
116118
report_type: test_results
119+
files: ./build/test-report.xml
117120
fail_ci_if_error: false
118121

119122
- name: Upload integration coverage to Codecov
120123
if: ${{ !cancelled() }}
121124
uses: codecov/codecov-action@v5
122125
with:
123126
token: ${{ secrets.CODECOV_TOKEN }}
124-
files: ./coverage.xml
127+
files: ./build/coverage.xml
125128
flags: integration
126129
fail_ci_if_error: false
127130

@@ -194,7 +197,9 @@ jobs:
194197
FIREBASE_DATABASE_EMULATOR_HOST: localhost:9100
195198
FIREBASE_AUTH_EMULATOR_HOST: localhost:9099
196199
XDEBUG_MODE: coverage
197-
run: firebase emulators:exec --only auth,database --project beste-firebase 'XDEBUG_MODE=coverage vendor/bin/phpunit --group=emulator --exclude-group grpc --coverage-clover=coverage.xml --log-junit=test-report.xml'
200+
run: |
201+
mkdir -p build
202+
firebase emulators:exec --only auth,database --project beste-firebase 'XDEBUG_MODE=coverage tools/phpunit --group=emulator --exclude-group grpc --coverage-clover=build/coverage.xml --log-junit=build/test-report.xml'
198203
199204
- name: Upload emulator test results to Codecov
200205
if: ${{ !cancelled() }}
@@ -203,14 +208,15 @@ jobs:
203208
token: ${{ secrets.CODECOV_TOKEN }}
204209
flags: emulator
205210
report_type: test_results
211+
files: ./build/test-report.xml
206212
fail_ci_if_error: false
207213

208214
- name: Upload emulator coverage to Codecov
209215
if: ${{ !cancelled() }}
210216
uses: codecov/codecov-action@v5
211217
with:
212218
token: ${{ secrets.CODECOV_TOKEN }}
213-
files: ./coverage.xml
219+
files: ./build/coverage.xml
214220
flags: emulator
215221
fail_ci_if_error: false
216222

@@ -299,7 +305,9 @@ jobs:
299305
TEST_FIREBASE_TENANT_ID: ${{secrets.TEST_FIREBASE_TENANT_ID}}
300306
TEST_REGISTRATION_TOKENS: ${{secrets.TEST_REGISTRATION_TOKENS}}
301307
XDEBUG_MODE: coverage
302-
run: vendor/bin/phpunit --testsuite=integration --group grpc --coverage-clover=coverage.xml --log-junit=test-report.xml --testdox
308+
run: |
309+
mkdir -p build
310+
tools/phpunit --testsuite=integration --group grpc --coverage-clover=build/coverage.xml --log-junit=build/test-report.xml --testdox
303311
304312
- name: Upload gRPC test results to Codecov
305313
if: ${{ !cancelled() && steps.grpc.outcome == 'success' }}
@@ -308,14 +316,15 @@ jobs:
308316
token: ${{ secrets.CODECOV_TOKEN }}
309317
flags: grpc
310318
report_type: test_results
319+
files: ./build/test-report.xml
311320
fail_ci_if_error: false
312321

313322
- name: Upload gRPC coverage to Codecov
314323
if: ${{ !cancelled() && steps.grpc.outcome == 'success' }}
315324
uses: codecov/codecov-action@v5
316325
with:
317326
token: ${{ secrets.CODECOV_TOKEN }}
318-
files: ./coverage.xml
327+
files: ./build/coverage.xml
319328
flags: grpc
320329
fail_ci_if_error: false
321330

0 commit comments

Comments
 (0)