From 8acc3cf886848c1922786a88cf493cd7afff9d1f Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 9 Dec 2022 02:22:31 +0100 Subject: [PATCH 01/23] GH Actions: update PHP versions in workflows PHP 8.2 has been released today :tada: and the `setup-php` action has announced support for PHP 8.3, so adding PHP 8.3 to the matrix and no longer allowing PHP 8.2 to fail the build. Builds against PHP 8.3 are still allowed to fail for now. --- .github/workflows/release.yml | 3 ++- .github/workflows/test.yml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7b8f56c..311826c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -62,7 +62,7 @@ jobs: verify: name: Validate binary on PHP ${{ matrix.php }} runs-on: ubuntu-latest - continue-on-error: ${{ matrix.php == '8.2' }} + continue-on-error: ${{ matrix.php == '8.3' }} needs: - bundle @@ -81,6 +81,7 @@ jobs: - '8.0' - '8.1' - '8.2' + - '8.3' steps: - name: Checkout code diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b81c8ac..9027fc0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -85,7 +85,7 @@ jobs: test: name: Run tests on PHP ${{ matrix.php }} runs-on: ubuntu-latest - continue-on-error: ${{ matrix.php == '8.2' }} + continue-on-error: ${{ matrix.php == '8.3' }} needs: - bundle @@ -104,6 +104,7 @@ jobs: - '8.0' - '8.1' - '8.2' + - '8.3' steps: - name: Checkout code From 99b3a651554b7f706f38e522a6a1a4b686cfdbf6 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 23 Nov 2023 03:57:13 +0100 Subject: [PATCH 02/23] GH Actions: update for the release of PHP 8.3 ... which is expected later today. --- .github/workflows/test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9027fc0..741b7b6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -85,7 +85,7 @@ jobs: test: name: Run tests on PHP ${{ matrix.php }} runs-on: ubuntu-latest - continue-on-error: ${{ matrix.php == '8.3' }} + continue-on-error: ${{ matrix.php == '8.4' }} needs: - bundle @@ -105,6 +105,7 @@ jobs: - '8.1' - '8.2' - '8.3' + - '8.4' steps: - name: Checkout code From 6038dcfe10dc221800a30a4ee24de8e28fd93a27 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 20 Feb 2022 19:21:09 +0100 Subject: [PATCH 03/23] Allow version check in application entry file to work By putting the class name, which contains PHP 5.3 namespace separator tokens, as a variable and then dynamically calling the class, the parse error on PHP < 5.3 is prevented and the version check at the top of the file can work as expected. Fixes 62 --- parallel-lint | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/parallel-lint b/parallel-lint index 256425c..942baf4 100755 --- a/parallel-lint +++ b/parallel-lint @@ -70,5 +70,7 @@ if (!$loaded) { require_once __DIR__ . '/src/polyfill.php'; -$app = new JakubOnderka\PhpParallelLint\Application(); +// Prevent parse error on PHP < 5.3 so the version check above can work. +$className = 'JakubOnderka\PhpParallelLint\Application'; +$app = new $className(); exit($app->run()); From dd1ea0b9908ab35cb60cfce61594f324ff5e717b Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 8 Jun 2021 06:28:15 +0200 Subject: [PATCH 04/23] Make the version check more informative Previously, the PHP version check run at the start of the script would display `PHP Parallel Lint requires PHP 5.3.0 or newer.` if the PHP version was too low. The message has been updated to include the currently detected PHP version and the path to the PHP binary. Note: both constants used are available in PHP cross-version. --- parallel-lint | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/parallel-lint b/parallel-lint index 942baf4..4e05f11 100755 --- a/parallel-lint +++ b/parallel-lint @@ -31,7 +31,15 @@ either expressed or implied, of the FreeBSD Project. */ if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50300) { - fwrite(STDERR, "PHP Parallel Lint requires PHP 5.3.0 or newer." . PHP_EOL); + fwrite( + STDERR, + sprintf( + 'PHP Parallel Lint requires PHP 5.3.0 or newer.' . PHP_EOL + . 'You are using PHP %s (%s).' . PHP_EOL, + PHP_VERSION, + PHP_BINDIR + ) + ); exit(254); } From da3ea49b910e4c942ae11a0e3f47e845df886efe Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 5 Mar 2022 19:29:08 +0100 Subject: [PATCH 05/23] GH Actions: version update for various predefined actions A number of predefined actions have had major release, which warrant an update to the workflow(s). These updates don't actually contain any changed functionality, they are mostly just a change of the Node version used by the action itself (from Node 14 to Node 16). Refs: * https://github.com/actions/checkout/releases * https://github.com/actions/download-artifact/releases * https://github.com/actions/upload-artifact/releases --- .github/workflows/release.yml | 10 +++++----- .github/workflows/test.yml | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 311826c..6d1ce4f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -23,7 +23,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -54,7 +54,7 @@ jobs: - name: Show info about the build phar with humbug/box run: php box.phar info -l parallel-lint.phar - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 with: name: parallel-lint-phar path: ./parallel-lint.phar @@ -85,9 +85,9 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v3 with: name: parallel-lint-phar @@ -109,7 +109,7 @@ jobs: - verify steps: - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v3 with: name: parallel-lint-phar diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 741b7b6..aba3cf2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,7 +28,7 @@ jobs: tools: cs2pr - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Install Composer dependencies uses: ramsey/composer-install@v2 @@ -46,7 +46,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -77,7 +77,7 @@ jobs: - name: Show info about the build phar with humbug/box run: php box.phar info -l parallel-lint.phar - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 with: name: parallel-lint-phar path: ./parallel-lint.phar @@ -109,7 +109,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -141,7 +141,7 @@ jobs: if: ${{ matrix.php >= 5.6 }} run: composer test - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v3 with: name: parallel-lint-phar From 5a4d8eb4963ba045e34697e82da76823b6f1f007 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 20 Feb 2022 17:07:02 +0100 Subject: [PATCH 06/23] SyntaxError::translateTokens(): prevent double translation Generally speaking, the `$translate` parameter for the `SyntaxError::getNormalizedMessage()` method should only be passed as `true` when on a PHP version which doesn't do the PHP native token translation yet. However, in edge cases, it could be possible that tokens could be double "translated", both by PHP itself as well as by the `SyntaxError::translateTokens()` method. This minor fix prevents this by not matching token names when surrounded by parentheses. --- src/Error.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Error.php b/src/Error.php index 0c9f65f..7d611ca 100644 --- a/src/Error.php +++ b/src/Error.php @@ -194,7 +194,7 @@ protected function translateTokens($message) 'T_ECHO' => 'echo' ); - return preg_replace_callback('~T_([A-Z_]*)~', function ($matches) use ($translateTokens) { + return preg_replace_callback('~(? Date: Sun, 20 Feb 2022 18:36:50 +0100 Subject: [PATCH 07/23] SyntaxError::getNormalizedMessage(): bug fix - file name containing regex delimiter If a file name would contain the delimiter used in the replacement regex, it would cause a PHP error like `preg_replace(): Unknown modifier 'f'`. Fixed by telling `preg_quote()` explicitly which delimiter is being used. Includes unit test. Ref: https://www.php.net/manual/en/function.preg-quote.php --- src/Error.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Error.php b/src/Error.php index 7d611ca..19eb01e 100644 --- a/src/Error.php +++ b/src/Error.php @@ -132,7 +132,7 @@ public function getLine() public function getNormalizedMessage($translateTokens = false) { $message = preg_replace('~^(Parse|Fatal) error: (syntax error, )?~', '', $this->message); - $message = preg_replace('~ in ' . preg_quote(basename($this->filePath)) . ' on line [0-9]+$~', '', $message); + $message = preg_replace('~ in ' . preg_quote(basename($this->filePath), '~') . ' on line [0-9]+$~', '', $message); $message = ucfirst($message); if ($translateTokens) { From b8d515ccd3e2f120e6156201d6a6f376b2f1ccfd Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 20 Feb 2022 18:39:32 +0100 Subject: [PATCH 08/23] SyntaxError::getNormalizedMessage(): bug fix - "in file on line" doesn't always get stripped In certain cases, PHP puts the full file name in the error message. In those cases the "in filename.php on line .." trailing part of the error message did not get stripped off. Also, in some cases, when Windows slashes are used in the file path, the "in filename.php on line .." trailing part of the error message may not get stripped off. This last case will be exceedingly rare as on Windows, those file paths are handled correctly and the chances of a non-Windows user passing a path using Windows slashes will be minuscule. Even so, I've fixed both cases by making the path handling in the function more robust. * When the initial stripping of the trailing part of the error message fails, it will be retried up to two times. * The first time, if Windows slashes would be found in the file path _after_ the `basename()` function has been applied, a "manual" basename extraction is done and the stripping of the trailing part is retried. * The second time, the full file path is used in a last attempt to strip the trailing part of the error message. Fixes 94 --- src/Error.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Error.php b/src/Error.php index 19eb01e..61cace9 100644 --- a/src/Error.php +++ b/src/Error.php @@ -107,6 +107,8 @@ function jsonSerialize() class SyntaxError extends Error { + const IN_ON_REGEX = '~ in %s on line [0-9]+$~'; + /** @var Blame */ private $blame; @@ -131,8 +133,22 @@ public function getLine() */ public function getNormalizedMessage($translateTokens = false) { - $message = preg_replace('~^(Parse|Fatal) error: (syntax error, )?~', '', $this->message); - $message = preg_replace('~ in ' . preg_quote(basename($this->filePath), '~') . ' on line [0-9]+$~', '', $message); + $message = preg_replace('~^(Parse|Fatal) error: (syntax error, )?~', '', $this->message); + $baseName = basename($this->filePath); + $regex = sprintf(self::IN_ON_REGEX, preg_quote($baseName, '~')); + $message = preg_replace($regex, '', $message, -1, $count); + + if ($count === 0 && strpos($baseName, '\\') !== false) { + $baseName = ltrim(strrchr($this->filePath, '\\'), '\\'); + $regex = sprintf(self::IN_ON_REGEX, preg_quote($baseName, '~')); + $message = preg_replace($regex, '', $message, -1, $count); + } + + if ($count === 0) { + $regex = sprintf(self::IN_ON_REGEX, preg_quote($this->filePath, '~')); + $message = preg_replace($regex, '', $message); + } + $message = ucfirst($message); if ($translateTokens) { From d054056b7e1e168057ff5fe3f9b0b4211d269d6c Mon Sep 17 00:00:00 2001 From: Daniel Schmelz Date: Sat, 20 Aug 2022 17:54:50 +0200 Subject: [PATCH 09/23] Fix typos --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ca3deb5..61bbf34 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![Build Status](https://github.com/php-parallel-lint/PHP-Parallel-Lint/actions/workflows/test.yml/badge.svg)](https://github.com/php-parallel-lint/PHP-Parallel-Lint/actions/workflows/test.yml) [![License](https://poser.pugx.org/php-parallel-lint/php-parallel-lint/license.svg)](https://packagist.org/packages/php-parallel-lint/php-parallel-lint) -This application checks syntax of PHP files in parallel. +This application checks the syntax of PHP files in parallel. It can output in plain text, colored text, json and checksyntax formats. Additionally `blame` can be used to show commits that introduced the breakage. @@ -72,7 +72,7 @@ It is strongly recommended for existing users of the (unmaintained) - `-a`, `--asp` Set asp_tags to On (default: Off). - `-e ` Check only files with selected extensions separated by comma. (default: php,php3,php4,php5,phtml,phpt) - `-j ` Run jobs in parallel (default: 10). -- `--exclude` Exclude a file or directory. If you want exclude multiple items, use multiple exclude parameters. +- `--exclude` Exclude a file or directory. If you want to exclude multiple items, use multiple exclude parameters. - `--colors` Enable colors in console output. (disables auto detection of color support) - `--no-colors` Disable colors in console output. - `--no-progress` Disable progress in console output. @@ -116,7 +116,7 @@ Note: The `// lint >= 7.4` comment has to be only the first line of the file and ## How to upgrade -Are you using `jakub-onderka/php-parallel-lint` package? You can switch to `php-parallel-lint/php-parallel-lint` using: +Are you using the `jakub-onderka/php-parallel-lint` package? You can switch to `php-parallel-lint/php-parallel-lint` using: composer remove --dev jakub-onderka/php-parallel-lint composer require --dev php-parallel-lint/php-parallel-lint From 9256c4490524f9da0a05ec88b9b111225858021a Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 5 Apr 2022 14:27:20 +0200 Subject: [PATCH 10/23] GH Actions: fix download URL for box Looks like the box project has moved organisations, so let's update the URL used to download the PHAR. As GitHub will automatically redirect moved URLs, I'm only pulling this to the `develop` branch. --- .github/workflows/release.yml | 4 ++-- .github/workflows/test.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6d1ce4f..b8845fe 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -43,7 +43,7 @@ jobs: # Note: do NOT turn on the requirement checker in the box config as it is no longer # compatible with PHP < 7.2. - name: Install Box - run: wget https://github.com/humbug/box/releases/latest/download/box.phar -O box.phar && chmod 0755 box.phar && pwd + run: wget https://github.com/box-project/box/releases/latest/download/box.phar -O box.phar && chmod 0755 box.phar && pwd - name: Validate configuration run: php box.phar validate -i box.json @@ -51,7 +51,7 @@ jobs: - name: Building binary... run: php box.phar compile -v --config=box.json - - name: Show info about the build phar with humbug/box + - name: Show info about the build phar with box-project/box run: php box.phar info -l parallel-lint.phar - uses: actions/upload-artifact@v3 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index aba3cf2..dd3510c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -66,7 +66,7 @@ jobs: # Note: do NOT turn on the requirement checker in the box config as it is no longer # compatible with PHP < 7.2. - name: Install Box - run: wget https://github.com/humbug/box/releases/latest/download/box.phar -O box.phar && chmod 0755 box.phar && pwd + run: wget https://github.com/box-project/box/releases/latest/download/box.phar -O box.phar && chmod 0755 box.phar && pwd - name: Validate configuration run: php box.phar validate -i box.json @@ -74,7 +74,7 @@ jobs: - name: Building binary... run: php box.phar compile -v --config=box.json - - name: Show info about the build phar with humbug/box + - name: Show info about the build phar with box-project/box run: php box.phar info -l parallel-lint.phar - uses: actions/upload-artifact@v3 From a528a8a09c06884d876c2335c138f3dc3d564def Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 23 Oct 2022 12:00:14 +0200 Subject: [PATCH 11/23] GH Actions: harden the workflow against PHPCS ruleset errors If there is a ruleset error, the `cs2pr` action doesn't receive an `xml` report and exits with a `0` error code, even though the PHPCS run failed (though not on CS errors, but on a ruleset error). This changes the GH Actions workflow to allow for that situation and still fail the build in that case. --- .github/workflows/test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dd3510c..bb89e38 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,10 +34,11 @@ jobs: uses: ramsey/composer-install@v2 - name: Run code sniffer - continue-on-error: true + id: phpcs run: vendor/bin/phpcs --report-full --report-checkstyle=./phpcs-report.xml - name: Show PHPCS results in PR + if: ${{ always() && steps.phpcs.outcome == 'failure' }} run: cs2pr ./phpcs-report.xml bundle: From 4d0a65a4fff082b8b36b00bd05b9c00d1408f6e7 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 9 Dec 2022 02:22:31 +0100 Subject: [PATCH 12/23] GH Actions: update PHP versions in workflows PHP 8.2 has been released today :tada: and the `setup-php` action has announced support for PHP 8.3, so adding PHP 8.3 to the matrix and no longer allowing PHP 8.2 to fail the build. Builds against PHP 8.3 are still allowed to fail for now. Includes minor tweak setting PHP to `latest` for tasks where the PHP version isn't that relevant. --- .github/workflows/test.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bb89e38..2a43550 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,7 +23,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '7.4' + php-version: 'latest' coverage: none tools: cs2pr @@ -125,8 +125,15 @@ jobs: run: composer remove --dev squizlabs/php_codesniffer --no-update --no-interaction - name: Install Composer dependencies + if: ${{ matrix.php != '8.3' }} uses: ramsey/composer-install@v2 + - name: "Install Composer dependencies (PHP 8.3, ignore PHP reqs)" + if: ${{ matrix.php == '8.3' }} + uses: ramsey/composer-install@v2 + with: + composer-options: --ignore-platform-req=php + - name: 'Integration test 1 - linting own code, no colors' continue-on-error: true run: ./parallel-lint --exclude vendor --exclude tests/examples --no-colors . From 96095f0e46e417466861a0ccc7c626947586b068 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 4 Nov 2022 19:51:20 +0100 Subject: [PATCH 13/23] GH Actions: bust the cache semi-regularly Caches used in GH Actions do not get updated, they can only be replaced by a different cache with a different cache key. Now the predefined Composer install action this repo is using already creates a pretty comprehensive cache key: > `ramsey/composer-install` will auto-generate a cache key which is composed of the following elements: > * The OS image name, like `ubuntu-latest`. > * The exact PHP version, like `8.1.11`. > * The options passed via `composer-options`. > * The dependency version setting as per `dependency-versions`. > * The working directory as per `working-directory`. > * A hash of the `composer.json` and/or `composer.lock` files. This means that aside from other factors, the cache will always be busted when changes are made to the (committed) `composer.json` or the `composer.lock` file (if the latter exists in the repo). For packages running on recent versions of PHP, it also means that the cache will automatically be busted once a month when a new PHP version comes out. ### The problem For runs on older PHP versions which don't receive updates anymore, the cache will not be busted via new PHP version releases, so effectively, the cache will only be busted when a change is made to the `composer.json`/`composer.lock` file - which may not happen that frequently on low-traffic repos. But... packages _in use_ on those older PHP versions - especially dependencies of declared dependencies - may still release new versions and those new versions will not exist in the cache and will need to be downloaded each time the action is run and over time the cache gets less and less relevant as more and more packages will need to be downloaded for each run. ### The solution To combat this issue, a new `custom-cache-suffix` option has been added to the Composer install action in version 2.2.0. This new option allows for providing some extra information to add to the cache key, which allows for busting the cache based on your own additional criteria. This commit implements the use of this `custom-cache-suffix` option for all relevant workflows in this repo. Refs: * https://github.com/ramsey/composer-install/#custom-cache-suffix * https://github.com/ramsey/composer-install/releases/tag/2.2.0 --- .github/workflows/release.yml | 2 ++ .github/workflows/test.yml | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b8845fe..d53023d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -39,6 +39,8 @@ jobs: uses: ramsey/composer-install@v2 with: composer-options: "--no-dev" + # Bust the cache at least once a month - output format: YYYY-MM. + custom-cache-suffix: $(date -u "+%Y-%m") # Note: do NOT turn on the requirement checker in the box config as it is no longer # compatible with PHP < 7.2. diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2a43550..f6e497c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,6 +32,9 @@ jobs: - name: Install Composer dependencies uses: ramsey/composer-install@v2 + with: + # Bust the cache at least once a month - output format: YYYY-MM. + custom-cache-suffix: $(date -u "+%Y-%m") - name: Run code sniffer id: phpcs @@ -63,6 +66,8 @@ jobs: uses: ramsey/composer-install@v2 with: composer-options: "--no-dev" + # Bust the cache at least once a month - output format: YYYY-MM. + custom-cache-suffix: $(date -u "+%Y-%m") # Note: do NOT turn on the requirement checker in the box config as it is no longer # compatible with PHP < 7.2. @@ -127,12 +132,16 @@ jobs: - name: Install Composer dependencies if: ${{ matrix.php != '8.3' }} uses: ramsey/composer-install@v2 + with: + # Bust the cache at least once a month - output format: YYYY-MM. + custom-cache-suffix: $(date -u "+%Y-%m") - name: "Install Composer dependencies (PHP 8.3, ignore PHP reqs)" if: ${{ matrix.php == '8.3' }} uses: ramsey/composer-install@v2 with: composer-options: --ignore-platform-req=php + custom-cache-suffix: $(date -u "+%Y-%m") - name: 'Integration test 1 - linting own code, no colors' continue-on-error: true From 3bc9df2da0615bc1445204108ff882b91e6e0867 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 11 Dec 2022 07:43:56 +0100 Subject: [PATCH 14/23] GH Actions: use `fail-fast` with setup-php when creating the binaries The recent build failure was due to the `setup-php` action running into a rate limit and not downloading the required version of Composer (`2.2`), which meant that the PHAR ended up being build with Composer 2.4. The `setup-php` action runner defaults to _showing_ these type errors in the logs, but not stopping the workflow run. For the creation of the binary it is really important that the correct Composer version is used as otherwise the PHAR file won't be compatible with PHP 5.3 - 5.5. So, specifically for those jobs, I'm adding the `fail-fast` option to `setup-php` to fail the build if the action runner ran into any errors. Ref: https://github.com/shivammathur/setup-php#fail-fast-optional --- .github/workflows/release.yml | 1 + .github/workflows/test.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d53023d..558dd14 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -34,6 +34,7 @@ jobs: ini-values: phar.readonly=Off, error_reporting=-1, display_errors=On, zend.assertions=1 # Autoload files generated with Composer 2.3 are not compatible with PHP < 7.0. tools: composer:2.2 + fail-fast: true - name: Install Composer dependencies uses: ramsey/composer-install@v2 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f6e497c..fe4601e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -61,6 +61,7 @@ jobs: ini-values: phar.readonly=Off, error_reporting=-1, display_errors=On, zend.assertions=1 # Autoload files generated with Composer 2.3 are not compatible with PHP < 7.0. tools: composer:2.2 + fail-fast: true - name: Install Composer dependencies uses: ramsey/composer-install@v2 From c7efb9a666a03c104f062dbf26d1bcf80352eafd Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 20 Dec 2022 15:08:49 +0100 Subject: [PATCH 15/23] GH Actions: fix up fail-fast for setup-php Follow up on PR #131 Oops... realized I implemented it incorrectly. Fixed now. --- .github/workflows/release.yml | 1 + .github/workflows/test.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 558dd14..ededca9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -34,6 +34,7 @@ jobs: ini-values: phar.readonly=Off, error_reporting=-1, display_errors=On, zend.assertions=1 # Autoload files generated with Composer 2.3 are not compatible with PHP < 7.0. tools: composer:2.2 + env: fail-fast: true - name: Install Composer dependencies diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fe4601e..1f9fcb8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -61,6 +61,7 @@ jobs: ini-values: phar.readonly=Off, error_reporting=-1, display_errors=On, zend.assertions=1 # Autoload files generated with Composer 2.3 are not compatible with PHP < 7.0. tools: composer:2.2 + env: fail-fast: true - name: Install Composer dependencies From 3d01e89a9b630d3060818223e0ab7c2a45b46e0c Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 16 Mar 2024 19:18:19 +0100 Subject: [PATCH 16/23] Align the percentage output Left pad with whitespace so that the 100% line doesn't pop out of alignment. --- src/Output.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Output.php b/src/Output.php index 7b72915..dc2c94a 100644 --- a/src/Output.php +++ b/src/Output.php @@ -348,9 +348,9 @@ protected function writeMark($type) protected function writePercent() { - $percent = floor($this->checkedFiles / $this->totalFileCount * 100); + $percent = $this->stringWidth(floor($this->checkedFiles / $this->totalFileCount * 100), 3); $current = $this->stringWidth($this->checkedFiles, strlen($this->totalFileCount)); - $this->writeLine(" $current/$this->totalFileCount ($percent %)"); + $this->writeLine(" $current/$this->totalFileCount ($percent%)"); } /** From 7212796a56baaea11005a5192279b62556c7d384 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 16 Mar 2024 19:49:49 +0100 Subject: [PATCH 17/23] Composer: update keywords Since Composer 2.4.0, Composer will prompt users if they are sure they want to install something as `require` instead of `require-dev` if the package contains certain "dev" related keyword, like `static analysis`. This adds the keywords to this package to help users add the package in the most appropriate place. Refs: * https://getcomposer.org/doc/04-schema.md#keywords * https://github.com/composer/composer/pull/10960 Co-authored-by: Markus Staab --- composer.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/composer.json b/composer.json index 5e36b1e..cdec2a0 100644 --- a/composer.json +++ b/composer.json @@ -3,6 +3,10 @@ "description": "This tool checks the syntax of PHP files about 20x faster than serial check.", "homepage": "https://github.com/php-parallel-lint/PHP-Parallel-Lint", "license": "BSD-2-Clause", + "keywords": [ + "lint", + "static analysis" + ], "authors": [ { "name": "Jakub Onderka", From 222c1d038d9123e3b9b28aa610690659bd9b73a2 Mon Sep 17 00:00:00 2001 From: Alexandru Benzari Date: Tue, 8 Aug 2023 11:00:32 +0100 Subject: [PATCH 18/23] Skip shebang sequence if it is the first line --- bin/skip-linting.php | 6 ++++++ tests/ParallelLint.lint.phpt | 10 ++++++++++ tests/examples/example-07/example.php | 5 +++++ 3 files changed, 21 insertions(+) create mode 100644 tests/examples/example-07/example.php diff --git a/bin/skip-linting.php b/bin/skip-linting.php index 2c69554..9cb552b 100644 --- a/bin/skip-linting.php +++ b/bin/skip-linting.php @@ -8,6 +8,12 @@ $f = @fopen($file, 'r'); if ($f) { $firstLine = fgets($f); + + // ignore shebang line + if (strpos($firstLine, '#!') === 0) { + $firstLine = fgets($f); + } + @fclose($f); if (preg_match('~getErrors())); } + public function testSkipShebang() + { + $parallelLint = new ParallelLint($this->getPhpExecutable()); + $result = $parallelLint->lint(array(__DIR__ . '/examples/example-07/example.php')); + + Assert::equal(0, $result->getCheckedFilesCount()); + Assert::equal(0, $result->getFilesWithSyntaxErrorCount()); + Assert::equal(1, $result->getSkippedFilesCount()); + } + public function testInvalidFile() { $parallelLint = new ParallelLint($this->getPhpExecutable()); diff --git a/tests/examples/example-07/example.php b/tests/examples/example-07/example.php new file mode 100644 index 0000000..a1f4e99 --- /dev/null +++ b/tests/examples/example-07/example.php @@ -0,0 +1,5 @@ +#!/usr/bin/php + Date: Sat, 16 Mar 2024 02:39:58 +0700 Subject: [PATCH 19/23] [PHP 8.4] Fixes for implicit nullability deprecation Fixes all issues that emit deprecation notices on PHP 8.4 for implicit nullable parameter type declarations. See: - [RFC](https://wiki.php.net/rfc/deprecate-implicitly-nullable-types) - [PHP 8.4: Implicitly nullable parameter declarations deprecated](https://php.watch/versions/8.4/implicitly-marking-parameter-type-nullable-deprecated) --- src/Manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Manager.php b/src/Manager.php index 84b7434..6b852e0 100644 --- a/src/Manager.php +++ b/src/Manager.php @@ -17,7 +17,7 @@ class Manager * @throws Exception * @throws \Exception */ - public function run(Settings $settings = null) + public function run(?Settings $settings = null) { $settings = $settings ?: new Settings; $output = $this->output ?: $this->getDefaultOutput($settings); From b9df728a352e3aa132cbe5ff5e298fb577ec0295 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 16 Mar 2024 19:57:34 +0100 Subject: [PATCH 20/23] Make PHP 8.4 implicit nullability fix compatible with PHP < 7.1 --- src/Manager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Manager.php b/src/Manager.php index 6b852e0..31d26ad 100644 --- a/src/Manager.php +++ b/src/Manager.php @@ -17,9 +17,9 @@ class Manager * @throws Exception * @throws \Exception */ - public function run(?Settings $settings = null) + public function run($settings = null) { - $settings = $settings ?: new Settings; + $settings = ($settings instanceof Settings) ? $settings : new Settings(); $output = $this->output ?: $this->getDefaultOutput($settings); $phpExecutable = PhpExecutable::getPhpExecutable($settings->phpExecutable); From a28efcc9c19e5a8ab7949b26be7af5931e2eaee6 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 16 Mar 2024 20:33:13 +0100 Subject: [PATCH 21/23] OutputTest: fix risky test The `OutputTest::testGitLabOutput()` was being marked as risky for the first test case (no errors) as no assertions were being run. This commit adds an extra assertion to prevent this, but also to make the test more thorough as the test will now also fail if the number of errors expected versus received does not match. --- tests/Output.phpt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Output.phpt b/tests/Output.phpt index 407c569..afea8e1 100644 --- a/tests/Output.phpt +++ b/tests/Output.phpt @@ -31,6 +31,8 @@ class OutputTest extends Tester\TestCase $result = (array) json_decode($writer->getLogs()); + Assert::equal(count($errors), count($result)); + for ($i = 0; $i < count($result) && $i < count($errors); $i++) { $message = $errors[$i]->getMessage(); $filePath = $errors[$i]->getFilePath(); From c18e8ad2bc40f146aeb749535a8fa908d5cef070 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 16 Mar 2024 21:23:03 +0100 Subject: [PATCH 22/23] GH Actions: version update for various predefined actions A number of predefined actions have had major releases, which warrant an update to the workflow(s). These updates don't actually contain any changed functionality, they are mostly just a change of the Node version used by the action itself (from Node 16 to Node 20). Refs: * https://github.com/actions/checkout/releases * https://github.com/actions/download-artifact/releases * https://github.com/actions/upload-artifact/releases * https://github.com/ramsey/composer-install/releases * https://github.com/softprops/action-gh-release/releases --- .github/workflows/release.yml | 14 +++++++------- .github/workflows/test.yml | 18 +++++++++--------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ededca9..01e9e0a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -23,7 +23,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -38,7 +38,7 @@ jobs: fail-fast: true - name: Install Composer dependencies - uses: ramsey/composer-install@v2 + uses: ramsey/composer-install@v3 with: composer-options: "--no-dev" # Bust the cache at least once a month - output format: YYYY-MM. @@ -58,7 +58,7 @@ jobs: - name: Show info about the build phar with box-project/box run: php box.phar info -l parallel-lint.phar - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: name: parallel-lint-phar path: ./parallel-lint.phar @@ -89,9 +89,9 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: parallel-lint-phar @@ -113,7 +113,7 @@ jobs: - verify steps: - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: parallel-lint-phar @@ -129,7 +129,7 @@ jobs: - name: Upload Phar as Release Asset id: upload-release-asset - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v2 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1f9fcb8..d6de46c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,10 +28,10 @@ jobs: tools: cs2pr - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install Composer dependencies - uses: ramsey/composer-install@v2 + uses: ramsey/composer-install@v3 with: # Bust the cache at least once a month - output format: YYYY-MM. custom-cache-suffix: $(date -u "+%Y-%m") @@ -50,7 +50,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -65,7 +65,7 @@ jobs: fail-fast: true - name: Install Composer dependencies - uses: ramsey/composer-install@v2 + uses: ramsey/composer-install@v3 with: composer-options: "--no-dev" # Bust the cache at least once a month - output format: YYYY-MM. @@ -85,7 +85,7 @@ jobs: - name: Show info about the build phar with box-project/box run: php box.phar info -l parallel-lint.phar - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: name: parallel-lint-phar path: ./parallel-lint.phar @@ -117,7 +117,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -133,14 +133,14 @@ jobs: - name: Install Composer dependencies if: ${{ matrix.php != '8.3' }} - uses: ramsey/composer-install@v2 + uses: ramsey/composer-install@v3 with: # Bust the cache at least once a month - output format: YYYY-MM. custom-cache-suffix: $(date -u "+%Y-%m") - name: "Install Composer dependencies (PHP 8.3, ignore PHP reqs)" if: ${{ matrix.php == '8.3' }} - uses: ramsey/composer-install@v2 + uses: ramsey/composer-install@v3 with: composer-options: --ignore-platform-req=php custom-cache-suffix: $(date -u "+%Y-%m") @@ -160,7 +160,7 @@ jobs: if: ${{ matrix.php >= 5.6 }} run: composer test - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: parallel-lint-phar From c3b494c9f3768fc69cad1fd6e817d01eaa911c25 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 16 Mar 2024 22:03:05 +0100 Subject: [PATCH 23/23] GH Actions: fix duplicate release As things were, the workflow was creating two releases, one in draft and one published, but without a good name/changelog. I noticed this last time there was a release, but never got round to fixing it (and it wasn't urgent as no new release was needed). As a new release is needed soon, now seemed like a good time to fix this. The `actions/create-release` action runner has been abandoned and mentions the `softprops/action-gh-release` action runner as a replacement. This commit now updates the workflow to solely use the `softprops/action-gh-release` action runner and updates the version and configuration to make sure it only creates a draft release, so we can still edit it and add the changelog before publishing. --- .github/workflows/release.yml | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 01e9e0a..6c7948d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -118,19 +118,12 @@ jobs: name: parallel-lint-phar - name: Draft Release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: softprops/action-gh-release@v2 with: tag_name: ${{ github.ref }} release_name: Release ${{ github.ref }} draft: true prerelease: false - - - name: Upload Phar as Release Asset - id: upload-release-asset - uses: softprops/action-gh-release@v2 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: + make_latest: true files: parallel-lint.phar + fail_on_unmatched_files: true