Skip to content

Commit 846075c

Browse files
committed
CI: switch to GitHub Actions - step 4: test and coverage stage
This commit: * Adds a GH Actions workflow for the CI checks which were previously run on Travis in the `test` and `coverage` stages. * Removes the, now redundant, `.travis.yml` configuration. * Updates the `.gitattributes` file. * Updates the "Build Status" badge in the Readme to use the results from the GH `Test` Actions runs. * Updates the "Tested on" badge in the Readme to include PHP 8. * Updates a test file which mentioned Travis. Notes: 1. Each of these jobs has a `needs` dependency on the previous job to prevent it from starting if the previous job failed. While not 100% necessary, this is just an efficiency tweak, being kind to the free service being offered as we know that if linting fails, the tests will fail etc. 2. The builds in the `test` and `coverage` jobs are essentially the same as previously run on Travis, though PHP 8.0 is now fully accounted for and `8.1` is set as `nightly`. 3. Previously, this "stage" would run on all `pull requests` events. The current set-up still does so, with one addition: pushes to `master` (merges) will now also use this workflow instead of the quicktest. This replaces the full run on tagging a release, meaning that thing will essentially be the same. 4. As there are a couple of jobs which are "allowed to fail" (`experimental` = true), the build status will unfortunately show as "failed", even though all non-experimental jobs have succeeded. This is a known issue in GHA: https://github.com/actions/toolkit/issues/399
1 parent ff6212e commit 846075c

File tree

6 files changed

+277
-210
lines changed

6 files changed

+277
-210
lines changed

.coveralls.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
coverage_clover: build/logs/clover.xml
22
json_path: build/logs/coveralls-upload.json
3-
service_name: travis-ci

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/.coveralls.yml export-ignore
99
/.gitattributes export-ignore
1010
/.gitignore export-ignore
11-
/.travis.yml export-ignore
11+
/.github/ export-ignore
1212
/phpcs.xml.dist export-ignore
1313
/phpdoc.xml.dist export-ignore
1414
/phpunit.xml.dist export-ignore

.github/workflows/test.yml

Lines changed: 272 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,272 @@
1+
name: Test
2+
3+
on:
4+
# Run on pushes to `master` and on all pull requests.
5+
push:
6+
branches:
7+
- master
8+
paths-ignore:
9+
- '**.md'
10+
- 'docs/**'
11+
pull_request:
12+
paths-ignore:
13+
- '**.md'
14+
- 'docs/**'
15+
16+
jobs:
17+
#### TEST STAGE ####
18+
test:
19+
runs-on: ubuntu-latest
20+
21+
strategy:
22+
# Keys:
23+
# - risky: Whether to run with tests which check for being in sync with PHPCS.
24+
# - experimental: Whether the build is "allowed to fail".
25+
matrix:
26+
# The GHA matrix works different from Travis.
27+
# You can define jobs here and then augment them with extra variables in `include`,
28+
# as well as add extra jobs in `include`.
29+
# @link https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix
30+
#
31+
# IMPORTANT: test runs shouldn't fail because of PHPCS being incompatible with a PHP version.
32+
# - PHPCS will run without errors on PHP 5.4 - 7.2 on any version.
33+
# - PHP 7.3 needs PHPCS 2.9.2 and 3.3.1+ to run without errors.
34+
# On PHPCS 2.x our tests won't fail though, but on PHPCS 3.x < 3.3.1 they will.
35+
# - PHP 7.4 needs PHPCS 3.5.0+ to run without errors.
36+
# On PHPCS 2.x our tests won't fail though, but on PHPCS 3.x < 3.5.0 they will.
37+
# - PHP 8.0 needs PHPCS 3.5.7+ to run without errors.
38+
#
39+
# The matrix is set up so as not to duplicate the builds which are run for code coverage.
40+
php: ['5.5', '5.6', '7.0', '7.1', '7.2']
41+
phpcs_version: ['2.6.0', '2.9.2', '3.1.0', 'dev-master']
42+
risky: [false]
43+
experimental: [false]
44+
45+
include:
46+
# Complement the builds run in code coverage to complete the matrix and prevent issues
47+
# with PHPCS versions incompatible with certain PHP versions.
48+
- php: '8.0'
49+
phpcs_version: 'dev-master'
50+
risky: false
51+
experimental: false
52+
- php: '8.0'
53+
phpcs_version: '3.5.7'
54+
risky: false
55+
experimental: false
56+
57+
- php: '7.4'
58+
phpcs_version: '3.5.0'
59+
risky: false
60+
experimental: false
61+
62+
- php: '7.3'
63+
phpcs_version: 'dev-master'
64+
risky: false
65+
experimental: false
66+
- php: '7.3'
67+
phpcs_version: '3.3.1'
68+
risky: false
69+
experimental: false
70+
- php: '7.3'
71+
phpcs_version: '2.6.0'
72+
risky: false
73+
experimental: false
74+
75+
- php: '5.4'
76+
phpcs_version: '3.1.0'
77+
risky: false
78+
experimental: false
79+
- php: '5.4'
80+
phpcs_version: '2.9.2'
81+
risky: false
82+
experimental: false
83+
84+
# One extra build to verify issues around PHPCS annotations when they weren't fully accounted for yet.
85+
- php: '7.2'
86+
phpcs_version: '3.2.0'
87+
risky: false
88+
experimental: false
89+
90+
# And a few more to verify various tokenizer issues in older PHPCS versions.
91+
- php: '5.6'
92+
phpcs_version: '2.8.1'
93+
risky: false
94+
experimental: false
95+
- php: '7.0'
96+
phpcs_version: '2.7.1'
97+
risky: false
98+
experimental: false
99+
100+
# Experimental builds. These are allowed to fail.
101+
102+
# Current lowest PHPCS version which _may_ run on PHP 8 is 3.5.0, so don't even try
103+
# to test against older versions.
104+
- php: '8.1'
105+
phpcs_version: 'dev-master'
106+
risky: false
107+
experimental: true
108+
109+
- php: '7.4'
110+
phpcs_version: '4.0.x-dev'
111+
risky: false
112+
experimental: true
113+
114+
# Run risky tests separately.
115+
- php: '7.4'
116+
phpcs_version: '4.0.x-dev'
117+
risky: true
118+
experimental: true
119+
120+
- php: '7.4'
121+
phpcs_version: 'dev-master'
122+
risky: true
123+
experimental: true
124+
125+
name: "Test${{ matrix.phpcs_version == 'dev-master' && matrix.risky == false && ' + Lint' || '' }}: PHP ${{ matrix.php }} - PHPCS ${{ matrix.phpcs_version }}${{ matrix.risky == true && ' (risky)' || '' }}"
126+
127+
continue-on-error: ${{ matrix.experimental }}
128+
129+
steps:
130+
- name: Checkout code
131+
uses: actions/checkout@v2
132+
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+
- name: Setup ini config
136+
id: set_ini
137+
run: |
138+
if [[ "${{ matrix.phpcs_version }}" != "dev-master" && "${{ matrix.phpcs_version }}" != "4.0.x-dev" ]]; then
139+
echo '::set-output name=PHP_INI::error_reporting=E_ALL & ~E_DEPRECATED'
140+
else
141+
echo '::set-output name=PHP_INI::error_reporting=E_ALL'
142+
fi
143+
144+
- name: Install PHP
145+
uses: shivammathur/setup-php@v2
146+
with:
147+
php-version: ${{ matrix.php }}
148+
ini-values: ${{ steps.set_ini.outputs.PHP_INI }}
149+
coverage: none
150+
151+
- name: 'Composer: set PHPCS version for tests'
152+
run: composer require --no-update squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}"
153+
154+
- name: 'Composer: conditionally tweak PHPUnit version'
155+
if: ${{ startsWith( matrix.php, '8' ) }}
156+
# Temporary fix - PHPUnit 9.3+ is buggy when used for code coverage, so not allowed "normally".
157+
# For tests which don't run code coverage, we can safely install it for PHP 8 though.
158+
run: composer require --no-update phpunit/phpunit:"^9.3"
159+
160+
# Install dependencies and handle caching in one go.
161+
# @link https://github.com/marketplace/actions/install-composer-dependencies
162+
- name: Install Composer dependencies - normal
163+
if: ${{ matrix.php < 8.1 }}
164+
uses: "ramsey/composer-install@v1"
165+
166+
# For the PHP "nightly", we need to install with ignore platform reqs as not all dependencies allow it yet.
167+
- name: Install Composer dependencies - with ignore platform
168+
if: ${{ matrix.php >= 8.1 }}
169+
uses: "ramsey/composer-install@v1"
170+
with:
171+
composer-options: --ignore-platform-reqs
172+
173+
- name: Lint against parse errors
174+
if: matrix.phpcs_version == 'dev-master' && matrix.risky == false
175+
run: composer lint
176+
177+
- name: Run the unit tests (non-risky)
178+
if: matrix.risky == false
179+
run: vendor/bin/phpunit --no-coverage
180+
181+
- name: Run the unit tests (risky)
182+
if: ${{ matrix.risky }}
183+
# "nothing" is excluded to force PHPUnit to ignore the <exclude> settings in phpunit.xml.dist.
184+
run: vendor/bin/phpunit --no-coverage --group compareWithPHPCS --exclude-group nothing
185+
186+
#### CODE COVERAGE STAGE ####
187+
# N.B.: Coverage is only checked on the lowest and highest stable PHP versions
188+
# and a low/high of each major for PHPCS.
189+
# These builds are left out off the "test" stage so as not to duplicate test runs.
190+
coverage:
191+
# No use running the coverage builds if there are failing test builds.
192+
needs: test
193+
194+
runs-on: ubuntu-latest
195+
196+
strategy:
197+
matrix:
198+
include:
199+
- php: '7.4' # This should be changed to 8.0 when the tests can run on PHPUnit 9.3+.
200+
phpcs_version: 'dev-master'
201+
- php: '7.3'
202+
phpcs_version: '2.9.2'
203+
- php: '5.4'
204+
phpcs_version: 'dev-master'
205+
- php: '5.4'
206+
phpcs_version: '2.6.0'
207+
208+
name: "Coverage: PHP ${{ matrix.php }} - PHPCS ${{ matrix.phpcs_version }}"
209+
210+
steps:
211+
- name: Checkout code
212+
uses: actions/checkout@v2
213+
214+
# On stable PHPCS versions, allow for PHP deprecation notices.
215+
# Unit tests don't need to fail on those for stable releases where those issues won't get fixed anymore.
216+
- name: Setup ini config
217+
id: set_ini
218+
run: |
219+
if [ "${{ matrix.phpcs_version }}" != "dev-master" ]; then
220+
echo '::set-output name=PHP_INI::error_reporting=E_ALL & ~E_DEPRECATED'
221+
else
222+
echo '::set-output name=PHP_INI::error_reporting=E_ALL'
223+
fi
224+
225+
- name: Install PHP
226+
uses: shivammathur/setup-php@v2
227+
with:
228+
php-version: ${{ matrix.php }}
229+
ini-values: ${{ steps.set_ini.outputs.PHP_INI }}
230+
coverage: xdebug
231+
232+
- name: 'Composer: adjust dependencies'
233+
run: |
234+
# Set a specific PHPCS version.
235+
composer require --no-update squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}" --no-scripts
236+
237+
- name: Install Composer dependencies - normal
238+
uses: "ramsey/composer-install@v1"
239+
240+
- name: Run the unit tests with code coverage
241+
run: vendor/bin/phpunit
242+
243+
# Uploading the results with PHP Coveralls v1 won't work from GH Actions, so switch the PHP version.
244+
- name: Switch to PHP 7.4
245+
if: ${{ success() && matrix.php != '7.4' }}
246+
uses: shivammathur/setup-php@v2
247+
with:
248+
php-version: 7.4
249+
coverage: none
250+
251+
- name: Install Coveralls
252+
if: ${{ success() }}
253+
run: composer require php-coveralls/php-coveralls:"^2.4.2"
254+
255+
- name: Upload coverage results to Coveralls
256+
if: ${{ success() }}
257+
env:
258+
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
259+
COVERALLS_PARALLEL: true
260+
COVERALLS_FLAG_NAME: php-${{ matrix.php }}-phpcs-${{ matrix.phpcs_version }}
261+
run: vendor/bin/php-coveralls -v -x build/logs/clover.xml
262+
263+
coveralls-finish:
264+
needs: coverage
265+
runs-on: ubuntu-latest
266+
267+
steps:
268+
- name: Coveralls Finished
269+
uses: coverallsapp/github-action@master
270+
with:
271+
github-token: ${{ secrets.GITHUB_TOKEN }}
272+
parallel-finished: true

0 commit comments

Comments
 (0)