Skip to content

Any better ?

Any better ? #2358

Workflow file for this run

name: Test
on:
# Run on pushes to `master` and on all pull requests.
# Prevent the build from running when there are only irrelevant changes.
push:
# branches:
# - master
# tags:
# - '**'
# paths-ignore:
# - '**.md'
pull_request:
# Allow manually triggering the workflow.
workflow_dispatch:
jobs:
coverage:
# Explicitly *NOT* setting "concurrency" for this job to allow for monitoring code coverage for all merges.
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ['ubuntu-latest', 'windows-latest']
php: ['8.4']
custom_ini: [false]
include:
- php: '5.4'
os: 'ubuntu-latest'
custom_ini: false
# Installing on Windows with PHP 5.4 runs into all sorts of problems with Composer.
# Considering PHP 5.4 is ancient, I deem it acceptable to run coverage on Windows on PHP 5.5.
# See this issue for more context (yes, I've seen this problem before):
# @link https://github.com/PHPCSStandards/composer-installer/pull/213
- php: '5.5'
os: 'windows-latest'
custom_ini: false
# Also run one coverage build with custom ini settings.
- php: '7.2'
os: 'ubuntu-latest'
custom_ini: true
# yamllint disable-line rule:line-length
name: "Coverage: ${{ matrix.php }} ${{ matrix.custom_ini && ' with custom ini settings' || '' }} (${{ matrix.os == 'ubuntu-latest' && 'Linux' || 'Win' }})"
steps:
- name: Prepare git to leave line endings alone
run: git config --global core.autocrlf input
- name: Checkout code
uses: actions/checkout@v4
- name: Setup ini config
if: ${{ matrix.os != 'windows-latest' }}
id: set_ini
shell: bash
run: |
# Set the "short_open_tag" ini to make sure specific conditions are tested.
if [[ ${{ matrix.custom_ini }} == true && "${{ matrix.php }}" == '7.2' ]]; then
echo 'PHP_INI=, date.timezone=Australia/Sydney, short_open_tag=On' >> "$GITHUB_OUTPUT"
fi
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
ini-values: error_reporting=-1, display_errors=On${{ steps.set_ini.outputs.PHP_INI }}
coverage: xdebug
# This action also handles the caching of the dependencies.
- name: Set up node
if: ${{ matrix.custom_ini == false }}
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install external tools used in tests
if: ${{ matrix.custom_ini == false }}
run: >
npm install -g --fund false
csslint
eslint
jshint
# Install dependencies and handle caching in one go.
# @link https://github.com/marketplace/actions/install-php-dependencies-with-composer
- name: Install Composer dependencies
uses: "ramsey/composer-install@v3"
with:
# Bust the cache at least once a month - output format: YYYY-MM.
custom-cache-suffix: $(date -u "+%Y-%m")
- name: Grab PHPUnit version
id: phpunit_version
shell: bash
# yamllint disable-line rule:line-length
run: echo "VERSION=$(php "vendor/bin/phpunit" --version | grep --only-matching --max-count=1 --extended-regexp '\b[0-9]+\.[0-9]+')" >> "$GITHUB_OUTPUT"
- name: "DEBUG: Show grabbed version"
run: echo ${{ steps.phpunit_version.outputs.VERSION }}
- name: 'PHPCS: set the path to PHP'
run: php "bin/phpcs" --config-set php_path php
# PHPUnit 9.3 started using PHP-Parser for code coverage, which can cause issues due to Parser
# also polyfilling PHP tokens.
# As of PHPUnit 9.3.4, a cache warming option is available.
# Using that option prevents issues with PHP-Parser backfilling PHP tokens during our test runs.
- name: "Warm the PHPUnit cache (PHPUnit 9.3+)"
if: ${{ steps.phpunit_version.outputs.VERSION >= '9.3' }}
run: php "vendor/bin/phpunit" --coverage-cache ./build/phpunit-cache --warm-coverage-cache
- name: "Run the unit tests with code coverage (PHPUnit < 9.3)"
if: ${{ matrix.os != 'windows-latest' && steps.phpunit_version.outputs.VERSION < '9.3' }}
run: php "vendor/bin/phpunit" tests/AllTests.php --filter ExpandRulesetReferenceTest
- name: "Run the unit tests with code coverage (PHPUnit 9.3+)"
if: ${{ matrix.os != 'windows-latest' && steps.phpunit_version.outputs.VERSION >= '9.3' }}
run: php "vendor/bin/phpunit" tests/AllTests.php --filter ExpandRulesetReferenceTest --coverage-cache ./build/phpunit-cache
- name: "Run select tests in CBF mode with code coverage (PHPUnit < 9.3)"
if: ${{ matrix.os != 'windows-latest' && steps.phpunit_version.outputs.VERSION < '9.3' }}
run: >
php "vendor/bin/phpunit" tests/AllTests.php
--group CBF --exclude-group nothing --coverage-clover build/logs/clover-cbf.xml
env:
PHP_CODESNIFFER_CBF: '1'
- name: "Run select tests in CBF mode with code coverage (PHPUnit 9.3+)"
if: ${{ matrix.os != 'windows-latest' && steps.phpunit_version.outputs.VERSION >= '9.3' }}
run: >
php "vendor/bin/phpunit" tests/AllTests.php --coverage-cache ./build/phpunit-cache
--group CBF --exclude-group nothing --coverage-clover build/logs/clover-cbf.xml
env:
PHP_CODESNIFFER_CBF: '1'
- name: "Run the unit tests which may have different outcomes on Windows with code coverage (PHPUnit < 9.3)"
if: ${{ matrix.os == 'windows-latest' && steps.phpunit_version.outputs.VERSION < '9.3' }}
run: php "vendor/bin/phpunit" tests/AllTests.php --filter ExpandRulesetReferenceTest --group Windows
- name: "Run the unit tests which may have different outcomes on Windows with code coverage (PHPUnit 9.3+)"
if: ${{ matrix.os == 'windows-latest' && steps.phpunit_version.outputs.VERSION >= '9.3' }}
run: php "vendor/bin/phpunit" tests/AllTests.php --filter ExpandRulesetReferenceTest --group Windows --coverage-cache ./build/phpunit-cache
- name: "Upload coverage results to Coveralls (normal run)"
if: ${{ success() }}
uses: coverallsapp/github-action@v2
with:
format: clover
file: build/logs/clover.xml
flag-name: os-${{ matrix.os }}-php-${{ matrix.php }}-custom-ini-${{ matrix.custom_ini }}
parallel: true
- name: "Upload coverage results to Coveralls (CBF run)"
if: ${{ matrix.os != 'windows-latest' && success() }}
uses: coverallsapp/github-action@v2
with:
format: clover
file: build/logs/clover-cbf.xml
flag-name: cbf-os-${{ matrix.os }}-ubuntu-latest-php-${{ matrix.php }}-custom-ini-${{ matrix.custom_ini }}
parallel: true
coveralls-finish:
needs: coverage
if: always() && needs.coverage.result == 'success'
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@v2
with:
parallel-finished: true