Skip to content

Commit 3bbdaa2

Browse files
committed
Refactor coverage uploading
1 parent 020af6d commit 3bbdaa2

File tree

2 files changed

+66
-20
lines changed

2 files changed

+66
-20
lines changed

.github/workflows/test-phpunit.yml

Lines changed: 64 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ concurrency:
3131
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
3232
cancel-in-progress: true
3333

34+
env:
35+
COVERAGE_PHP_VERSION: '8.0'
36+
3437
jobs:
3538
tests:
3639
name: PHP ${{ matrix.php-versions }} - ${{ matrix.db-platforms }}
@@ -133,9 +136,10 @@ jobs:
133136
php-version: ${{ matrix.php-versions }}
134137
tools: composer, pecl
135138
extensions: imagick, sqlsrv, gd, sqlite3, redis, memcached, oci8, pgsql
136-
coverage: xdebug
139+
coverage: ${{ env.COVERAGE_DRIVER }}
137140
env:
138141
update: true
142+
COVERAGE_DRIVER: ${{ matrix.php-versions == env.COVERAGE_PHP_VERSION && 'xdebug' || 'none'}}
139143

140144
- name: Install latest ImageMagick
141145
run: |
@@ -158,44 +162,84 @@ jobs:
158162
run: |
159163
composer update --ansi --no-interaction
160164
composer remove --ansi --dev --unused -W -- rector/rector phpstan/phpstan friendsofphp/php-cs-fixer nexusphp/cs-config codeigniter/coding-standard
161-
env:
162-
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
163165
164-
- name: Profile slow tests in PHP 8.0
165-
if: matrix.php-versions == '8.0'
166+
- name: Profile slow tests in PHP ${{ env.COVERAGE_PHP_VERSION }}
167+
if: matrix.php-versions == env.COVERAGE_PHP_VERSION
166168
run: echo "TACHYCARDIA_MONITOR_GA=enabled" >> $GITHUB_ENV
167169

168170
- name: Compute coverage option
169171
uses: actions/github-script@v6
170172
id: phpunit-coverage-option
171173
with:
172-
script: 'return "${{ matrix.php-versions }}" == "8.0" ? "" : "--no-coverage"'
174+
script: |
175+
const { COVERAGE_NAME } = process.env
176+
177+
return "${{ matrix.php-versions }}" == "${{ env.COVERAGE_PHP_VERSION }}" ? `--coverage-php build/cov/coverage-${COVERAGE_NAME}.cov` : "--no-coverage"
173178
result-encoding: string
179+
env:
180+
COVERAGE_NAME: php-v${{ env.COVERAGE_PHP_VERSION }}-${{ matrix.db-platforms }}
174181

175182
- name: Test with PHPUnit
176183
run: script -e -c "vendor/bin/phpunit --color=always --exclude-group=auto-review ${{ steps.phpunit-coverage-option.outputs.result }}"
177184
env:
178185
DB: ${{ matrix.db-platforms }}
179186
TERM: xterm-256color
180187

181-
- name: Run Coveralls
182-
if: github.repository_owner == 'codeigniter4' && matrix.php-versions == '8.0'
183-
run: |
184-
composer global require --ansi php-coveralls/php-coveralls:^2.4
185-
php-coveralls --coverage_clover=build/logs/clover.xml -v
188+
- name: Upload coverage file
189+
if: matrix.php-versions == env.COVERAGE_PHP_VERSION
190+
uses: actions/upload-artifact@v3
191+
with:
192+
name: ${{ env.COVERAGE_NAME }}
193+
path: build/cov/coverage-${{ env.COVERAGE_NAME }}.cov
194+
if-no-files-found: error
195+
retention-days: 1
186196
env:
187-
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
188-
COVERALLS_PARALLEL: true
189-
COVERALLS_FLAG_NAME: PHP ${{ matrix.php-versions }} - ${{ matrix.db-platforms }}
197+
COVERAGE_NAME: php-v${{ env.COVERAGE_PHP_VERSION }}-${{ matrix.db-platforms }}
190198

191-
coveralls-finish:
199+
coveralls:
192200
if: github.repository_owner == 'codeigniter4'
193-
needs: [tests]
201+
needs: tests
194202
runs-on: ubuntu-20.04
195203

196204
steps:
197-
- name: Coveralls Finished
198-
uses: coverallsapp/github-action@master
205+
- name: Checkout
206+
uses: actions/checkout@v3
207+
208+
- name: Setup PHP, with composer and extensions
209+
uses: shivammathur/setup-php@v2
210+
with:
211+
php-version: ${{ env.COVERAGE_PHP_VERSION }}
212+
tools: composer
213+
coverage: xdebug
214+
env:
215+
update: true
216+
217+
- name: Download coverage files
218+
uses: actions/download-artifact@v3
199219
with:
200-
github-token: ${{ secrets.GITHUB_TOKEN }}
201-
parallel-finished: true
220+
path: build/cov
221+
222+
- name: Display structure of downloaded files
223+
run: ls -R
224+
working-directory: build/cov
225+
226+
- name: Get composer cache directory
227+
run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_ENV
228+
229+
- name: Cache dependencies
230+
uses: actions/cache@v3
231+
with:
232+
path: ${{ env.COMPOSER_CACHE_FILES_DIR }}
233+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
234+
restore-keys: ${{ runner.os }}-composer-
235+
236+
- name: Install dependencies
237+
run: composer update --ansi --no-interaction
238+
239+
- name: Merge coverage files
240+
run: vendor/bin/phpcov merge --clover build/logs/clover.xml build/cov
241+
242+
- name: Upload coverage to Coveralls
243+
run: vendor/bin/php-coveralls --verbose --exclude-no-stmt --ansi
244+
env:
245+
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
"mikey179/vfsstream": "^1.6",
2222
"nexusphp/cs-config": "^3.6",
2323
"nexusphp/tachycardia": "^1.0",
24+
"php-coveralls/php-coveralls": "^2.5",
2425
"phpstan/phpstan": "^1.7.1",
26+
"phpunit/phpcov": "^8.2",
2527
"phpunit/phpunit": "^9.1",
2628
"predis/predis": "^1.1 || ^2.0",
2729
"rector/rector": "0.14.6"

0 commit comments

Comments
 (0)