Skip to content

Commit

Permalink
GH Actions: run tests on Windows too
Browse files Browse the repository at this point in the history
For the `quicktest` and the `coverage` jobs, only select tests which are marked with `@group Windows` will be run.

For the "normal " `test` job, all tests will now be run on Windows too.
  • Loading branch information
jrfnl committed Nov 13, 2024
1 parent 8d8de78 commit 64cec98
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 31 deletions.
18 changes: 12 additions & 6 deletions .github/workflows/quicktest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ jobs:
# These are basically the same builds as in the Test->Coverage workflow, but then without doing
# the code-coverage.
quicktest:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: ['ubuntu-latest', 'windows-latest']
php: ['7.2', 'latest']

name: "QuickTest: PHP ${{ matrix.php }}"
name: "QuickTest: PHP ${{ matrix.php }} (${{ matrix.os == 'ubuntu-latest' && 'Linux' || 'Win' }})"

steps:
- name: Checkout code
Expand All @@ -52,11 +53,16 @@ jobs:
custom-cache-suffix: $(date -u "+%Y-%m")

- name: 'PHPCS: set the path to PHP'
run: php bin/phpcs --config-set php_path php
run: php "bin/phpcs" --config-set php_path php

- name: 'PHPUnit: run the tests'
run: vendor/bin/phpunit tests/AllTests.php --no-coverage
- name: 'PHPUnit: run the full test suite'
if: ${{ matrix.os != 'windows-latest' }}
run: php "vendor/bin/phpunit" --no-coverage

- name: 'PHPUnit: run tests which may have different outcomes on Windows'
if: ${{ matrix.os == 'windows-latest' }}
run: php "vendor/bin/phpunit" --group Windows --no-coverage

# Note: The code style check is run as an integration test.
- name: 'PHPCS: check code style without cache, no parallel'
run: php bin/phpcs --no-cache --parallel=1
run: php "bin/phpcs" --no-cache --parallel=1
65 changes: 40 additions & 25 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ jobs:
# - custom_ini: Whether to run with specific custom ini settings to hit very specific
# code conditions.
matrix:
os: ['ubuntu-latest', 'windows-latest']
php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5']
custom_ini: [false]

Expand All @@ -102,9 +103,11 @@ jobs:

# Extra builds running only the unit tests with different PHP ini settings.
- php: '7.4'
os: 'ubuntu-latest'
custom_ini: true

name: "PHP: ${{ matrix.php }} ${{ matrix.custom_ini && ' with custom ini settings' || '' }}"
# yamllint disable-line rule:line-length
name: "PHP: ${{ matrix.php }} ${{ matrix.custom_ini && ' with custom ini settings' || '' }} (${{ matrix.os == 'ubuntu-latest' && 'Linux' || 'Win' }})"

continue-on-error: ${{ matrix.php == '8.5' }}

Expand All @@ -114,6 +117,7 @@ jobs:

- name: Setup ini config
id: set_ini
shell: bash
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.
Expand Down Expand Up @@ -142,20 +146,20 @@ jobs:
# Note: The code style check is run multiple times against every PHP version
# as it also acts as an integration test.
- name: 'PHPCS: set the path to PHP'
run: php bin/phpcs --config-set php_path php
run: php "bin/phpcs" --config-set php_path php

- name: 'PHPUnit: run the tests without code coverage'
- name: 'PHPUnit: run the full test suite without code coverage'
if: ${{ matrix.skip_tests != true }}
run: vendor/bin/phpunit --no-coverage
run: php "vendor/bin/phpunit" --no-coverage

- name: 'PHPCS: check code style without cache, no parallel'
if: ${{ matrix.custom_ini == false && matrix.php != '7.4' }}
run: php bin/phpcs --no-cache --parallel=1
run: php "bin/phpcs" --no-cache --parallel=1

- name: 'PHPCS: check code style to show results in PR'
if: ${{ matrix.custom_ini == false && matrix.php == '7.4' }}
id: phpcs
run: php bin/phpcs --no-cache --parallel=1 --report-full --report-checkstyle=./phpcs-report.xml
run: php "bin/phpcs" --no-cache --parallel=1 --report-full --report-checkstyle=./phpcs-report.xml

- name: Show PHPCS results in PR
if: ${{ always() && steps.phpcs.outcome == 'failure' && matrix.php == '7.4' }}
Expand All @@ -173,40 +177,42 @@ jobs:
run: php phpcs.phar

coverage:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: ['ubuntu-latest', 'windows-latest']
php: ['7.2', '8.4']
custom_ini: [false]

include:
- php: '7.2'
custom_ini: false
# Also run one coverage build with custom ini settings.
- php: '8.1'
os: 'ubuntu-latest'
custom_ini: true
- php: '8.4'
custom_ini: false

name: "Coverage: ${{ matrix.php }} ${{ matrix.custom_ini && ' with custom ini settings' || '' }}"
# 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: 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.
# Also turn on error_reporting to ensure all notices are shown.
if [[ ${{ matrix.custom_ini }} == 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"
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: ${{ steps.set_ini.outputs.PHP_INI }}
ini-values: error_reporting=-1, display_errors=On${{ steps.set_ini.outputs.PHP_INI }}
coverage: xdebug

# Install dependencies and handle caching in one go.
Expand All @@ -219,38 +225,47 @@ jobs:

- name: Grab PHPUnit version
id: phpunit_version
shell: bash
# yamllint disable-line rule:line-length
run: echo "VERSION=$(vendor/bin/phpunit --version | grep --only-matching --max-count=1 --extended-regexp '\b[0-9]+\.[0-9]+')" >> "$GITHUB_OUTPUT"
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
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: vendor/bin/phpunit --coverage-cache ./build/phpunit-cache --warm-coverage-cache
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: ${{ steps.phpunit_version.outputs.VERSION < '9.3' }}
run: vendor/bin/phpunit
if: ${{ matrix.os != 'windows-latest' && steps.phpunit_version.outputs.VERSION < '9.3' }}
run: php "vendor/bin/phpunit"

- name: "Run the unit tests with code coverage (PHPUnit 9.3+)"
if: ${{ steps.phpunit_version.outputs.VERSION >= '9.3' }}
run: vendor/bin/phpunit --coverage-cache ./build/phpunit-cache
if: ${{ matrix.os != 'windows-latest' && steps.phpunit_version.outputs.VERSION >= '9.3' }}
run: php "vendor/bin/phpunit" --coverage-cache ./build/phpunit-cache

- 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" --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" --group Windows --coverage-cache ./build/phpunit-cache

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

coveralls-finish:
Expand Down

0 comments on commit 64cec98

Please sign in to comment.