Skip to content

Commit 3f29c24

Browse files
committed
GH Actions: start recording code coverage
This commit reworks the `test` workflow to start running the tests with code coverage for low/medium/high PHP and upload the generated reports to Coveralls. * It adds an extra "coverage" job which runs only the unit tests with code coverage against low/medium/high PHP. This job does not run the CS check as an integration test. * Makes minor tweaks to the pre-existing "test" job to prevent duplicate test runs for the exact same PHP/custom ini combinations. No need to run the same check twice. The recorded code coverage reports will be available on: https://coveralls.io/github/PHPCSStandards/PHP_CodeSniffer Includes adding a code coverage badge to the README.
1 parent c49a254 commit 3f29c24

File tree

3 files changed

+102
-4
lines changed

3 files changed

+102
-4
lines changed

.github/workflows/quicktest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
run: php bin/phpcs --config-set php_path php
5555

5656
- name: 'PHPUnit: run the tests'
57-
run: vendor/bin/phpunit tests/AllTests.php
57+
run: vendor/bin/phpunit tests/AllTests.php --no-coverage
5858

5959
# Note: The code style check is run as an integration test.
6060
- name: 'PHPCS: check code style without cache, no parallel'

.github/workflows/test.yml

Lines changed: 100 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,14 @@ jobs:
7474
custom_ini: [false]
7575

7676
include:
77-
# Builds running the basic tests with different PHP ini settings.
77+
# Skip test runs on builds which are also run for in the coverage job.
78+
# Note: the tests on PHP 7.2 will still be run as the coverage build is uses custom_ini for that version.
79+
- php: '5.4'
80+
skip_tests: true
81+
- php: '8.3'
82+
skip_tests: true
83+
84+
# Extra builds running only the unit tests with different PHP ini settings.
7885
- php: '5.5'
7986
custom_ini: true
8087
- php: '7.0'
@@ -137,8 +144,9 @@ jobs:
137144
- name: 'PHPCS: set the path to PHP'
138145
run: php bin/phpcs --config-set php_path php
139146

140-
- name: 'PHPUnit: run the tests'
141-
run: vendor/bin/phpunit tests/AllTests.php
147+
- name: 'PHPUnit: run the tests without code coverage'
148+
if: ${{ matrix.skip_tests != true }}
149+
run: vendor/bin/phpunit tests/AllTests.php --no-coverage
142150

143151
- name: 'PHPCS: check code style without cache, no parallel'
144152
if: ${{ matrix.custom_ini == false && matrix.php != '7.4' }}
@@ -163,3 +171,92 @@ jobs:
163171
- name: 'PHPCS: check code style using the Phar file'
164172
if: ${{ matrix.custom_ini == false }}
165173
run: php phpcs.phar
174+
175+
coverage:
176+
runs-on: ubuntu-latest
177+
178+
strategy:
179+
matrix:
180+
include:
181+
- php: '5.4'
182+
custom_ini: false
183+
- php: '7.2'
184+
custom_ini: true
185+
- php: '8.3'
186+
custom_ini: false
187+
188+
name: "Coverage: ${{ matrix.php }} ${{ matrix.custom_ini && ' with custom ini settings' || '' }}"
189+
190+
steps:
191+
- name: Checkout code
192+
uses: actions/checkout@v4
193+
194+
- name: Setup ini config
195+
id: set_ini
196+
run: |
197+
# Set the "short_open_tag" ini to make sure specific conditions are tested.
198+
# Also turn on error_reporting to ensure all notices are shown.
199+
if [[ ${{ matrix.custom_ini }} == true && "${{ startsWith( matrix.php, '5.' ) }}" == true ]]; then
200+
echo 'PHP_INI=error_reporting=-1, display_errors=On, date.timezone=Australia/Sydney, short_open_tag=On, asp_tags=On' >> $GITHUB_OUTPUT
201+
elif [[ ${{ matrix.custom_ini }} == true && "${{ startsWith( matrix.php, '7.' ) }}" == true ]]; then
202+
echo 'PHP_INI=error_reporting=-1, display_errors=On, date.timezone=Australia/Sydney, short_open_tag=On' >> $GITHUB_OUTPUT
203+
else
204+
echo 'PHP_INI=error_reporting=-1, display_errors=On' >> $GITHUB_OUTPUT
205+
fi
206+
207+
- name: Install PHP
208+
uses: shivammathur/setup-php@v2
209+
with:
210+
php-version: ${{ matrix.php }}
211+
ini-values: ${{ steps.set_ini.outputs.PHP_INI }}
212+
coverage: xdebug
213+
214+
# This action also handles the caching of the dependencies.
215+
- name: Set up node
216+
if: ${{ matrix.custom_ini == false }}
217+
uses: actions/setup-node@v4
218+
with:
219+
node-version: '20'
220+
221+
- name: Install external tools used in tests
222+
if: ${{ matrix.custom_ini == false }}
223+
run: >
224+
npm install -g --fund false
225+
csslint
226+
eslint
227+
jshint
228+
229+
# Install dependencies and handle caching in one go.
230+
# @link https://github.com/marketplace/actions/install-php-dependencies-with-composer
231+
- name: Install Composer dependencies
232+
uses: "ramsey/composer-install@v2"
233+
with:
234+
# Bust the cache at least once a month - output format: YYYY-MM.
235+
custom-cache-suffix: $(date -u "+%Y-%m")
236+
237+
- name: 'PHPCS: set the path to PHP'
238+
run: php bin/phpcs --config-set php_path php
239+
240+
- name: 'PHPUnit: run the tests with code coverage'
241+
run: vendor/bin/phpunit tests/AllTests.php
242+
243+
- name: Upload coverage results to Coveralls
244+
if: ${{ success() }}
245+
uses: coverallsapp/github-action@v2
246+
with:
247+
format: clover
248+
file: build/logs/clover.xml
249+
flag-name: php-${{ matrix.php }}-custom-ini-${{ matrix.custom_ini }}
250+
parallel: true
251+
252+
coveralls-finish:
253+
needs: coverage
254+
if: always() && needs.coverage.result == 'success'
255+
256+
runs-on: ubuntu-latest
257+
258+
steps:
259+
- name: Coveralls Finished
260+
uses: coverallsapp/github-action@v2
261+
with:
262+
parallel-finished: true

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ PHP_CodeSniffer
66
[![Latest Stable Version](http://poser.pugx.org/phpcsstandards/php_codesniffer/v)](https://github.com/PHPCSStandards/PHP_CodeSniffer/releases)
77
[![Validate](https://github.com/PHPCSStandards/PHP_CodeSniffer/actions/workflows/validate.yml/badge.svg?branch=master)](https://github.com/PHPCSStandards/PHP_CodeSniffer/actions/workflows/validate.yml)
88
[![Test](https://github.com/PHPCSStandards/PHP_CodeSniffer/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/PHPCSStandards/PHP_CodeSniffer/actions/workflows/test.yml)
9+
[![Coverage Status](https://coveralls.io/repos/github/PHPCSStandards/PHP_CodeSniffer/badge.svg?branch=master)](https://coveralls.io/github/PHPCSStandards/PHP_CodeSniffer?branch=master)
910
[![License](http://poser.pugx.org/phpcsstandards/php_codesniffer/license)](https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt)
1011

1112
![Minimum PHP Version](https://img.shields.io/packagist/php-v/squizlabs/php_codesniffer.svg?maxAge=3600)

0 commit comments

Comments
 (0)