YoastCS: fix some tests not running #105
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test | |
on: | |
# Run on pushes to `main` and on all pull requests. | |
push: | |
branches: | |
- main | |
- develop | |
paths-ignore: | |
- '**.md' | |
pull_request: | |
# Allow manually triggering the workflow. | |
workflow_dispatch: | |
# Cancels all previous workflow runs for the same branch that have not yet completed. | |
concurrency: | |
# The concurrency group contains the workflow name and the branch name. | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
# Note: while WPCS 3.0.0 is not (yet) supported by YoastCS, the "highest" release for WPCS should use | |
# the last stable WPCS release supported by YoastCS, i.e. `2.3.0`. | |
# Once support for WPCS 3.0.0 has been added, the matrix should switch (back) using `dev-develop`. | |
env: | |
PHPCS_HIGHEST: 'dev-master' | |
WPCS_HIGHEST: '2.3.0' | |
jobs: | |
#### TEST STAGE #### | |
test: | |
if: ${{ github.ref != 'refs/heads/develop' }} | |
runs-on: ubuntu-latest | |
strategy: | |
# Keys: | |
# - experimental: Whether the build is "allowed to fail". | |
matrix: | |
# The GHA matrix works different from Travis. | |
# You can define jobs here and then augment them with extra variables in `include`, | |
# as well as add extra jobs in `include`. | |
# @link https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix | |
# | |
# The matrix is set up so as not to duplicate the builds which are run for code coverage. | |
php_version: ['5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '8.0', '8.1', '8.2'] | |
cs_dependencies: ['lowest', 'highest'] | |
experimental: [false] | |
include: | |
# Experimental builds. These are allowed to fail. | |
# PHP nightly | |
- php_version: '8.3' | |
cs_dependencies: 'highest' | |
experimental: true | |
# Test against WPCS unstable. Re-enable when WPCS is not in dev for the next major. | |
#- php_version: '8.0' | |
# cs_dependencies: 'highest' | |
# experimental: true | |
# Test against the next major of PHPCS. Temporarily disabled due to upstream bugs. | |
#- php_version: '7.4' | |
# cs_dependencies: 'highest' | |
# phpcs_version: '4.0.x-dev' | |
# experimental: true | |
name: "Test${{ matrix.cs_dependencies == 'highest' && ' + Lint' || '' }}: PHP ${{ matrix.php_version }} - CS Deps ${{ matrix.cs_dependencies }}" | |
continue-on-error: ${{ matrix.experimental }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
# On stable PHPCS versions, allow for PHP deprecation notices. | |
# Unit tests don't need to fail on those for stable releases where those issues won't get fixed anymore. | |
- name: Setup ini config | |
id: set_ini | |
run: | | |
if [[ "${{ matrix.cs_dependencies }}" != "highest" && "${{ matrix.phpcs_version }}" != "4.0.x-dev" ]]; then | |
echo 'PHP_INI=error_reporting=E_ALL & ~E_DEPRECATED, display_errors=On' >> $GITHUB_OUTPUT | |
else | |
echo 'PHP_INI=error_reporting=-1, display_errors=On' >> $GITHUB_OUTPUT | |
fi | |
- name: Install PHP | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: ${{ matrix.php_version }} | |
ini-values: ${{ steps.set_ini.outputs.PHP_INI }} | |
coverage: none | |
tools: cs2pr | |
env: | |
# Token is needed for the PHPCS 4.x run against source. | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# Set Composer up to download only PHPCS from source for PHPCS 4.x. | |
# The source is needed to get the base testcase from PHPCS. | |
# All other jobs can use `auto`, which is Composer's default value. | |
- name: 'Composer: conditionally prefer source for PHPCS 4.x' | |
if: ${{ startsWith( matrix.phpcs_version, '4' ) }} | |
run: composer config preferred-install.squizlabs/php_codesniffer source | |
- name: 'Composer: adjust CS dependencies (high)' | |
if: ${{ matrix.cs_dependencies == 'highest' }} | |
run: | | |
composer require --no-update --no-scripts squizlabs/php_codesniffer:"${{ env.PHPCS_HIGHEST }}" --no-interaction | |
composer require --no-update --no-scripts wp-coding-standards/wpcs:"${{ env.WPCS_HIGHEST }}" --no-interaction | |
- name: 'Composer: adjust CS dependencies (4.x)' | |
if: ${{ matrix.phpcs_version }} | |
run: | | |
composer require --no-update --no-scripts squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}" --no-interaction | |
- name: 'Composer: conditionally remove PHPCSDevtools for PHPCS 4.x' | |
if: ${{ startsWith( matrix.phpcs_version, '4' ) }} | |
# Remove devtools as it will not (yet) install on PHPCS 4.x. | |
run: composer remove --no-update --dev phpcsstandards/phpcsdevtools --no-interaction | |
# Install dependencies and handle caching in one go. | |
# @link https://github.com/marketplace/actions/install-composer-dependencies | |
- name: Install Composer dependencies - normal | |
if: ${{ startsWith( matrix.php_version, '8' ) == false }} | |
uses: ramsey/composer-install@v2 | |
with: | |
# Bust the cache at least once a month - output format: YYYY-MM. | |
custom-cache-suffix: $(date -u "+%Y-%m") | |
# For PHP 8/"nightly", we need to install with ignore platform reqs as we're still using PHPUnit 7. | |
- name: Install Composer dependencies - with ignore platform | |
if: ${{ startsWith( matrix.php_version, '8' ) }} | |
uses: ramsey/composer-install@v2 | |
with: | |
composer-options: --ignore-platform-req=php+ | |
custom-cache-suffix: $(date -u "+%Y-%m") | |
- name: "Composer: set PHPCS version for tests (low)" | |
if: ${{ matrix.cs_dependencies == 'lowest' }} | |
run: composer update squizlabs/php_codesniffer wp-coding-standards/wpcs --with-dependencies --prefer-lowest --ignore-platform-req=php+ --no-scripts --no-interaction | |
- name: Verify installed versions | |
run: composer info --no-dev | |
- name: Verify installed standards | |
run: vendor/bin/phpcs -i | |
# The results of the linting will be shown inline in the PR via the CS2PR tool. | |
# @link https://github.com/staabm/annotate-pull-request-from-checkstyle/ | |
- name: Lint against parse errors | |
if: ${{ matrix.cs_dependencies == 'highest' }} | |
run: composer lint -- --checkstyle | cs2pr | |
- name: Run the unit tests - PHP 5.4 - 8.0 | |
if: ${{ matrix.php_version < '8.1' }} | |
run: composer test | |
- name: Run the unit tests - PHP 8.1+ | |
if: ${{ matrix.php_version >= '8.1' }} | |
run: composer test -- --no-configuration --bootstrap=./phpunit-bootstrap.php --dont-report-useless-tests | |
#### CODE COVERAGE STAGE #### | |
# N.B.: Coverage is only checked on the lowest and highest stable PHP versions | |
# and a low/high of each major for PHPCS. | |
# These builds are left out off the "test" stage so as not to duplicate test runs. | |
coverage: | |
# No use running the coverage builds if there are failing test builds. | |
needs: test | |
# The default condition is success(), but this is false when one of the previous jobs is skipped | |
if: always() && (needs.test.result == 'success' || needs.test.result == 'skipped') | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
# 7.4 should be updated to 8.2 when higher PHPUnit versions can be supported. | |
php_version: ['5.4', '7.4'] | |
cs_dependencies: ['lowest', 'highest'] | |
name: "Coverage${{ matrix.cs_dependencies == 'highest' && ' + Lint' || '' }}: PHP ${{ matrix.php_version }} - CS Deps ${{ matrix.cs_dependencies }}" | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
# On stable PHPCS versions, allow for PHP deprecation notices. | |
# Unit tests don't need to fail on those for stable releases where those issues won't get fixed anymore. | |
- name: Setup ini config | |
id: set_ini | |
run: | | |
if [[ "${{ matrix.cs_dependencies }}" != "highest" && "${{ matrix.phpcs_version }}" != "4.0.x-dev" ]]; then | |
echo 'PHP_INI=error_reporting=E_ALL & ~E_DEPRECATED, display_errors=On' >> $GITHUB_OUTPUT | |
else | |
echo 'PHP_INI=error_reporting=-1, display_errors=On' >> $GITHUB_OUTPUT | |
fi | |
- name: Install PHP | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: ${{ matrix.php_version }} | |
ini-values: ${{ steps.set_ini.outputs.PHP_INI }} | |
coverage: xdebug | |
tools: cs2pr | |
- name: 'Composer: adjust CS dependencies (high)' | |
if: ${{ matrix.cs_dependencies == 'highest' }} | |
run: | | |
composer require --no-update --no-scripts squizlabs/php_codesniffer:"${{ env.PHPCS_HIGHEST }}" --no-interaction | |
composer require --no-update --no-scripts wp-coding-standards/wpcs:"${{ env.WPCS_HIGHEST }}" --no-interaction | |
# Install dependencies and handle caching in one go. | |
# @link https://github.com/marketplace/actions/install-composer-dependencies | |
- name: Install Composer dependencies | |
uses: "ramsey/composer-install@v2" | |
with: | |
# Bust the cache at least once a month - output format: YYYY-MM. | |
custom-cache-suffix: $(date -u "+%Y-%m") | |
- name: "Composer: set PHPCS version for tests (low)" | |
if: ${{ matrix.cs_dependencies == 'lowest' }} | |
run: composer update squizlabs/php_codesniffer wp-coding-standards/wpcs --with-dependencies --prefer-lowest --ignore-platform-req=php+ --no-scripts --no-interaction | |
- name: Verify installed versions | |
run: composer info --no-dev | |
- name: Verify installed standards | |
run: vendor/bin/phpcs -i | |
# The results of the linting will be shown inline in the PR via the CS2PR tool. | |
# @link https://github.com/staabm/annotate-pull-request-from-checkstyle/ | |
- name: Lint against parse errors | |
if: ${{ matrix.cs_dependencies == 'highest' }} | |
run: composer lint -- --checkstyle | cs2pr | |
- name: Run the unit tests with code coverage | |
run: composer coverage | |
# Uploading the results with PHP Coveralls v1 won't work from GH Actions, so switch the PHP version. | |
- name: Switch to PHP 7.4 | |
if: ${{ success() && matrix.php_version != '7.4' }} | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: 7.4 | |
coverage: none | |
# Global install is used to prevent a conflict with the local composer.lock in PHP 8.0+. | |
- name: Install Coveralls | |
if: ${{ success() }} | |
run: composer global require php-coveralls/php-coveralls:"^2.5.3" --no-interaction | |
- name: Upload coverage results to Coveralls | |
if: ${{ success() }} | |
env: | |
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_TOKEN }} | |
COVERALLS_PARALLEL: true | |
COVERALLS_FLAG_NAME: php-${{ matrix.php_version }}-cs-${{ matrix.cs_dependencies }} | |
run: php-coveralls -v -x build/logs/clover.xml | |
coveralls-finish: | |
needs: coverage | |
if: always() && needs.coverage.result == 'success' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Coveralls Finished | |
uses: coverallsapp/github-action@v2 | |
with: | |
github-token: ${{ secrets.COVERALLS_TOKEN }} | |
parallel-finished: true |