Skip to content

Commit 156490d

Browse files
authored
CI/QA: Switch to GitHub Actions and start using Coveralls (sirbrillig#252)
* CI/QA: Remove CircleCI configuration ... and all work-arounds in place to accommodate. Hope I caught them all. * Composer.json - widen PHPUnit requirements PHP 5.4 needs PHPUnit 4.x to be able to run the tests, so that needed adding. Aside from that PHPUnit 9.x has come out quite a while back and has better support for PHP 8.0 and 8.1 than PHPUnit 8.x. I've set the version constraints for the 4.x and 5.x series to very specific minimum versions for a reason: those are the first versions to have the forward-compatibility layer with the namespaced PHPUnit `TestCase`, which is used by the tests in this repo. * CI/QA: add GH Actions workflows This commit adds two workflows which run the same checks as were run in CircleCI + a lot more. **CS and QA workflow: `checkcs` job** Differences between this workflow and these checks when run via CircleCI: * New: This workflow will now also run QA checks on the `ruleset.xml` file. It will run two checks: 1. Does the ruleset validate against the schema ? 2. Does the ruleset have a consistent code style, including consistent indentation using four spaces ? * Removed: CircleCI ran PHPCS against both PHP 7.3 as well as 7.4. This is redundant as PHPCS should give the same results cross-version. In the new setup, it will only be run once against PHP 7.4. * Changed: The PHPCS check will now be run using PHPCS `master` as an early warning system for upstream bugs. * New: By using the `cs2pr` tool and the `xmllint-problem-matcher`, violations found will be shown in the GH code views, like the "Files" tab on a PR. **CS and QA workflow: `phpstan` job** Differences between this workflow and these checks when run via CircleCI: * Removed: CircleCI ran PHPStan against both PHP 7.3 as well as 7.4. This is redundant as PHPStan, same like PHPCS, should give the same results cross-version. In the new setup, it will only be run once against PHP 7.4. * New: PHPStan natively supports showing violations found in the GH code views, like the "Files" tab on a PR. ** Test workflow: `test` job** * Changed: CircleCI only ran the tests against PHP 5.4, 5.6, 7.3 and 7.4 and only against the latest version of PHPCS. In this new setup, the tests are run against all supported PHP versions + the high/low supported PHPCS, which at this time means: PHPCS `3.5.6` as "low" and PHPCS `dev-master` as "high". This results in a lot more test runs, but this will safeguard the cross-version compatibility of the standard much better as well (and GH Actions is fast, so it shouldn't really impact CI runtime anyway). * New: Tests are now also run against PHP 8.0, 8.1 and 8.2, where the run against PHP 8.2 is still allowed to fail for now (`continue-on-error`). * GH Actions/Test: add code coverage test runs & send to Coveralls This commits: * Splits the test runs into two jobs, where code coverage is run against the high/low PHP/PHPCS combinations and the "normal" test runs remain for all other PHP/PHPCS combination. * Includes setting up cache warming for PHPUnit 9.3+ as PHP-Parser can interfere otherwise by backfilling tokens when they are not (yet) available in PHPCS. * Adjusts the PHPUnit configuration to allow for measuring code coverage. * Adds a new script to the `composer.json` file for running the tests with code coverage and adjusts the existing `test` script to ignore code coverage. * Adds the badge from Coveralls to the README. Co-authored-by: jrfnl <jrfnl@users.noreply.github.com>
1 parent ba1e2da commit 156490d

File tree

9 files changed

+327
-115
lines changed

9 files changed

+327
-115
lines changed

.circleci/config.yml

Lines changed: 0 additions & 59 deletions
This file was deleted.

.gitattributes

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
# https://www.reddit.com/r/PHP/comments/2jzp6k/i_dont_need_your_tests_in_my_production
66
# https://blog.madewithlove.be/post/gitattributes/
77
#
8-
/.gitattributes export-ignore
9-
/.gitignore export-ignore
10-
/composer.circleci.json export-ignore
11-
/phpcs.xml.dist export-ignore
8+
/.gitattributes export-ignore
9+
/.gitignore export-ignore
10+
/phpcs.xml.dist export-ignore
1211
/phpstan.neon.dist export-ignore
13-
/phpunit.xml.dist export-ignore
14-
/.circleci/ export-ignore
15-
/Tests/ export-ignore
12+
/phpunit.xml.dist export-ignore
13+
/.github export-ignore
14+
/Tests/ export-ignore
1615

1716
#
1817
# Auto detect text files and perform LF normalization

.github/workflows/csqa.yml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: CS and QA
2+
3+
on:
4+
# Run on all pushes and on all pull requests.
5+
# Prevent the build from running when there are only irrelevant changes.
6+
push:
7+
paths-ignore:
8+
- '**.md'
9+
pull_request:
10+
# Allow manually triggering the workflow.
11+
workflow_dispatch:
12+
13+
# Cancels all previous workflow runs for the same branch that have not yet completed.
14+
concurrency:
15+
# The concurrency group contains the workflow name and the branch name.
16+
group: ${{ github.workflow }}-${{ github.ref }}
17+
cancel-in-progress: true
18+
19+
jobs:
20+
checkcs:
21+
name: 'PHP: 7.4 | Basic CS and QA checks'
22+
runs-on: ubuntu-latest
23+
24+
env:
25+
XMLLINT_INDENT: ' '
26+
27+
steps:
28+
- name: Checkout code
29+
uses: actions/checkout@v3
30+
31+
- name: Install PHP
32+
uses: shivammathur/setup-php@v2
33+
with:
34+
php-version: '7.4'
35+
coverage: none
36+
tools: cs2pr
37+
38+
# Using PHPCS `master` as an early detection system for bugs upstream.
39+
- name: 'Composer: adjust dependencies'
40+
run: composer require --no-update squizlabs/php_codesniffer:"dev-master"
41+
42+
# Install dependencies and handle caching in one go.
43+
# @link https://github.com/marketplace/actions/install-composer-dependencies
44+
- name: Install Composer dependencies
45+
uses: "ramsey/composer-install@v2"
46+
47+
- name: Install xmllint
48+
run: |
49+
sudo apt-get update
50+
sudo apt-get install --no-install-recommends -y libxml2-utils
51+
52+
# Show XML violations inline in the file diff.
53+
# @link https://github.com/marketplace/actions/xmllint-problem-matcher
54+
- uses: korelstar/xmllint-problem-matcher@v1
55+
56+
# Validate the XML file.
57+
# @link http://xmlsoft.org/xmllint.html
58+
- name: Validate ruleset against schema
59+
run: xmllint --noout --schema vendor/squizlabs/php_codesniffer/phpcs.xsd VariableAnalysis/ruleset.xml
60+
61+
# Check the code-style consistency of the XML file.
62+
- name: Check XML code style
63+
run: diff -B ./VariableAnalysis/ruleset.xml <(xmllint --format "./VariableAnalysis/ruleset.xml")
64+
65+
# Check the code-style consistency of the PHP files.
66+
- name: Check PHP code style
67+
continue-on-error: true
68+
run: composer lint -- --no-cache --report-full --report-checkstyle=./phpcs-report.xml
69+
70+
- name: Show PHPCS results in PR
71+
run: cs2pr ./phpcs-report.xml
72+
73+
phpstan:
74+
name: "PHP: 7.4 | PHPStan"
75+
runs-on: ubuntu-latest
76+
77+
steps:
78+
- name: Checkout code
79+
uses: actions/checkout@v3
80+
81+
- name: Install PHP
82+
uses: shivammathur/setup-php@v2
83+
with:
84+
php-version: '7.4'
85+
coverage: none
86+
87+
# Install dependencies and handle caching in one go.
88+
# Dependencies need to be installed to make sure the PHPUnit classes are recognized.
89+
# @link https://github.com/marketplace/actions/install-composer-dependencies
90+
- name: Install Composer dependencies
91+
uses: "ramsey/composer-install@v2"
92+
93+
- name: Run PHPStan
94+
run: composer phpstan

.github/workflows/test.yml

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
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

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/composer.lock
22
/vendor/
3+
/build/
34
phpunit.xml
45
.phpunit.result.cache
56
.phpcs.xml

0 commit comments

Comments
 (0)