|
| 1 | +name: Test |
| 2 | + |
| 3 | +on: |
| 4 | + # Run on all pushes and pull requests. |
| 5 | + push: |
| 6 | + pull_request: |
| 7 | + # Allow manually triggering the workflow. |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +# Cancels all previous workflow runs for the same branch that have not yet completed. |
| 11 | +concurrency: |
| 12 | + # The concurrency group contains the workflow name and the branch name. |
| 13 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 14 | + cancel-in-progress: true |
| 15 | + |
| 16 | +jobs: |
| 17 | + #### TEST STAGE #### |
| 18 | + test: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + |
| 21 | + strategy: |
| 22 | + matrix: |
| 23 | + # The GHA matrix works different from Travis. |
| 24 | + # You can define jobs here and then augment them with extra variables in `include`, |
| 25 | + # as well as add extra jobs in `include`. |
| 26 | + # @link https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix |
| 27 | + # |
| 28 | + # IMPORTANT: test runs shouldn't fail because of PHPCS being incompatible with a PHP version. |
| 29 | + # - PHPCS will run without errors on PHP 5.4 - 7.4 on all supported PHPCS versions. |
| 30 | + # - PHP 8.0 needs PHPCS 3.5.7+ to run without errors. |
| 31 | + # - PHP 8.1 needs PHPCS 3.6.1+ to run without errors. |
| 32 | + # |
| 33 | + # The matrix is set up so as not to duplicate the builds which are run for code coverage. |
| 34 | + php: ['5.5', '5.6', '7.0', '7.1', '7.2', '7.3'] |
| 35 | + phpcs_version: ['3.5.6', 'dev-master'] |
| 36 | + |
| 37 | + include: |
| 38 | + # Make the matrix complete without duplicating builds run in code coverage. |
| 39 | + - php: '8.1' |
| 40 | + phpcs_version: '3.6.1' |
| 41 | + |
| 42 | + - php: '8.0' |
| 43 | + phpcs_version: 'dev-master' |
| 44 | + - php: '8.0' |
| 45 | + phpcs_version: '3.5.7' |
| 46 | + |
| 47 | + - php: '7.4' |
| 48 | + phpcs_version: 'dev-master' |
| 49 | + |
| 50 | + # Experimental builds. |
| 51 | + - php: '8.2' # Nightly. |
| 52 | + phpcs_version: 'dev-master' |
| 53 | + |
| 54 | + name: "Test: PHP ${{ matrix.php }} on PHPCS ${{ matrix.phpcs_version }}" |
| 55 | + |
| 56 | + continue-on-error: ${{ matrix.php == '8.2' }} |
| 57 | + |
| 58 | + steps: |
| 59 | + - name: Checkout code |
| 60 | + uses: actions/checkout@v3 |
| 61 | + |
| 62 | + - name: Setup ini config |
| 63 | + id: set_ini |
| 64 | + run: | |
| 65 | + # On stable PHPCS versions, allow for PHP deprecation notices. |
| 66 | + # Unit tests don't need to fail on those for stable releases where those issues won't get fixed anymore. |
| 67 | + if [ "${{ matrix.phpcs_version }}" != "dev-master" ]; then |
| 68 | + echo '::set-output name=PHP_INI::error_reporting=E_ALL & ~E_DEPRECATED, display_errors=On, zend.assertions=1' |
| 69 | + else |
| 70 | + echo '::set-output name=PHP_INI::error_reporting=-1, display_errors=On, zend.assertions=1' |
| 71 | + fi |
| 72 | +
|
| 73 | + - name: Install PHP |
| 74 | + uses: shivammathur/setup-php@v2 |
| 75 | + with: |
| 76 | + php-version: ${{ matrix.php }} |
| 77 | + ini-values: ${{ steps.set_ini.outputs.PHP_INI }} |
| 78 | + coverage: none |
| 79 | + |
| 80 | + - name: 'Composer: adjust dependencies' |
| 81 | + run: | |
| 82 | + # Remove dev dependencies which are not compatible with all supported PHP versions. |
| 83 | + composer remove --dev --no-update sirbrillig/phpcs-import-detection phpstan/phpstan |
| 84 | + # Set the PHPCS version for this test run. |
| 85 | + composer require --no-update squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}" |
| 86 | +
|
| 87 | + # Install dependencies and handle caching in one go. |
| 88 | + # @link https://github.com/marketplace/actions/install-composer-dependencies |
| 89 | + - name: Install Composer dependencies - normal |
| 90 | + if: ${{ matrix.php != '8.2' }} |
| 91 | + uses: "ramsey/composer-install@v2" |
| 92 | + |
| 93 | + # For the PHP "nightly", we need to install with ignore platform reqs as not all dependencies allow it yet. |
| 94 | + - name: Install Composer dependencies - with ignore platform |
| 95 | + if: ${{ matrix.php == '8.2' }} |
| 96 | + uses: "ramsey/composer-install@v2" |
| 97 | + with: |
| 98 | + composer-options: --ignore-platform-req=php |
| 99 | + |
| 100 | + - name: Run the unit tests |
| 101 | + run: composer test |
| 102 | + |
| 103 | + #### CODE COVERAGE STAGE #### |
| 104 | + # N.B.: Coverage is only checked on the lowest and highest stable PHP versions |
| 105 | + # and low/high for PHPCS. |
| 106 | + coverage: |
| 107 | + # No use running the coverage builds if there are failing test builds. |
| 108 | + needs: test |
| 109 | + runs-on: ubuntu-latest |
| 110 | + |
| 111 | + strategy: |
| 112 | + matrix: |
| 113 | + include: |
| 114 | + - php: '8.1' |
| 115 | + phpcs_version: 'dev-master' |
| 116 | + - php: '7.4' |
| 117 | + phpcs_version: '3.5.6' |
| 118 | + |
| 119 | + - php: '5.4' |
| 120 | + phpcs_version: 'dev-master' |
| 121 | + - php: '5.4' |
| 122 | + phpcs_version: '3.5.6' |
| 123 | + |
| 124 | + name: "Coverage: PHP ${{ matrix.php }} on PHPCS ${{ matrix.phpcs_version }}" |
| 125 | + |
| 126 | + steps: |
| 127 | + - name: Checkout code |
| 128 | + uses: actions/checkout@v3 |
| 129 | + |
| 130 | + - name: Setup ini config |
| 131 | + id: set_ini |
| 132 | + run: | |
| 133 | + # On stable PHPCS versions, allow for PHP deprecation notices. |
| 134 | + # Unit tests don't need to fail on those for stable releases where those issues won't get fixed anymore. |
| 135 | + if [ "${{ matrix.phpcs_version }}" != "dev-master" ]; then |
| 136 | + echo '::set-output name=PHP_INI::error_reporting=E_ALL & ~E_DEPRECATED, display_errors=On, zend.assertions=1' |
| 137 | + else |
| 138 | + echo '::set-output name=PHP_INI::error_reporting=-1, display_errors=On, zend.assertions=1' |
| 139 | + fi |
| 140 | +
|
| 141 | + - name: Install PHP |
| 142 | + uses: shivammathur/setup-php@v2 |
| 143 | + with: |
| 144 | + php-version: ${{ matrix.php }} |
| 145 | + ini-values: ${{ steps.set_ini.outputs.PHP_INI }} |
| 146 | + coverage: xdebug |
| 147 | + |
| 148 | + - name: 'Composer: adjust dependencies' |
| 149 | + run: | |
| 150 | + # Remove dev dependencies which are not compatible with all supported PHP versions. |
| 151 | + composer remove --dev --no-update sirbrillig/phpcs-import-detection phpstan/phpstan |
| 152 | + composer require --no-update squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}" |
| 153 | +
|
| 154 | + - name: Install Composer dependencies |
| 155 | + uses: "ramsey/composer-install@v2" |
| 156 | + |
| 157 | + - name: Grab PHPUnit version |
| 158 | + id: phpunit_version |
| 159 | + run: echo ::set-output name=VERSION::$(vendor/bin/phpunit --version | grep --only-matching --max-count=1 --extended-regexp '\b[0-9]+\.[0-9]+') |
| 160 | + |
| 161 | + - name: "DEBUG: Show grabbed version" |
| 162 | + run: echo ${{ steps.phpunit_version.outputs.VERSION }} |
| 163 | + |
| 164 | + # PHPUnit 9.3 started using PHP-Parser for code coverage which can cause interference. |
| 165 | + # As of PHPUnit 9.3.4, a cache warming option is available. |
| 166 | + # Using that option prevents issues with PHP-Parser backfilling PHP tokens when PHPCS does not (yet), |
| 167 | + # which would otherwise cause tests to fail on tokens being available when they shouldn't be. |
| 168 | + - name: "Warm the PHPUnit cache (PHPUnit 9.3+)" |
| 169 | + if: ${{ steps.phpunit_version.outputs.VERSION >= '9.3' }} |
| 170 | + run: vendor/bin/phpunit --coverage-cache ./build/phpunit-cache --warm-coverage-cache |
| 171 | + |
| 172 | + - name: "Run the unit tests with code coverage (PHPUnit < 9.3)" |
| 173 | + if: ${{ steps.phpunit_version.outputs.VERSION < '9.3' }} |
| 174 | + run: composer coverage |
| 175 | + |
| 176 | + - name: "Run the unit tests with code coverage (PHPUnit 9.3+)" |
| 177 | + if: ${{ steps.phpunit_version.outputs.VERSION >= '9.3' }} |
| 178 | + run: composer coverage -- --coverage-cache ./build/phpunit-cache |
| 179 | + |
| 180 | + # PHP Coveralls v2 has a PHP 5.5 minimum and is not yet fully compatible with PHP 8.0+, so switch the PHP version. |
| 181 | + - name: Switch to PHP 7.4 |
| 182 | + if: ${{ success() && matrix.php != '7.4' }} |
| 183 | + uses: shivammathur/setup-php@v2 |
| 184 | + with: |
| 185 | + php-version: 7.4 |
| 186 | + coverage: none |
| 187 | + |
| 188 | + - name: Install Coveralls |
| 189 | + if: ${{ success() }} |
| 190 | + run: composer require php-coveralls/php-coveralls:"^2.5.2" --no-interaction |
| 191 | + |
| 192 | + - name: Upload coverage results to Coveralls |
| 193 | + if: ${{ success() }} |
| 194 | + env: |
| 195 | + COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 196 | + COVERALLS_PARALLEL: true |
| 197 | + COVERALLS_FLAG_NAME: php-${{ matrix.php }}-phpcs-${{ matrix.phpcs_version }} |
| 198 | + run: vendor/bin/php-coveralls -v -x build/logs/clover.xml |
| 199 | + |
| 200 | + coveralls-finish: |
| 201 | + needs: coverage |
| 202 | + runs-on: ubuntu-latest |
| 203 | + |
| 204 | + steps: |
| 205 | + - name: Coveralls Finished |
| 206 | + uses: coverallsapp/github-action@master |
| 207 | + with: |
| 208 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 209 | + parallel-finished: true |
0 commit comments