diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000000..1e80c17d06e --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,75 @@ +name: Lint + +on: + # Run on pushes to select branches and on all pull requests. + push: + branches: + - master + - trunk + - 'release/**' + - 'hotfix/[0-9]+.[0-9]+*' + - 'feature/**' + 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 + +jobs: + lint: + runs-on: ubuntu-latest + + strategy: + matrix: + # Lint against the highest/lowest supported versions of each PHP major. + # And also do a run against "nightly" (the current dev version of PHP). + php_version: ['5.6', '7.0', '7.4', '8.0', '8.1', '8.2'] + + name: "Lint: PHP ${{ matrix.php_version }}" + + # Allow builds to fail on as-of-yet unreleased PHP versions. + continue-on-error: ${{ matrix.php_version == '8.2' }} + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + # For the purpose of linting the code, we need the `vendor-prefixed` directory to + # be created as the prefixed code should be linted to ensure there are no parse errors + # in the generated code against any of the supported PHP versions. + # The prefix-dependencies task makes use of reflection-based PHP code that only works on PHP > 7.2. + - name: Install PHP 7.x for generating the vendor_prefixed directory + uses: shivammathur/setup-php@v2 + with: + php-version: 7.2 + coverage: none + + - name: Install Composer dependencies and generate vendor_prefixed directory + uses: ramsey/composer-install@v2 + + # Remove packages which are not PHP cross-version compatible and only used for the prefixing. + # - humbug/php-scoper is only needed to actually do the prefixing, so won't be shipped anyway. + # - league/oauth2-client and its dependencies *are* the packages being prefixed, so linting the + # prefixed versions is sufficient. + - name: Delete dependencies which are not cross-version compatible + run: composer remove --dev --no-scripts humbug/php-scoper league/oauth2-client + + - name: Install PHP for the actual linting + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php_version }} + ini-values: zend.assertions=1, error_reporting=-1, display_errors=On + coverage: none + tools: cs2pr + + # We don't need to remove and reinstall the Composer dependencies as + # the only thing we'll use is the PHP-Parallel-Lint package (PHP 5.3+) + # and that means the package is compatible with all supported PHP versions, + # so we can just use the version installed on PHP 7.2. + + - name: Lint against parse errors + run: composer lint -- --checkstyle | cs2pr diff --git a/.travis.yml b/.travis.yml index e830edb65d0..783da7912bd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,17 +29,16 @@ jobs: - php: 7.3.24 env: WP_VERSION=latest WP_MULTISITE=1 COVERAGE=1 - php: 5.6 - env: WP_VERSION=5.8 WP_MULTISITE=1 PHPLINT=1 PHPUNIT=1 + env: WP_VERSION=5.8 WP_MULTISITE=1 PHPUNIT=1 # Use 'trusty' to test against MySQL 5.6, 'xenial' contains 5.7 by default. dist: trusty - php: 7.3 env: WP_VERSION=trunk PHPUNIT=1 - php: 7.4 - env: WP_VERSION=latest PHPUNIT=1 PHPLINT=1 + env: WP_VERSION=latest PHPUNIT=1 - php: 8.0 - env: WP_VERSION=latest PHPUNIT=1 PHPLINT=1 + env: WP_VERSION=latest PHPUNIT=1 - php: "nightly" - env: PHPLINT=1 - stage: 🚀 deployment name: "Deploy to S3" if: branch = deploy # Only build when on the `deploy` branch, this functionality is not used yet and is taking a long time to complete. @@ -143,7 +142,7 @@ install: - | if [[ ${TRAVIS_PHP_VERSION:0:1} == "8" || $TRAVIS_PHP_VERSION == "nightly" ]]; then travis_retry composer install --no-interaction --ignore-platform-reqs --no-scripts --no-suggest - elif [[ "$PHPUNIT" == "1" || "$COVERAGE" == "1" || "$PHPLINT" == "1" ]]; then + elif [[ "$PHPUNIT" == "1" || "$COVERAGE" == "1" ]]; then # Run composer update as we have dev dependencies locked at PHP ^7.0 versions. travis_retry composer update --no-interaction --no-scripts travis_retry composer install --no-interaction --no-scripts @@ -226,13 +225,6 @@ script: yarn test travis_time_finish && travis_fold end "JavaScript.tests" fi - # PHP Linting - - | - if [[ "$PHPLINT" == "1" ]]; then - travis_fold start "PHP.check" && travis_time_start - composer lint - travis_time_finish && travis_fold end "PHP.check" - fi # PHP Unit - | if [[ "$PHPUNIT" == "1" && ${TRAVIS_PHP_VERSION:0:1} != "8" && $TRAVIS_PHP_VERSION != "nightly" ]]; then diff --git a/README.md b/README.md index b158e7b3070..9732b80ee00 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Yoast SEO [![CS](https://github.com/Yoast/wordpress-seo/actions/workflows/cs.yml/badge.svg)](https://github.com/Yoast/wordpress-seo/actions/workflows/cs.yml) +[![Lint](https://github.com/Yoast/wordpress-seo/actions/workflows/lint.yml/badge.svg)](https://github.com/Yoast/wordpress-seo/actions/workflows/lint.yml) [![Build Status](https://api.travis-ci.com/Yoast/wordpress-seo.svg?branch=master)](https://travis-ci.com/Yoast/wordpress-seo) [![Stable Version](https://poser.pugx.org/yoast/wordpress-seo/v/stable.svg)](https://packagist.org/packages/yoast/wordpress-seo) [![License](https://poser.pugx.org/yoast/wordpress-seo/license.svg)](https://packagist.org/packages/yoast/wordpress-seo) diff --git a/composer.json b/composer.json index 2286e52c9f3..22abc2e5e94 100644 --- a/composer.json +++ b/composer.json @@ -64,10 +64,10 @@ "@php ./vendor/phpunit/phpunit/phpunit -c phpunit-integration.xml.dist" ], "lint": [ - "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --show-deprecated --exclude vendor --exclude vendor_prefixed --exclude node_modules --exclude .git" + "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --show-deprecated --exclude vendor --exclude node_modules --exclude .git" ], "lint-files": [ - "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint --show-deprecated" + "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint -e php --show-deprecated" ], "lint-branch": [ "Yoast\\WP\\SEO\\Composer\\Actions::lint_branch"