Skip to content

Commit 04bfe05

Browse files
committed
GH Actions: start recording code coverage
This commit updates the `test` workflow to start running the tests with code coverage for low/medium/high PHP and uploads the generated reports to Coveralls. 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 2b41ff6 commit 04bfe05

File tree

3 files changed

+48
-6
lines changed

3 files changed

+48
-6
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: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,31 @@ jobs:
6969
# Keys:
7070
# - custom_ini: Whether to run with specific custom ini settings to hit very specific
7171
# code conditions.
72+
# - coverage: Whether to run the tests with code coverage.
7273
matrix:
73-
php: ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
74+
php: ['5.5', '5.6', '7.0', '7.1', '7.3', '7.4', '8.0', '8.1', '8.2', '8.4']
7475
custom_ini: [false]
76+
coverage: [false]
7577

7678
include:
7779
# Builds running the basic tests with different PHP ini settings.
7880
- php: '5.5'
7981
custom_ini: true
82+
coverage: false
8083
- php: '7.0'
8184
custom_ini: true
85+
coverage: false
86+
87+
# Builds running the tests with code coverage.
88+
- php: '5.4'
89+
custom_ini: false
90+
coverage: true
91+
- php: '7.2'
92+
custom_ini: true
93+
coverage: true
94+
- php: '8.3'
95+
custom_ini: false
96+
coverage: true
8297

8398
name: "PHP: ${{ matrix.php }} ${{ matrix.custom_ini && ' with custom ini settings' || '' }}"
8499

@@ -93,9 +108,9 @@ jobs:
93108
run: |
94109
# Set the "short_open_tag" ini to make sure specific conditions are tested.
95110
# Also turn on error_reporting to ensure all notices are shown.
96-
if [[ ${{ matrix.custom_ini }} == true && "${{ matrix.php }}" == '5.5' ]]; then
111+
if [[ ${{ matrix.custom_ini }} == true && "${{ startsWith( matrix.php, '5.' ) }}" == true ]]; then
97112
echo 'PHP_INI=error_reporting=-1, display_errors=On, date.timezone=Australia/Sydney, short_open_tag=On, asp_tags=On' >> $GITHUB_OUTPUT
98-
elif [[ ${{ matrix.custom_ini }} == true && "${{ matrix.php }}" == '7.0' ]]; then
113+
elif [[ ${{ matrix.custom_ini }} == true && "${{ startsWith( matrix.php, '7.' ) }}" == true ]]; then
99114
echo 'PHP_INI=error_reporting=-1, display_errors=On, date.timezone=Australia/Sydney, short_open_tag=On' >> $GITHUB_OUTPUT
100115
else
101116
echo 'PHP_INI=error_reporting=-1, display_errors=On' >> $GITHUB_OUTPUT
@@ -106,7 +121,7 @@ jobs:
106121
with:
107122
php-version: ${{ matrix.php }}
108123
ini-values: ${{ steps.set_ini.outputs.PHP_INI }}
109-
coverage: none
124+
coverage: ${{ matrix.coverage == true && 'xdebug' || 'none' }}
110125
tools: cs2pr
111126

112127
# This action also handles the caching of the dependencies.
@@ -144,7 +159,12 @@ jobs:
144159
- name: 'PHPCS: set the path to PHP'
145160
run: php bin/phpcs --config-set php_path php
146161

147-
- name: 'PHPUnit: run the tests'
162+
- name: 'PHPUnit: run the tests without code coverage'
163+
if: ${{ matrix.coverage == false }}
164+
run: vendor/bin/phpunit tests/AllTests.php --no-coverage
165+
166+
- name: 'PHPUnit: run the tests with code coverage'
167+
if: ${{ matrix.coverage == true }}
148168
run: vendor/bin/phpunit tests/AllTests.php
149169

150170
- name: 'PHPCS: check code style without cache, no parallel'
@@ -169,3 +189,24 @@ jobs:
169189
- name: 'PHPCS: check code style using the Phar file'
170190
if: ${{ matrix.custom_ini == false }}
171191
run: php phpcs.phar
192+
193+
- name: Upload coverage results to Coveralls
194+
if: ${{ success() && matrix.coverage == true }}
195+
uses: coverallsapp/github-action@v2
196+
with:
197+
format: clover
198+
file: build/logs/clover.xml
199+
flag-name: php-${{ matrix.php }}-custom-ini-${{ matrix.custom_ini }}
200+
parallel: true
201+
202+
coveralls-finish:
203+
needs: test
204+
if: always() && needs.test.result == 'success'
205+
206+
runs-on: ubuntu-latest
207+
208+
steps:
209+
- name: Coveralls Finished
210+
uses: coverallsapp/github-action@v2
211+
with:
212+
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)