From e5d7a7312438f7dd1ab2d619fd98e9735a104bfe Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 2 Oct 2021 09:25:06 +0200 Subject: [PATCH] CI: switch to GitHub Actions - step 2: linting This commit: * Adds a GH Actions workflow for the PHP lint CI check. * Removes the, now redundant, `.travis.yml` configuration. * Updates the `.gitattributes` file to reflect the removal of the `.travis.yml` file. * Updates the "Build Status" badge in the Readme to use the results from the GH `Lint` Action runs. Notes: 1. Builds will run on: - Select pushes using branch filtering similar to before. - All pull requests. - When manually triggered. Note: manual triggering of builds has to be [explicitly allowed](https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/). This is not a feature which is enabled by default. 2. The default ini settings used by the `setup-php` action are based on the `php.ini-production` configuration. This means that `error_reporting=E_ALL & ~E_DEPRECATED & ~E_STRICT` and `display_errors` is set to `Off`. For the purposes of CI, especially for linting and testing code, I'd recommend running with `-1` and `display_errors=On` to ensure **all** PHP notices are shown. Note: the defaults will be changed in the next major of `setup-php` to be based on the `php.ini-develop` configuration, but that may still be a while off. Refs: * https://github.com/shivammathur/setup-php/issues/450 * https://github.com/shivammathur/setup-php/issues/469 3. While the `setup-php` action offers the ability to [install the PHAR file for Parallel Lint](https://github.com/shivammathur/setup-php#wrench-tools-support), I've elected not to use that option as it would mean that we would not be able to use the `composer lint` script in the workflow, which would mean that the CLI arguments would have to be duplicated between the `composer.json` file and the `lint.yml` file. IMO, that would make this a typical point of failure where updates would be done in one, but not the other. If, at some point in the future, the Parallel Lint tool would start to support a config file for the CLI arguments, removing this point of failure, this choice can be (and should be) revisited. 4. Composer dependency downloads will be cached for faster builds using a [predefined GH action](https://github.com/marketplace/actions/install-composer-dependencies) specifically created for this purpose. The alternative would be to handle the caching manually, which would add three extra steps to the script. Note: Caching works differently between Travis and GH Actions. On GH Actions, once a cache has been created, it can't be updated. It can only be replaced by a new cache with a different key. As the PHP version, the `composer.json` and a potential `composer.lock` hash are all part of the key used by the above mentioned action, this difference should not have a significant impact. Ref: https://docs.github.com/en/actions/advanced-guides/caching-dependencies-to-speed-up-workflows 5. The Linting check will display the results inline in the GitHub code view using the [cs2pr](https://github.com/staabm/annotate-pull-request-from-checkstyle) tool. Differences with the Travis implementation: * There is a minor difference in the branch filtering being done for `push` events. Travis accepted PCRE regexes for the filtering. GH Actions uses glob patterns. The glob patterns now in place match the regexes as closely as possible, but are not an exact match to the "old" patterns. They should be sufficient for our purposes though. * The toggle for running `composer install` with or without `--ignore-platform-reqs` has not been implemented as it is currently unnecessary. * Linting will now also be executed against PHP 8.1 and 8.2 (nightly), neither of which has yet been released. Linting runs against either of these two PHP versions will be "allowed to fail" for the time being. Note: if any of the "allowed to fail" jobs actually fail, the workflow will show as succesfull, but there will still be a red `x` next to a PR. This is a known issue in GHA: https://github.com/actions/toolkit/issues/399 There are work-arounds possible for this, however, the work-arounds would hide failures even more, meaning that chances are they won't be seen until they actually become a problem (no longer allowed to fail), which is too late. --- .gitattributes | 1 - .github/workflows/lint.yml | 47 ++++++++++++++++++++++++++++++++++++++ .travis.yml | 41 --------------------------------- README.md | 2 +- 4 files changed, 48 insertions(+), 43 deletions(-) create mode 100644 .github/workflows/lint.yml delete mode 100644 .travis.yml diff --git a/.gitattributes b/.gitattributes index 590ae54..27cb9f4 100644 --- a/.gitattributes +++ b/.gitattributes @@ -9,7 +9,6 @@ .gitignore export-ignore .phpcs.xml export-ignore .phpcs.xml.dist export-ignore -.travis.yml export-ignore phpcs.xml export-ignore phpcs.xml.dist export-ignore /.cache export-ignore diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..8d01bf5 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,47 @@ +name: Lint + +on: + # Run on pushes to select branches and on all pull requests. + push: + branches: + - master + - 'release/[0-9]+.[0-9]+*' + - 'hotfix/[0-9]+.[0-9]+*' + pull_request: + # Allow manually triggering the workflow. + workflow_dispatch: + +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.1' || matrix.php_version == '8.2' }} + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php_version }} + ini-values: error_reporting=-1, display_errors=On + coverage: none + tools: cs2pr + + # 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: Lint against parse errors + run: composer lint -- --checkstyle | cs2pr diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 94e37ef..0000000 --- a/.travis.yml +++ /dev/null @@ -1,41 +0,0 @@ -os: linux -language: php - -cache: - directories: - - .cache - - vendor - # Cache directory for older Composer versions. - - $HOME/.composer/cache/files - # Cache directory for more recent Composer versions. - - $HOME/.cache/composer/files - -branches: - only: - - master - - /^release\/\d+\.\d+(\.\d+)?(-\S*)?$/ - - /^hotfix\/\d+\.\d+(\.\d+)?(-\S*)?$/ - -php: - - 8.0 - - 7.4 - - 7.0 - - 5.6 - -jobs: - fast_finish: true - -before_install: - - phpenv config-rm xdebug.ini || echo 'No xdebug config.' - -install: - - | - if [[ $TRAVIS_PHP_VERSION == "nightly" ]]; then - composer install --prefer-dist --no-interaction --ignore-platform-reqs - else - composer install --prefer-dist --no-interaction - fi - -script: -# PHP Linting -- composer lint diff --git a/README.md b/README.md index 40eb69b..23ff8b6 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ [![CS](https://github.com/Yoast/i18n-module/actions/workflows/cs.yml/badge.svg)](https://github.com/Yoast/i18n-module/actions/workflows/cs.yml) -[![Build Status](https://travis-ci.org/Yoast/i18n-module.png?branch=master)](https://travis-ci.org/Yoast/i18n-module) +[![Lint](https://github.com/Yoast/i18n-module/actions/workflows/lint.yml/badge.svg)](https://github.com/Yoast/i18n-module/actions/workflows/lint.yml) [![Code Climate](https://codeclimate.com/github/Yoast/i18n-module/badges/gpa.svg)](https://codeclimate.com/github/Yoast/i18n-module) # Yoast i18n module