Skip to content

Commit

Permalink
GH Actions: split PHAR build test from other tests
Browse files Browse the repository at this point in the history
As things were in the CI script, the `phpcs` and `phpcbf` Phars would be build against each supported PHP version and the tests run with the `phpcs` Phar would use the Phar as build on the same PHP version as the test was being run on.

This test was not representative of the reality as with each release, only one `phpcs` and one `phpcbf` phar is released.

The changes in this commit:
* Split the building of the Phar off from the main test script.
* This new `build` job:
    - Tests building the Phar against all supported PHP versions as an early detection system for problems in the Phar extension/Phar building script.
    - Uploads both phars as build against PHP 7.4.
        The uploaded Phars match the Phars as would be included on a release as they are build against the same PHP version as used for releases.
        These Phars will now also be available for PRs and merges to `master` to allow for easier testing of change proposals by issue reporters who may not have a git clone of the repo.
        The uploaded Phars will be available for 28 days (default 90).
    - Does a cursory test with both the `phpcs.phar` as well as the `phpcbf.phar` to test that the build phar files are functional.
* In the `test` job, which now depends on the `build` job, the Phar will now no longer be build, but the Phar as uploaded in the `build` job - i.e. the Phar build against the same PHP version as used when releasing Phars - is downloaded and used to run the Phar test.

The uploaded Phar files can be found on the "Summary" page of the `test` workflow after the build has finished for each build run.
  • Loading branch information
jrfnl committed Dec 17, 2021
1 parent 6296b27 commit 7d4514d
Showing 1 changed file with 60 additions and 6 deletions.
66 changes: 60 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,60 @@ on:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

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

name: "Build Phar on PHP: ${{ matrix.php }}"

continue-on-error: ${{ matrix.php == '8.2' }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
ini-values: phar.readonly=Off, error_reporting=-1, display_errors=On

- name: Build the phar
run: php scripts/build-phar.php

- name: Upload the PHPCS phar
uses: actions/upload-artifact@v2
if: ${{ success() && matrix.php == '7.4' }}
with:
name: phpcs-phar
path: ./phpcs.phar
if-no-files-found: error
retention-days: 28

- name: Upload the PHPCBF phar
uses: actions/upload-artifact@v2
if: ${{ success() && matrix.php == '7.4' }}
with:
name: phpcbf-phar
path: ./phpcbf.phar
if-no-files-found: error
retention-days: 28

# Both the below only check a few files which are rarely changed and therefore unlikely to have issues.
# This test is about testing that the phars are functional, *not* about whether the code style complies.
- name: 'PHPCS: check code style using the Phar file to test the Phar is functional'
run: php phpcs.phar ./scripts

- name: 'PHPCBF: fix code style using the Phar file to test the Phar is functional'
run: php phpcbf.phar ./scripts

test:
runs-on: ubuntu-latest
needs: build

strategy:
# Keys:
Expand Down Expand Up @@ -45,11 +97,11 @@ jobs:
# Set the "short_open_tag" ini to make sure specific conditions are tested.
# Also turn on error_reporting to ensure all notices are shown.
if [[ ${{ matrix.custom_ini }} == true && "${{ matrix.php }}" == '5.5' ]]; then
echo '::set-output name=PHP_INI::phar.readonly=Off, error_reporting=-1, display_errors=On, date.timezone=Australia/Sydney, short_open_tag=On, asp_tags=On'
echo '::set-output name=PHP_INI::error_reporting=-1, display_errors=On, date.timezone=Australia/Sydney, short_open_tag=On, asp_tags=On'
elif [[ ${{ matrix.custom_ini }} == true && "${{ matrix.php }}" == '7.0' ]]; then
echo '::set-output name=PHP_INI::phar.readonly=Off, error_reporting=-1, display_errors=On, date.timezone=Australia/Sydney, short_open_tag=On'
echo '::set-output name=PHP_INI::error_reporting=-1, display_errors=On, date.timezone=Australia/Sydney, short_open_tag=On'
else
echo '::set-output name=PHP_INI::phar.readonly=Off, error_reporting=-1, display_errors=On'
echo '::set-output name=PHP_INI::error_reporting=-1, display_errors=On'
fi
- name: Install PHP
Expand Down Expand Up @@ -106,10 +158,12 @@ jobs:
if: ${{ matrix.custom_ini == false }}
run: composer validate --no-check-all --strict

- name: Build the phar
if: ${{ matrix.custom_ini == false }}
run: php scripts/build-phar.php
- name: Download the PHPCS phar
uses: actions/download-artifact@v2
with:
name: phpcs-phar

# This test specifically tests that the Phar which will be released works correctly on all PHP versions.
- name: 'PHPCS: check code style using the Phar file'
if: ${{ matrix.custom_ini == false }}
run: php phpcs.phar

0 comments on commit 7d4514d

Please sign in to comment.