Skip to content

Commit

Permalink
GH Actions: start recording code coverage
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jrfnl committed Dec 9, 2023
1 parent 2b41ff6 commit 04bfe05
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/quicktest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
run: php bin/phpcs --config-set php_path php

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

# Note: The code style check is run as an integration test.
- name: 'PHPCS: check code style without cache, no parallel'
Expand Down
51 changes: 46 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,31 @@ jobs:
# Keys:
# - custom_ini: Whether to run with specific custom ini settings to hit very specific
# code conditions.
# - coverage: Whether to run the tests with code coverage.
matrix:
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']
php: ['5.5', '5.6', '7.0', '7.1', '7.3', '7.4', '8.0', '8.1', '8.2', '8.4']
custom_ini: [false]
coverage: [false]

include:
# Builds running the basic tests with different PHP ini settings.
- php: '5.5'
custom_ini: true
coverage: false
- php: '7.0'
custom_ini: true
coverage: false

# Builds running the tests with code coverage.
- php: '5.4'
custom_ini: false
coverage: true
- php: '7.2'
custom_ini: true
coverage: true
- php: '8.3'
custom_ini: false
coverage: true

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

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

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

- name: 'PHPUnit: run the tests'
- name: 'PHPUnit: run the tests without code coverage'
if: ${{ matrix.coverage == false }}
run: vendor/bin/phpunit tests/AllTests.php --no-coverage

- name: 'PHPUnit: run the tests with code coverage'
if: ${{ matrix.coverage == true }}
run: vendor/bin/phpunit tests/AllTests.php

- name: 'PHPCS: check code style without cache, no parallel'
Expand All @@ -169,3 +189,24 @@ jobs:
- name: 'PHPCS: check code style using the Phar file'
if: ${{ matrix.custom_ini == false }}
run: php phpcs.phar

- name: Upload coverage results to Coveralls
if: ${{ success() && matrix.coverage == true }}
uses: coverallsapp/github-action@v2
with:
format: clover
file: build/logs/clover.xml
flag-name: php-${{ matrix.php }}-custom-ini-${{ matrix.custom_ini }}
parallel: true

coveralls-finish:
needs: test
if: always() && needs.test.result == 'success'

runs-on: ubuntu-latest

steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@v2
with:
parallel-finished: true
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ PHP_CodeSniffer
[![Latest Stable Version](http://poser.pugx.org/phpcsstandards/php_codesniffer/v)](https://github.com/PHPCSStandards/PHP_CodeSniffer/releases)
[![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)
[![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)
[![Coverage Status](https://coveralls.io/repos/github/PHPCSStandards/PHP_CodeSniffer/badge.svg?branch=master)](https://coveralls.io/github/PHPCSStandards/PHP_CodeSniffer?branch=master)
[![License](http://poser.pugx.org/phpcsstandards/php_codesniffer/license)](https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt)

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

0 comments on commit 04bfe05

Please sign in to comment.