Skip to content

Commit

Permalink
CI: switch to GitHub Actions - step 2: linting and unit tests
Browse files Browse the repository at this point in the history
This commit:
* Adds a GH Actions workflow for the PHP lint and the PHPUnit CI checks.
* Removes the, now redundant, `.travis.yml` configuration.
* Updates the `.gitattributes` file to reflect the removal of the `.travis.yml` file.
* Adds a "Build Status" badge to the Readme to use the results from this particular GH Actions run.

Notes:
1. Builds will run on:
    - All pushes and 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`, `display_errors` is set to `Off` and `zend.assertions` is set to `-1` (= do not compile).
    For the purposes of CI, especially for linting and testing code, I'd recommend running with `zend.assertions=-1, `error_reporting=-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:
    * shivammathur/setup-php#450
    * shivammathur/setup-php#469
3. While the `setup-php` action offers the ability to [install the PHAR files for Parallel Lint and PHPUnit](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 `test.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 Composer install step for PHP 8.2 is special cased for now as PHPUnit 9.x does not allow for installation on PHP 8.2 yet.
6. 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:
* Linting and running of the tests will now also be executed against PHP 8.1 and 8.2 (nightly), neither of which has yet been released.
    Builds 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 successful, 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.
  • Loading branch information
jrfnl committed Oct 2, 2021
1 parent d2e4bca commit c035334
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 52 deletions.
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -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
/phpunit.xml export-ignore
Expand Down
58 changes: 58 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Test

on:
# Run on all pushes and on all pull requests.
push:
pull_request:
# Allow manually triggering the workflow.
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
php_version: ['5.3', '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2']

name: "Lint and test: 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: zend.assertions=1, error_reporting=-1, display_errors=On
coverage: none
tools: cs2pr

# YoastCS has a minimum PHP requirement of 5.4, so remove it and hard require Parallel Lint.
- name: Adjust Composer dependencies (PHP 5.3)
if: matrix.php_version == '5.3'
run: |
composer remove --dev --no-update --no-scripts yoast/yoastcs
composer require --dev --no-update --no-scripts php-parallel-lint/php-parallel-lint
# Install dependencies and handle caching in one go.
# @link https://github.com/marketplace/actions/install-composer-dependencies
- name: Install Composer dependencies (PHP < 8.2)
if: matrix.php_version != '8.2'
uses: ramsey/composer-install@v1

- name: Install Composer dependencies (PHP 8.2)
if: matrix.php_version == '8.2'
uses: ramsey/composer-install@v1
with:
composer-options: "--ignore-platform-req=php"

- name: Lint against parse errors
run: composer lint -- --checkstyle | cs2pr

- name: Run the unit tests
run: vendor/bin/phpunit
51 changes: 0 additions & 51 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[![CS](https://github.com/Yoast/whip/actions/workflows/cs.yml/badge.svg)](https://github.com/Yoast/whip/actions/workflows/cs.yml)
[![Test](https://github.com/Yoast/whip/actions/workflows/test.yml/badge.svg)](https://github.com/Yoast/whip/actions/workflows/test.yml)

# whip
A WordPress package to nudge users to upgrade their software versions (starting with PHP)
Expand Down

0 comments on commit c035334

Please sign in to comment.