From 65143ee110e47613b08cacca99455a175313e700 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 3 Mar 2021 02:29:14 +0100 Subject: [PATCH 1/2] CI: switch to GitHub Actions - step 1: sniff and lint stage This commit: * Adds a GH Actions workflow for the CI checks which were previously run on Travis in the `sniff` and `lint` stages. For the badge and workflow display, the name `BasicQA` seems an appropriately descriptive name. * Removes that part of the `.travis.yml` configuration. * Removes a duplicate line in the `bin/xml-lint` script used by this workflow. Notes: 1. In the Travis script, these checks were in two separate stages. I've now combined them into one workflow `job`. In GH Actions, the environment has to be setup as part of the workflow. And as the environment needed for these checks is largely the same, combining the checks into one workflow simplifies the script and reduced duplication. 2. Builds will run on all pushes and on pull requests, with the exception of pushes just modifying files which are irrelevant to this workflow. 3. The workflow can be manually (re-)triggered if needs be. 4. Any violations reported by the XML validation against the XSD schema, as well as coming from the PHPCS run, are set up to be shown in-line in the pull request to easily see what line in the pull request causes a build to fail. --- .github/workflows/basics.yml | 62 ++++++++++++++++++++++++++++++++++++ .travis.yml | 45 +------------------------- bin/xml-lint | 1 - 3 files changed, 63 insertions(+), 45 deletions(-) create mode 100644 .github/workflows/basics.yml diff --git a/.github/workflows/basics.yml b/.github/workflows/basics.yml new file mode 100644 index 00000000..84b6d850 --- /dev/null +++ b/.github/workflows/basics.yml @@ -0,0 +1,62 @@ +name: BasicQA + +on: + # Run on all pushes and on all pull requests. + # Prevent the "push" build from running when there are only irrelevant changes. + push: + paths-ignore: + - '**.md' + pull_request: + # Allow manually triggering the workflow. + workflow_dispatch: + +jobs: + checkcs: + name: 'Basic CS and QA checks' + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + coverage: none + tools: cs2pr + + - name: 'Lint PHP against parse errors' + run: ./bin/php-lint + + - name: Install xmllint + run: sudo apt-get install --no-install-recommends -y libxml2-utils + + # Show XML violations inline in the file diff. + # @link https://github.com/marketplace/actions/xmllint-problem-matcher + - uses: korelstar/xmllint-problem-matcher@v1 + + # Validate the composer.json file. + # @link https://getcomposer.org/doc/03-cli.md#validate + - name: Validate Composer installation + run: composer validate --no-check-all --strict + + - name: 'Composer: adjust dependencies' + # Using PHPCS `master` as an early detection system for bugs upstream. + run: composer require --no-update --no-scripts squizlabs/php_codesniffer:"dev-master" + + # 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@v1" + + - name: 'Validate XML against schema and check code style' + run: ./bin/xml-lint + + # Check the code-style consistency of the PHP files. + - name: Check PHP code style + continue-on-error: true + run: vendor/bin/phpcs --report-full --report-checkstyle=./phpcs-report.xml + + - name: Show PHPCS results in PR + run: cs2pr ./phpcs-report.xml diff --git a/.travis.yml b/.travis.yml index f2fd62b8..160a49b1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,54 +21,11 @@ php: - 7.4 - "nightly" -# Rather than a `matrix` property, we use build stages. This allows early -# build failure for basic linting and sniffing issues. -# @link https://docs.travis-ci.com/user/build-stages/ - -stages: - - lint - - sniff - - test - jobs: allow_failures: - php: "nightly" include: - - - stage: lint - php: 7.4 - env: PHPCS_BRANCH="dev-master" - before_install: phpenv config-rm xdebug.ini || echo 'No xdebug config.' - install: skip - cache: skip - script: - # Lint the PHP files against parse errors. - - ./bin/php-lint - - # Add PHPCS locally for the XSD. - - travis_retry composer require squizlabs/php_codesniffer - # Validate the XML files and check the code-style consistency of the XML files. - - ./bin/xml-lint - - # Validate the composer.json file. - # @link https://getcomposer.org/doc/03-cli.md#validate - - composer validate --no-check-all --strict - addons: - apt: - packages: - - libxml2-utils - - - stage: sniff - php: 7.4 - env: PHPCS_BRANCH="dev-master" - before_install: phpenv config-rm xdebug.ini || echo 'No xdebug config.' - install: travis_retry composer install --no-suggest - script: - # Run PHPCS against VIPCS. - - ./bin/phpcs - # Builds which need a different distro or specific PHPCS version. - - stage: test - php: 8.0 env: PHPCS_BRANCH="dev-master" - php: 8.0 @@ -96,7 +53,7 @@ before_install: # 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. - | - if [[ "$TRAVIS_BUILD_STAGE_NAME" != "Sniff" && $PHPCS_BRANCH != "dev-master" ]]; then + if [[ $PHPCS_BRANCH != "dev-master" ]]; then echo 'error_reporting = E_ALL & ~E_DEPRECATED' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini fi diff --git a/bin/xml-lint b/bin/xml-lint index a8e295a3..6ab4e113 100755 --- a/bin/xml-lint +++ b/bin/xml-lint @@ -9,7 +9,6 @@ # ./bin/xml-lint # Validate the ruleset XML files. -#xmllint --noout --schema ./vendor/squizlabs/php_codesniffer/phpcs.xsd ./*/ruleset.xml xmllint --noout --schema ./vendor/squizlabs/php_codesniffer/phpcs.xsd ./*/ruleset.xml # Check the code-style consistency of the XML files. From 7b04b16cb2ff034b769b00c41d8605f7ca6041a0 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 3 Mar 2021 03:04:40 +0100 Subject: [PATCH 2/2] CI: switch to GitHub Actions - step 2: test stage This commit: * Adds a GH Actions workflow for the CI check which was previously run on Travis in the `test` stage. * Removes the, now redundant, `.travis.yml` configuration. * Updates the `.gitattributes` file. Notes: 1. For the time being, I've commented out the job against PHP 8.1/nightly as - no matter what I've tried - I can't even get the tests running at the moment, so they would only ever fail. Once PHP 8.1 starts to release alpha/beta/RC builds, further testing should be done to attempt to get this working. Notes/current findings: - With PHPUnit 7.x on PHP 8.1, using a configuration file will block the tests from running. - In some cases (PHPCS itself, PHPCSExtra), I managed to get the tests running by passing all relevant information via the command-line and actively ignoring the configuration file using `--no-configuration`. Unfortunately, that does not seem to work in this case. Further investigation is needed. - Based on the (running) tests for PHPCSExtra on PHP 8.1, an incompatibility with PHP 8.1 in PHPCS itself has already been discovered. A fix for this has been pulled, but not yet merged: squizlabs/php_codesniffer 3250 --- .gitattributes | 1 - .github/workflows/test.yml | 101 +++++++++++++++++++++++++++++++++++++ .travis.yml | 76 ---------------------------- 3 files changed, 101 insertions(+), 77 deletions(-) create mode 100644 .github/workflows/test.yml delete mode 100644 .travis.yml diff --git a/.gitattributes b/.gitattributes index 5727a3b9..a4ac8db3 100644 --- a/.gitattributes +++ b/.gitattributes @@ -8,7 +8,6 @@ /.gitattributes export-ignore /.gitignore export-ignore /.phpcs.xml.dist export-ignore -/.travis.yml export-ignore /phpunit.xml.dist export-ignore /.github export-ignore /bin export-ignore diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..2ea218da --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,101 @@ +name: Test + +on: + # Run on all pushes and on all pull requests. + # Prevent the "push" build from running when there are only irrelevant changes. + push: + paths-ignore: + - '**.md' + pull_request: + # Allow manually triggering the workflow. + workflow_dispatch: + +jobs: + test: + runs-on: ubuntu-latest + + strategy: + # Keys: + # - php: The PHP versions to test against. + # - phpcs_version: The PHPCS versions to test against. + # IMPORTANT: test runs shouldn't fail because of PHPCS being incompatible with a PHP version. + # - PHPCS will run without errors on PHP 5.4 - 7.4 on any supported version. + # - PHP 8.0 needs PHPCS 3.5.7+ to run without errors. + # - The `wpcs_version` key is added to allow additional test builds when multiple WPCS versions + # would be supported. As, at this time, only the latest stable release of WPCS is supported, + # no additional versions are included in the array. + # - experimental: Whether the build is "allowed to fail". + matrix: + php: ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4'] + phpcs_version: ['3.5.5', 'dev-master'] + wpcs_version: ['2.3.*'] + experimental: [false] + + include: + # Complete the matrix by adding PHP 8.0, but only test against compatible PHPCS versions. + - php: '8.0' + phpcs_version: 'dev-master' + wpcs_version: '2.3.*' + experimental: false + - php: '8.0' + # PHPCS 3.5.7 is the lowest version of PHPCS which supports PHP 8.0. + phpcs_version: '3.5.7' + wpcs_version: '2.3.*' + experimental: false + + # Experimental builds. These are allowed to fail. + #- php: '8.1' + # phpcs_version: 'dev-master' + # wpcs_version: '2.3.*' + # experimental: true + + name: "Test: PHP ${{ matrix.php }} - PHPCS ${{ matrix.phpcs_version }} - WPCS ${{ matrix.wpcs_version }}" + + continue-on-error: ${{ matrix.experimental }} + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + # 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.phpcs_version }}" != "dev-master" ]]; then + echo '::set-output name=PHP_INI::error_reporting=E_ALL & ~E_DEPRECATED' + else + echo '::set-output name=PHP_INI::error_reporting=E_ALL' + fi + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + ini-values: ${{ steps.set_ini.outputs.PHP_INI }} + coverage: none + + - name: 'Composer: set PHPCS and WPCS versions for tests' + run: | + composer require --no-update --no-scripts squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}" + composer require --no-update --no-scripts wp-coding-standards/wpcs:"${{ matrix.wpcs_version }}" + + # 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, '8' ) == false }} + uses: "ramsey/composer-install@v1" + + # PHPUnit 7.x does not allow for installation on PHP 8, so ignore platform + # requirements to get PHPUnit 7.x to install on nightly. + - name: Install Composer dependencies - with ignore platform + if: ${{ startsWith( matrix.php, '8' ) }} + uses: "ramsey/composer-install@v1" + with: + composer-options: --ignore-platform-reqs + + - name: Run the unit tests + run: ./bin/unit-tests + + - name: Run the ruleset tests + run: ./bin/ruleset-tests diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 160a49b1..00000000 --- a/.travis.yml +++ /dev/null @@ -1,76 +0,0 @@ -language: php -os: linux -dist: xenial - -env: - # `master` is now 3.x. - - PHPCS_BRANCH="dev-master" - # Lowest supported release in the 3.x series with which VIPCS is compatible. - - PHPCS_BRANCH="3.5.5" - -cache: - directories: - - $HOME/.cache/composer/files - -php: - - 5.6 - - 7.0 - - 7.1 - - 7.2 - - 7.3 - - 7.4 - - "nightly" - -jobs: - allow_failures: - - php: "nightly" - include: - # Builds which need a different distro or specific PHPCS version. - - php: 8.0 - env: PHPCS_BRANCH="dev-master" - - php: 8.0 - # PHPCS 3.5.7 is the lowest version of PHPCS which supports PHP 8.0. - env: PHPCS_BRANCH="3.5.7" - - php: 5.5 - dist: trusty - env: PHPCS_BRANCH="dev-master" - - php: 5.5 - dist: trusty - env: PHPCS_BRANCH="3.5.5" - - php: 5.4 - dist: trusty - env: PHPCS_BRANCH="dev-master" - - php: 5.4 - dist: trusty - env: PHPCS_BRANCH="3.5.5" - -before_install: - # Speed up build time by disabling Xdebug. - # https://johnblackbourn.com/reducing-travis-ci-build-times-for-wordpress-projects/ - # https://twitter.com/kelunik/status/954242454676475904 - - phpenv config-rm xdebug.ini || echo 'No xdebug config.' - - # 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. - - | - if [[ $PHPCS_BRANCH != "dev-master" ]]; then - echo 'error_reporting = E_ALL & ~E_DEPRECATED' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini - fi - -install: - - travis_retry composer require squizlabs/php_codesniffer:"$PHPCS_BRANCH" --no-update --no-suggest --no-scripts - - | - if [[ $TRAVIS_PHP_VERSION == "nightly" || $TRAVIS_PHP_VERSION == "8.0" ]]; then - # PHPUnit 7.x does not allow for installation on PHP 8, so ignore platform - # requirements to get PHPUnit 7.x to install on nightly. - travis_retry composer install --ignore-platform-reqs --no-suggest - else - travis_retry composer install --no-suggest - fi - -script: - # Run the unit tests. - - ./bin/unit-tests - - # Run ruleset tests. - - ./bin/ruleset-tests