Skip to content

Commit d4d68a6

Browse files
committed
GH Actions: add PHP linting job
This commit: * Add a new dependency on the PHP Parallel Lint package for fast PHP linting. The PHP Parallel Lint package, in combination with the PHP Console Highlighter provides the following advantages in comparison with "plain" PHP linting: - Higher speed due to the parallel processes. - Improved usability by providing color coded syntax highlighting of found errors on the command-line. - Integration with the `cs2pr` tool, allowing for the results of the lint command to be shown in-line in PRs. * Adds a Composer `lint` script for easy access to the tool for devs, while making sure the correct command line parameters will be used. The linting command as currently set up, will also check the example files for linting errors. * Adds a GH Actions job for linting the code on the high/low supported PHP versions, one arbitrary interim version + an experimental build against PHP 8.1. The `cs2pr` tool has been enabled and will show the results of the non-experimental lint runs in-line in PRs. **Note**: For PHP 8.1, the `cs2pr` tool is not used as there is a known issue in the Parallel Lint tool with PHP 8.1 which breaks on the checkstyle reporting. There is already a [PR open](php-parallel-lint/PHP-Parallel-Lint#64) to fix this upstream. Once this PR has been merged and a new version of Parallel Lint has been released, the separate step for PHP 8.1 linting can be removed. * Makes the `test` job in the GHA workflow dependent on the `lint` job having passed... ... as the tests would fail anyway if there are linting errors. Also adjusts the name of the `test` jobs to include the word "Test" so they can be easily distinguished from the Lint jobs. Refs: * https://github.com/php-parallel-lint/PHP-Parallel-Lint
1 parent 1599497 commit d4d68a6

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

.github/workflows/tests.yml

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,45 @@ jobs:
3535
- name: Show PHPCS results in PR
3636
run: cs2pr ./phpcs-report.xml
3737

38+
lint:
39+
runs-on: ubuntu-18.04
40+
strategy:
41+
matrix:
42+
php: ['5.5', '7.2', '8.0']
43+
experimental: [false]
44+
include:
45+
- php: '8.1'
46+
experimental: true
47+
48+
name: "Lint: PHP ${{ matrix.php }}"
49+
continue-on-error: ${{ matrix.experimental }}
50+
51+
steps:
52+
- name: Checkout code
53+
uses: actions/checkout@v2
54+
55+
- name: Install PHP
56+
uses: shivammathur/setup-php@v2
57+
with:
58+
php-version: ${{ matrix.php }}
59+
coverage: none
60+
tools: cs2pr
61+
62+
# Install dependencies and handle caching in one go.
63+
# @link https://github.com/marketplace/actions/install-composer-dependencies
64+
- name: Install Composer dependencies
65+
uses: "ramsey/composer-install@v1"
66+
67+
- name: Lint against parse errors
68+
if: ${{ matrix.php != '8.1' }}
69+
run: composer lint -- --checkstyle | cs2pr
70+
71+
- name: Lint against parse errors (PHP 8.1)
72+
if: ${{ matrix.php == '8.1' }}
73+
run: composer lint
74+
3875
test:
39-
needs: ['coding-standard']
76+
needs: ['coding-standard', 'lint']
4077
runs-on: ubuntu-18.04
4178
strategy:
4279
matrix:
@@ -47,7 +84,7 @@ jobs:
4784
- php: '8.1'
4885
experimental: true
4986

50-
name: PHP ${{ matrix.php }}
87+
name: "Test: PHP ${{ matrix.php }}"
5188

5289
continue-on-error: ${{ matrix.experimental }}
5390

composer.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
"require-dev": {
3535
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
3636
"doctrine/annotations": "^1.2",
37+
"php-parallel-lint/php-console-highlighter": "^0.5.0",
38+
"php-parallel-lint/php-parallel-lint": "^1.3",
3739
"phpcompatibility/php-compatibility": "^9.3.5",
3840
"roave/security-advisories": "dev-latest",
3941
"squizlabs/php_codesniffer": "^3.6.0",
@@ -60,6 +62,9 @@
6062
"license": "LGPL-2.1-only",
6163
"scripts": {
6264
"check": "./vendor/bin/phpcs",
63-
"test": "./vendor/bin/phpunit"
65+
"test": "./vendor/bin/phpunit",
66+
"lint": [
67+
"@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php,phps --exclude vendor --exclude .git --exclude build"
68+
]
6469
}
6570
}

0 commit comments

Comments
 (0)