Skip to content

Commit 7d3d8cd

Browse files
committed
GH Actions: switch over to parallel linting of PHP files
### Composer This installs two additional PHP packages in `require-dev`: * [`php-parallel-lint`](https://packagist.org/packages/php-parallel-lint/php-parallel-lint) which allows for linting PHP files in parallel (faster), as well as automatically recursively walking directories. * [`php-console-highlighter`](https://packagist.org/packages/php-parallel-lint/php-console-highlighter) which provides PHP code highlighting in the command line console, allowing the linter to display the results in a more meaningful manner. It also adjusts the existing `bin/php-lint` script to use this new dependency instead of using *nix specific commands. ### GH Actions As it was, PHP linting was only done on PHP 7.4 as part of the `basics` workflow. This commit changes this to run linting on the lowest (PHP 5.4) and highest (latest/PHP 8.0) supported PHP versions as part of the `test` workflow. (And by "supported", I mean _runtime_ support in this case, not _syntax support_.) The running of the tests has been made dependent on the linting jobs passing as if the linting turns up failures, we can be sure that there will be (or should be) failures in the test runs anyway. This new job uses the "CS2PR" tool which will show any errors as feedback in the actual PR code view. It also runs the linter against PHP 8.1 - against which we are currently not yet running the tests - as an early warning system in case of upcoming issues. Ref: * https://github.com/php-parallel-lint/PHP-Parallel-Lint/releases/tag/v1.3.0 * https://github.com/php-parallel-lint/PHP-Console-Highlighter/releases/tag/v0.5
1 parent 288ad35 commit 7d3d8cd

File tree

4 files changed

+41
-16
lines changed

4 files changed

+41
-16
lines changed

.github/workflows/basics.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ jobs:
2626
coverage: none
2727
tools: cs2pr
2828

29-
- name: 'Lint PHP against parse errors'
30-
run: ./bin/php-lint
31-
3229
- name: Install xmllint
3330
run: sudo apt-get install --no-install-recommends -y libxml2-utils
3431

.github/workflows/test.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,45 @@ on:
1111
workflow_dispatch:
1212

1313
jobs:
14+
#### PHP LINT STAGE ####
15+
# Linting against high/low PHP versions should catch everything.
16+
# If needs be, we can always add interim versions at a later point in time.
17+
lint:
18+
runs-on: ubuntu-latest
19+
20+
strategy:
21+
matrix:
22+
php: ['5.4', 'latest']
23+
experimental: [false]
24+
25+
include:
26+
- php: '8.1'
27+
experimental: true
28+
29+
name: "Lint: PHP ${{ matrix.php }}"
30+
continue-on-error: ${{ matrix.experimental }}
31+
32+
steps:
33+
- name: Checkout code
34+
uses: actions/checkout@v2
35+
36+
- name: Install PHP
37+
uses: shivammathur/setup-php@v2
38+
with:
39+
php-version: ${{ matrix.php }}
40+
coverage: none
41+
tools: cs2pr
42+
43+
- name: Install Composer dependencies
44+
uses: "ramsey/composer-install@v1"
45+
46+
- name: Lint against parse errors
47+
run: ./bin/php-lint --checkstyle | cs2pr
48+
1449
test:
50+
# No use running the tests if there is a linting error somewhere as they would fail anyway.
51+
needs: lint
52+
1553
runs-on: ubuntu-latest
1654

1755
strategy:

bin/php-lint

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,9 @@
22
#
33
# Lint the PHP files against parse errors.
44
#
5-
# The find utility recursively descends the directory tree for each path listed.
6-
#
7-
# find . = Start with all files in this package
8-
# -path ./vendor -prune = But remove those in the vendor directory
9-
# -o -path ./bin -prune = And remove those in the bin directory
10-
# -o -path ./.git -prune = And remove those in the .git directory
11-
# -o -name "*.php" = And only consider those with a .php extension
12-
# -exec php -l {} = Run PHP linter on the remaining files
13-
# | grep "^[Parse error|Fatal error]" = Look in the results for any parse or fatal errors.
14-
#
155
# EXAMPLE TO RUN LOCALLY:
166
#
177
# ./bin/php-lint
188
#
199

20-
if find . -path ./vendor -prune -o -path ./bin -prune -o -path ./.git -prune -o -name "*.php" -exec php -l -f {} \; | grep "^[Errors parsing]"; then
21-
exit 1;
22-
fi
10+
"$(pwd)/vendor/bin/parallel-lint" . -e php --exclude vendor --exclude .git $@

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
"wp-coding-standards/wpcs": "^2.3"
2323
},
2424
"require-dev": {
25+
"php-parallel-lint/php-parallel-lint": "^1.0",
26+
"php-parallel-lint/php-console-highlighter": "^0.5",
2527
"phpcompatibility/php-compatibility": "^9",
2628
"phpunit/phpunit": "^4 || ^5 || ^6 || ^7"
2729
},

0 commit comments

Comments
 (0)