From cef9b35143665c5628a0dcddb62d0e365300682e Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 11 Nov 2024 22:45:29 +0100 Subject: [PATCH] GH Actions: run tests on Windows too 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. --- .github/workflows/quicktest.yml | 18 ++++++--- .github/workflows/test.yml | 65 ++++++++++++++++++++------------- 2 files changed, 52 insertions(+), 31 deletions(-) diff --git a/.github/workflows/quicktest.yml b/.github/workflows/quicktest.yml index 0a22480fa8..d2b6b8db9f 100644 --- a/.github/workflows/quicktest.yml +++ b/.github/workflows/quicktest.yml @@ -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 @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 956b1fc4e3..774c2a4841 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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] @@ -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' }} @@ -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. @@ -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' }} @@ -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' 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. @@ -219,14 +225,15 @@ 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. @@ -234,15 +241,23 @@ jobs: # 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() }} @@ -250,7 +265,7 @@ jobs: 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: