From 200d593f3cc96724d1abaa9dfee3df1812eb8af0 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 21 Dec 2020 02:42:55 +0100 Subject: [PATCH 01/29] Readme: minor fixes to badge links --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 29742ed..b1029eb 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,9 @@ PHPCSDevTools for developers of PHP_CodeSniffer sniffs [![Last Commit to Unstable](https://img.shields.io/github/last-commit/PHPCSStandards/PHPCSDevTools/develop.svg)](https://github.com/PHPCSStandards/PHPCSDevTools/commits/develop) [![Minimum PHP Version](https://img.shields.io/packagist/php-v/phpcsstandards/phpcsdevtools.svg?maxAge=3600)](https://packagist.org/packages/phpcsstandards/phpcsdevtools) -[![Build Status CS](https://github.com/PHPCSStandards/PHPCSDevTools/workflows/CS/badge.svg?branch=develop)](https://github.com/PHPCSStandards/PHPCSDevTools/actions) -[![Build Status Test](https://github.com/PHPCSStandards/PHPCSDevTools/workflows/Test/badge.svg?branch=develop)](https://github.com/PHPCSStandards/PHPCSDevTools/actions) -[![Tested on PHP 5.4 to nightly](https://img.shields.io/badge/tested%20on-PHP%205.4%20|%205.5%20|%205.6%20|%207.0%20|%207.1%20|%207.2%20|%207.3%20|%207.4%20|%208.0%20|%20nightly-brightgreen.svg?maxAge=2419200)](https://travis-ci.com/PHPCSStandards/PHPCSDevTools) +[![Build Status CS](https://github.com/PHPCSStandards/PHPCSDevTools/workflows/CS/badge.svg?branch=develop)](https://github.com/PHPCSStandards/PHPCSDevTools/actions?query=workflow%3ACS) +[![Build Status Test](https://github.com/PHPCSStandards/PHPCSDevTools/workflows/Test/badge.svg?branch=develop)](https://github.com/PHPCSStandards/PHPCSDevTools/actions?query=workflow%3ATest) +[![Tested on PHP 5.4 to nightly](https://img.shields.io/badge/tested%20on-PHP%205.4%20|%205.5%20|%205.6%20|%207.0%20|%207.1%20|%207.2%20|%207.3%20|%207.4%20|%208.0%20|%20nightly-brightgreen.svg?maxAge=2419200)](https://github.com/PHPCSStandards/PHPCSDevTools/actions?query=workflow%3ATest) [![License: LGPLv3](https://poser.pugx.org/phpcsstandards/phpcsdevtools/license)](https://github.com/PHPCSStandards/PHPCSDevTools/blob/stable/LICENSE) ![Awesome](https://img.shields.io/badge/awesome%3F-yes!-brightgreen.svg) From 639358116b259fdbd3ab5f66582c3bae0f18835e Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 27 Feb 2021 15:16:19 +0100 Subject: [PATCH 02/29] GH Actions: don't ignore markdown-only changes ... as it doesn't play nice with required statuses. --- .github/workflows/cs.yml | 4 ---- .github/workflows/quicktest.yml | 2 -- .github/workflows/test.yml | 2 -- 3 files changed, 8 deletions(-) diff --git a/.github/workflows/cs.yml b/.github/workflows/cs.yml index 31b658c..517902a 100644 --- a/.github/workflows/cs.yml +++ b/.github/workflows/cs.yml @@ -4,11 +4,7 @@ on: # Run on all pushes and on all pull requests. # Prevent the build from running when there are only irrelevant changes. push: - paths-ignore: - - '**.md' pull_request: - paths-ignore: - - '**.md' jobs: checkcs: diff --git a/.github/workflows/quicktest.yml b/.github/workflows/quicktest.yml index b3ed032..df3e79e 100644 --- a/.github/workflows/quicktest.yml +++ b/.github/workflows/quicktest.yml @@ -5,8 +5,6 @@ on: push: branches-ignore: - stable - paths-ignore: - - '**.md' jobs: #### QUICK TEST STAGE #### diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index faa237d..2f8d384 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,8 +6,6 @@ on: branches: - stable pull_request: - paths-ignore: - - '**.md' jobs: #### TEST STAGE #### From 470a6aa9f1856e547f7a5d0bea8d6a1f3c3ac94f Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 27 Feb 2021 15:16:48 +0100 Subject: [PATCH 03/29] GH Actions: allow for manually triggering a workflow Triggering a workflow for a branch manually is not supported by default in GH Actions, but has to be explicitly allowed. Ref: https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/ --- .github/workflows/cs.yml | 2 ++ .github/workflows/quicktest.yml | 2 ++ .github/workflows/test.yml | 2 ++ 3 files changed, 6 insertions(+) diff --git a/.github/workflows/cs.yml b/.github/workflows/cs.yml index 517902a..218e678 100644 --- a/.github/workflows/cs.yml +++ b/.github/workflows/cs.yml @@ -5,6 +5,8 @@ on: # Prevent the build from running when there are only irrelevant changes. push: pull_request: + # Allow manually triggering the workflow. + workflow_dispatch: jobs: checkcs: diff --git a/.github/workflows/quicktest.yml b/.github/workflows/quicktest.yml index df3e79e..f47b312 100644 --- a/.github/workflows/quicktest.yml +++ b/.github/workflows/quicktest.yml @@ -5,6 +5,8 @@ on: push: branches-ignore: - stable + # Allow manually triggering the workflow. + workflow_dispatch: jobs: #### QUICK TEST STAGE #### diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2f8d384..244a3e1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,6 +6,8 @@ on: branches: - stable pull_request: + # Allow manually triggering the workflow. + workflow_dispatch: jobs: #### TEST STAGE #### From 5fe6eb2cedc77e4b04eb14d76e981fdcb07dd9cd Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 27 Feb 2021 15:20:39 +0100 Subject: [PATCH 04/29] GH Actions: report CS violations in the PR The cs2pr tool will allow to display the results from an action run in checkstyle format in-line in the PR code view, which should improve usability of the workflow results. Ref: https://github.com/staabm/annotate-pull-request-from-checkstyle --- .github/workflows/cs.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cs.yml b/.github/workflows/cs.yml index 218e678..6a0c40b 100644 --- a/.github/workflows/cs.yml +++ b/.github/workflows/cs.yml @@ -25,6 +25,7 @@ jobs: with: php-version: '7.4' coverage: none + tools: cs2pr - name: 'Composer: adjust dependencies' run: | @@ -56,7 +57,11 @@ jobs: # Check the code-style consistency of the PHP files. - name: Check PHP code style - run: composer check-cs + continue-on-error: true + run: composer check-cs -- --report-full --report-checkstyle=./phpcs-report.xml + + - name: Show PHPCS results in PR + run: cs2pr ./phpcs-report.xml # Validate the composer.json file. # @link https://getcomposer.org/doc/03-cli.md#validate From 93afec9fc023acaf5c09f0945ddfd306d9fcc5d2 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 27 Feb 2021 16:36:30 +0100 Subject: [PATCH 05/29] GH Actions: report linting violations in the PR The cs2pr tool will allow to display the results from an action run in checkstyle format in-line in the PR code view, which should improve usability of the workflow results. Ref: https://github.com/staabm/annotate-pull-request-from-checkstyle --- .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 244a3e1..d11520e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -84,6 +84,7 @@ jobs: php-version: ${{ matrix.php }} ini-values: ${{ steps.set_ini.outputs.PHP_INI }} coverage: none + tools: cs2pr - name: 'Composer: adjust dependencies' run: | @@ -107,7 +108,7 @@ jobs: - name: Lint against parse errors if: matrix.phpcs_version == 'dev-master' - run: composer lint + run: composer lint -- --checkstyle | cs2pr # Check that any sniffs available are feature complete. # This also acts as an integration test for the feature completeness script, From e904bb76277e12eb40dd65fd0cdb755bf76bc269 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 21 Jun 2021 23:29:50 +0200 Subject: [PATCH 06/29] GH Actions: turn display_errors on Turns out the default setting for `error_reporting` used by the SetupPHP action is `error_reporting=E_ALL & ~E_DEPRECATED & ~E_STRICT` and `display_errors` is set to `Off`. For the purposes of CI, I'd recommend running with `E_ALL` and `display_errors=On` to ensure **all** PHP notices are shown. In this script, error_reporting was already enabled, but the error display was not yet fixed. Sorted now. --- .github/workflows/quicktest.yml | 4 ++-- .github/workflows/test.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/quicktest.yml b/.github/workflows/quicktest.yml index f47b312..fb60805 100644 --- a/.github/workflows/quicktest.yml +++ b/.github/workflows/quicktest.yml @@ -41,9 +41,9 @@ jobs: id: set_ini run: | if [ "${{ matrix.phpcs_version }}" != "dev-master" ]; then - echo '::set-output name=PHP_INI::error_reporting=E_ALL & ~E_DEPRECATED' + echo '::set-output name=PHP_INI::error_reporting=E_ALL & ~E_DEPRECATED, display_errors=On' else - echo '::set-output name=PHP_INI::error_reporting=E_ALL' + echo '::set-output name=PHP_INI::error_reporting=E_ALL, display_errors=On' fi - name: Install PHP diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d11520e..7e09325 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -73,9 +73,9 @@ jobs: # On stable PHPCS versions, allow for PHP deprecation notices. # Unit tests don't need to fail on those for stable releases where those issues won't get fixed anymore. if [[ "${{ matrix.phpcs_version }}" != "dev-master" && "${{ matrix.phpcs_version }}" != "4.0.x-dev" ]]; then - echo '::set-output name=PHP_INI::error_reporting=E_ALL & ~E_DEPRECATED' + echo '::set-output name=PHP_INI::error_reporting=E_ALL & ~E_DEPRECATED, display_errors=On' else - echo '::set-output name=PHP_INI::error_reporting=E_ALL' + echo '::set-output name=PHP_INI::error_reporting=E_ALL, display_errors=On' fi - name: Install PHP From 9bcfe74e77964fcb8e6ddfd236ea4af019f7f756 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 19 Sep 2021 23:23:09 +0200 Subject: [PATCH 07/29] Composer: update dev dependencies Most notably, PHP Parallel Lint 1.3.1 has improved compatibility with PHP 8.1. Refs: * https://github.com/php-parallel-lint/PHP-Parallel-Lint/releases/tag/v1.3.1 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f367b92..e1d98b4 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "require-dev" : { "roave/security-advisories" : "dev-master", "phpunit/phpunit" : "^4.5 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0", - "php-parallel-lint/php-parallel-lint": "^1.0", + "php-parallel-lint/php-parallel-lint": "^1.3.1", "php-parallel-lint/php-console-highlighter": "^0.5", "phpcsstandards/phpcsdevcs": "^1.1.1", "phpcsstandards/phpcsutils" : "^1.0" From cdcbbc97df0f298801866d9f9bd763b782616e5d Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 25 Sep 2021 20:21:59 +0200 Subject: [PATCH 08/29] PHPUnit: update configuration PHPUnit just released version 9.5.10 and 8.5.21. This contains a particular (IMO breaking) change: > * PHPUnit no longer converts PHP deprecations to exceptions by default (configure `convertDeprecationsToExceptions="true"` to enable this) Let's unpack this: Previously (PHPUnit < 9.5.10/8.5.21), if PHPUnit would encounter a PHP native deprecation notice, it would: 1. Show a test which causes a deprecation notice to be thrown as **"errored"**, 2. Show the **first** deprecation notice it encountered and 3. PHPUnit would exit with a **non-0 exit code** (2), which will fail a CI build. As of PHPUnit 9.5.10/8.5.21, if PHPUnit encounters a PHP native deprecation notice, it will no longer do so. Instead PHPUnit will: 1. Show a test which causes a PHP deprecation notice to be thrown as **"risky"**, 2. Show the **all** deprecation notices it encountered and 3. PHPUnit will exit with a **0 exit code**, which will show a CI build as passing. This commit reverts PHPUnit to the previous behaviour by adding `convertDeprecationsToExceptions="true"` to the PHPUnit configuration. Refs: * https://github.com/sebastianbergmann/phpunit/blob/9.5/ChangeLog-8.5.md * https://github.com/sebastianbergmann/phpunit/blob/9.5/ChangeLog-9.5.md --- phpunit.xml.dist | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c6d81a1..5b55a72 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -5,6 +5,10 @@ backupGlobals="true" bootstrap="./phpunit-bootstrap.php" beStrictAboutTestsThatDoNotTestAnything="false" + convertErrorsToExceptions="true" + convertWarningsToExceptions="true" + convertNoticesToExceptions="true" + convertDeprecationsToExceptions="true" colors="true" forceCoversAnnotation="true"> From 893694291d09e3735b8366ec87931d0e6bf45ba3 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 23 Dec 2021 01:35:58 +0100 Subject: [PATCH 09/29] Composer: use PHPCSDevCS v 1.1.3 Ref: https://github.com/PHPCSStandards/PHPCSDevCS/releases/tag/1.1.3 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e1d98b4..8bcb49c 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,7 @@ "phpunit/phpunit" : "^4.5 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0", "php-parallel-lint/php-parallel-lint": "^1.3.1", "php-parallel-lint/php-console-highlighter": "^0.5", - "phpcsstandards/phpcsdevcs": "^1.1.1", + "phpcsstandards/phpcsdevcs": "^1.1.3", "phpcsstandards/phpcsutils" : "^1.0" }, "bin": [ From 58ff7ea781b359e9ffc50f5dc5efc817c3c2256b Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 23 Dec 2021 01:36:40 +0100 Subject: [PATCH 10/29] Composer: allow the PHPCS plugin The `dealerdirect/phpcodesniffer-composer-installer` Composer plugin is used to register external PHPCS standards with PHPCS. As of Composer 2.2.0, Composer plugins need to be explicitly allowed to run. This adds the necessary configuration for that. Refs: * https://blog.packagist.com/composer-2-2/#more-secure-plugin-execution --- composer.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/composer.json b/composer.json index 8bcb49c..2cca6e4 100644 --- a/composer.json +++ b/composer.json @@ -32,6 +32,11 @@ "phpcsstandards/phpcsdevcs": "^1.1.3", "phpcsstandards/phpcsutils" : "^1.0" }, + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } + }, "bin": [ "bin/phpcs-check-feature-completeness" ], From a1c672d5dbf84ac473678b27a56d7bfb8c4017da Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 23 Dec 2021 01:40:21 +0100 Subject: [PATCH 11/29] GH Actions: auto-cancel previous builds for same branch Previously, in Travis, when the same branch was pushed again and the "Auto cancellation" option on the "Settings" page had been turned on (as it was for most repos), any still running builds for the same branch would be stopped in favour of starting the build for the newly pushed version of the branch. To enable this behaviour in GH Actions, a `concurrency` configuration needs to be added to each workflow for which this should applied to. More than anything, this is a way to be kind to GitHub by not wasting resources which they so kindly provide to us for free. Refs: * https://github.blog/changelog/2021-04-19-github-actions-limit-workflow-run-or-job-concurrency/ * https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#concurrency --- .github/workflows/cs.yml | 6 ++++++ .github/workflows/quicktest.yml | 6 ++++++ .github/workflows/test.yml | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/.github/workflows/cs.yml b/.github/workflows/cs.yml index 6a0c40b..d44b2e1 100644 --- a/.github/workflows/cs.yml +++ b/.github/workflows/cs.yml @@ -8,6 +8,12 @@ on: # Allow manually triggering the workflow. workflow_dispatch: +# Cancels all previous workflow runs for the same branch that have not yet completed. +concurrency: + # The concurrency group contains the workflow name and the branch name. + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: checkcs: name: 'Basic CS and QA checks' diff --git a/.github/workflows/quicktest.yml b/.github/workflows/quicktest.yml index fb60805..b44cb3f 100644 --- a/.github/workflows/quicktest.yml +++ b/.github/workflows/quicktest.yml @@ -8,6 +8,12 @@ on: # Allow manually triggering the workflow. workflow_dispatch: +# Cancels all previous workflow runs for the same branch that have not yet completed. +concurrency: + # The concurrency group contains the workflow name and the branch name. + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: #### QUICK TEST STAGE #### # This is a much quicker test which only runs the unit tests and linting against the low/high diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7e09325..dc0f003 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,6 +9,12 @@ on: # Allow manually triggering the workflow. workflow_dispatch: +# Cancels all previous workflow runs for the same branch that have not yet completed. +concurrency: + # The concurrency group contains the workflow name and the branch name. + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: #### TEST STAGE #### test: From 64462a15c627b08138e86d9593e0ca2e69b7f0a6 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 23 Dec 2021 01:40:53 +0100 Subject: [PATCH 12/29] GH Actions: use `error_reporting=-1` --- .github/workflows/quicktest.yml | 2 +- .github/workflows/test.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/quicktest.yml b/.github/workflows/quicktest.yml index b44cb3f..96db723 100644 --- a/.github/workflows/quicktest.yml +++ b/.github/workflows/quicktest.yml @@ -49,7 +49,7 @@ jobs: if [ "${{ matrix.phpcs_version }}" != "dev-master" ]; then echo '::set-output name=PHP_INI::error_reporting=E_ALL & ~E_DEPRECATED, display_errors=On' else - echo '::set-output name=PHP_INI::error_reporting=E_ALL, display_errors=On' + echo '::set-output name=PHP_INI::error_reporting=-1, display_errors=On' fi - name: Install PHP diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dc0f003..2561a51 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -81,7 +81,7 @@ jobs: if [[ "${{ matrix.phpcs_version }}" != "dev-master" && "${{ matrix.phpcs_version }}" != "4.0.x-dev" ]]; then echo '::set-output name=PHP_INI::error_reporting=E_ALL & ~E_DEPRECATED, display_errors=On' else - echo '::set-output name=PHP_INI::error_reporting=E_ALL, display_errors=On' + echo '::set-output name=PHP_INI::error_reporting=-1, display_errors=On' fi - name: Install PHP From 0ebff07e61f6895c4295870e10f247c76129b866 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 23 Dec 2021 01:41:10 +0100 Subject: [PATCH 13/29] GH Actions: update for the release of PHP 8.1 --- .github/workflows/test.yml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2561a51..8aaea78 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,12 +29,20 @@ jobs: # - PHP 7.3 needs PHPCS 3.3.1+ to run without errors. # - PHP 7.4 needs PHPCS 3.5.0+ to run without errors. # - PHP 8.0 needs PHPCS 3.5.7+ to run without errors. + # - PHP 8.1 needs PHPCS 3.6.1+ to run without errors. php: ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2'] phpcs_version: ['3.1.0', 'dev-master'] experimental: [false] include: # Complete the matrix, while preventing issues with PHPCS versions incompatible with certain PHP versions. + - php: '8.1' + phpcs_version: 'dev-master' + experimental: false + - php: '8.1' + phpcs_version: '3.6.1' + experimental: false + - php: '8.0' phpcs_version: 'dev-master' experimental: false @@ -61,7 +69,7 @@ jobs: phpcs_version: '4.0.x-dev' experimental: true - - php: '8.1' # Nightly. + - php: '8.2' # Nightly. phpcs_version: 'dev-master' experimental: true @@ -102,12 +110,12 @@ jobs: # Install dependencies and handle caching in one go. # @link https://github.com/marketplace/actions/install-composer-dependencies - name: Install Composer dependencies - normal - if: ${{ matrix.php < 8.1 }} + if: ${{ matrix.php < 8.2 }} uses: "ramsey/composer-install@v1" # For PHP "nightly", we need to install with ignore platform reqs as not all dependencies allow installation. - name: Install Composer dependencies - with ignore platform - if: ${{ matrix.php >= 8.1 }} + if: ${{ matrix.php >= 8.2 }} uses: "ramsey/composer-install@v1" with: composer-options: --ignore-platform-reqs From baaabde9aaf1ede749e2630e391f51715cc4ac9b Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 24 Dec 2021 05:23:56 +0100 Subject: [PATCH 14/29] GH Actions: version update for `ramsey/composer-install` The action used to install Composer packages and handle the caching has released a new major (and some follow-up patch releases), which means, the action reference needs to be updated to benefit from it. Includes adding `--no-interaction` to "plain" Composer commands to potentially prevent CI hanging if, for whatever reason, interaction would be needed in the future. Refs: * https://github.com/ramsey/composer-install/releases/tag/2.0.0 * https://github.com/ramsey/composer-install/releases/tag/2.0.1 * https://github.com/ramsey/composer-install/releases/tag/2.0.2 --- .github/workflows/cs.yml | 6 +++--- .github/workflows/quicktest.yml | 6 +++--- .github/workflows/test.yml | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/cs.yml b/.github/workflows/cs.yml index d44b2e1..36fa8a7 100644 --- a/.github/workflows/cs.yml +++ b/.github/workflows/cs.yml @@ -36,14 +36,14 @@ jobs: - name: 'Composer: adjust dependencies' run: | # The sniff stage doesn't run the unit tests, so no need for PHPUnit. - composer remove --no-update --dev phpunit/phpunit --no-scripts + composer remove --no-update --dev phpunit/phpunit --no-scripts --no-interaction # Using PHPCS `master` as an early detection system for bugs upstream. - composer require --no-update squizlabs/php_codesniffer:"dev-master" + composer require --no-update squizlabs/php_codesniffer:"dev-master" --no-interaction # Install dependencies and handle caching in one go. # @link https://github.com/marketplace/actions/install-composer-dependencies - name: Install Composer dependencies - uses: "ramsey/composer-install@v1" + uses: "ramsey/composer-install@v2" - name: Install xmllint run: sudo apt-get install --no-install-recommends -y libxml2-utils diff --git a/.github/workflows/quicktest.yml b/.github/workflows/quicktest.yml index 96db723..39acac9 100644 --- a/.github/workflows/quicktest.yml +++ b/.github/workflows/quicktest.yml @@ -62,14 +62,14 @@ jobs: - name: 'Composer: adjust dependencies' run: | # Set the PHPCS version to be used in the tests. - composer require --no-update squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}" --no-scripts + composer require --no-update squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}" --no-scripts --no-interaction # Remove the PHPCSDevCS dependency as it has different PHPCS requirements and would block installs. - composer remove --no-update --dev phpcsstandards/phpcsdevcs --no-scripts + composer remove --no-update --dev phpcsstandards/phpcsdevcs --no-scripts --no-interaction # Install dependencies and handle caching in one go. # @link https://github.com/marketplace/actions/install-composer-dependencies - name: Install Composer dependencies - uses: "ramsey/composer-install@v1" + uses: "ramsey/composer-install@v2" - name: Lint against parse errors if: ${{ matrix.lint }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8aaea78..7a76303 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -103,20 +103,20 @@ jobs: - name: 'Composer: adjust dependencies' run: | # Set the PHPCS version to be used in the tests. - composer require --no-update squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}" --no-scripts + composer require --no-update squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}" --no-scripts --no-interaction # Remove the PHPCSDevCS dependency as it has different PHPCS requirements and would block installs. - composer remove --no-update --dev phpcsstandards/phpcsdevcs --no-scripts + composer remove --no-update --dev phpcsstandards/phpcsdevcs --no-scripts --no-interaction # Install dependencies and handle caching in one go. # @link https://github.com/marketplace/actions/install-composer-dependencies - name: Install Composer dependencies - normal if: ${{ matrix.php < 8.2 }} - uses: "ramsey/composer-install@v1" + uses: "ramsey/composer-install@v2" # For PHP "nightly", we need to install with ignore platform reqs as not all dependencies allow installation. - name: Install Composer dependencies - with ignore platform if: ${{ matrix.php >= 8.2 }} - uses: "ramsey/composer-install@v1" + uses: "ramsey/composer-install@v2" with: composer-options: --ignore-platform-reqs From 9c90e5869613e423d41471d9adf8805303c3c8f2 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 17 Feb 2022 22:49:01 +0100 Subject: [PATCH 15/29] README: update for Composer 2.2 The `dealerdirect/phpcodesniffer-composer-installer` Composer plugin is a non-dev requirement for VIPCS. As of Composer 2.2.0, Composer plugins need to be explicitly allowed to run. This commit adds the CLI command to set those permissions to the installation instructions. Refs: * https://blog.packagist.com/composer-2-2/#more-secure-plugin-execution --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index b1029eb..c43a3a6 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ Installation Run the following from the root of your project: ```bash +composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true composer require --dev phpcsstandards/phpcsdevtools:^1.0 ``` @@ -43,6 +44,7 @@ composer require --dev phpcsstandards/phpcsdevtools:^1.0 If you work on several different sniff repos, you may want to install this toolset globally: ```bash +composer global config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true composer global require --dev phpcsstandards/phpcsdevtools:^1.0 ``` From ebfdea779e61ff35b60b29b95c51f66dc43638ca Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 17 Feb 2022 22:50:18 +0100 Subject: [PATCH 16/29] Update references to the Composer plugin The Composer plugin has a new home. Ref: https://github.com/PHPCSStandards/composer-installer/issues/146 --- CHANGELOG.md | 4 ++-- README.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0db40a..542ffc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,7 +26,7 @@ _Nothing yet._ ### Changed * The `master` branch has been renamed to `stable`. -* The version requirements for the [Dealerdirect Composer PHPCS plugin] have been widened to allow installation of releases from the `0.7.x` range, which brings compatibility with Composer 2.0. +* The version requirements for the [Composer PHPCS plugin] have been widened to allow installation of releases from the `0.7.x` range, which brings compatibility with Composer 2.0. * Miscellaneous updates to the development environment and CI scripts. @@ -41,4 +41,4 @@ Initial release containing: [1.1.0]: https://github.com/PHPCSStandards/PHPCSDevTools/compare/1.0.1...1.1.0 [1.0.1]: https://github.com/PHPCSStandards/PHPCSDevTools/compare/1.0.0...1.0.1 -[Dealerdirect Composer PHPCS plugin]: https://github.com/Dealerdirect/phpcodesniffer-composer-installer/ +[Composer PHPCS plugin]: https://github.com/PHPCSStandards/composer-installer diff --git a/README.md b/README.md index c43a3a6..0c7965b 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ composer global config allow-plugins.dealerdirect/phpcodesniffer-composer-instal composer global require --dev phpcsstandards/phpcsdevtools:^1.0 ``` -Composer will automatically install dependencies and register the PHPCSDebug standard with PHP_CodeSniffer using the [DealerDirect Composer PHPCS plugin](https://github.com/Dealerdirect/phpcodesniffer-composer-installer/). +Composer will automatically install dependencies and register the PHPCSDebug standard with PHP_CodeSniffer using the [Composer PHPCS plugin](https://github.com/PHPCSStandards/composer-installer). ### Stand-alone Installation From 8886b2a7520b9f51afcbeaad4af369fd8e93fd2f Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 5 Mar 2022 17:58:59 +0100 Subject: [PATCH 17/29] GH Actions: version update for various predefined actions A number of predefined actions have had major release, which warrant an update 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 --- .github/workflows/cs.yml | 2 +- .github/workflows/quicktest.yml | 2 +- .github/workflows/test.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cs.yml b/.github/workflows/cs.yml index 36fa8a7..c77fa8e 100644 --- a/.github/workflows/cs.yml +++ b/.github/workflows/cs.yml @@ -24,7 +24,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Install PHP uses: shivammathur/setup-php@v2 diff --git a/.github/workflows/quicktest.yml b/.github/workflows/quicktest.yml index 39acac9..0090f33 100644 --- a/.github/workflows/quicktest.yml +++ b/.github/workflows/quicktest.yml @@ -39,7 +39,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 # On stable PHPCS versions, allow for PHP deprecation notices. # Unit tests don't need to fail on those for stable releases where those issues won't get fixed anymore. diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7a76303..a3e99f8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -79,7 +79,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Setup ini config id: set_ini From a7e8fc016777f559c7ed6a23cf5ac372237880b3 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 19 Mar 2022 09:22:23 +0100 Subject: [PATCH 18/29] GH Actions/CS: fix build failure Fix failing installation of the xmllint tooling. --- .github/workflows/cs.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cs.yml b/.github/workflows/cs.yml index c77fa8e..52ad1f6 100644 --- a/.github/workflows/cs.yml +++ b/.github/workflows/cs.yml @@ -46,7 +46,9 @@ jobs: uses: "ramsey/composer-install@v2" - name: Install xmllint - run: sudo apt-get install --no-install-recommends -y libxml2-utils + run: | + sudo apt-get update + sudo apt-get install --no-install-recommends -y libxml2-utils # Show XML violations inline in the file diff. # @link https://github.com/marketplace/actions/xmllint-problem-matcher From dade96650fece52e4bba11b66bb5aa3ce42aa9a5 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 24 Apr 2022 02:59:17 +0200 Subject: [PATCH 19/29] Composer: update PHP Parallel Lint and Console Highlighter PHP Console Highlighter has released version `1.0.0` and PHP Parallel Lint version `1.3.2` is the first PHP Parallel Lint version which supports PHP Console Highlighter `1.0.0`. As the minimum supported PHP version is still PHP 5.3 for both, we can safely update both dependency requirements. Refs: * https://github.com/php-parallel-lint/PHP-Console-Highlighter/releases/tag/v1.0.0 * https://github.com/php-parallel-lint/PHP-Parallel-Lint/releases/tag/v1.3.2 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 2cca6e4..40d9f22 100644 --- a/composer.json +++ b/composer.json @@ -27,8 +27,8 @@ "require-dev" : { "roave/security-advisories" : "dev-master", "phpunit/phpunit" : "^4.5 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0", - "php-parallel-lint/php-parallel-lint": "^1.3.1", - "php-parallel-lint/php-console-highlighter": "^0.5", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "php-parallel-lint/php-console-highlighter": "^1.0.0", "phpcsstandards/phpcsdevcs": "^1.1.3", "phpcsstandards/phpcsutils" : "^1.0" }, From 28aac3192aaa29f5b4256f24c8dfdd3ca5629a54 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 24 Apr 2022 02:59:26 +0200 Subject: [PATCH 20/29] GH Actions: show deprecations when linting While rare, there are some deprecations which PHP can show when a file is being linted. By default these are ignored by PHP-Parallel-Lint. Apparently though, there is an option to show them (wasn't documented until recently), so let's turn that option on. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 40d9f22..0f0eff2 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,7 @@ "prefer-stable": true, "scripts" : { "lint": [ - "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --exclude vendor --exclude .git" + "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --show-deprecated --exclude vendor --exclude .git" ], "check-cs": [ "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs" From 021532a1813a7077d7db130447ea874b789bc08d Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 24 Apr 2022 03:08:05 +0200 Subject: [PATCH 21/29] README: update badges * Update links to workflows. * Update "tested up to" badge to include PHP 8.1. * Hide the badges for screenreaders. --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0c7965b..73ab527 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ PHPCSDevTools for developers of PHP_CodeSniffer sniffs ===================================================== + This is a set of tools to aid developers of sniffs for [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer). From 887e721b00730579508b75623550111639f3f979 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 27 Apr 2022 14:13:21 +0200 Subject: [PATCH 22/29] Debug/Tokenlist: minor readability improvement Pad the content length to three characters to prevent the display of the content jumping depending on the length. Includes updated unit tests. --- PHPCSDebug/Sniffs/Debug/TokenListSniff.php | 2 +- PHPCSDebug/Tests/Debug/TokenListUnitTest.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/PHPCSDebug/Sniffs/Debug/TokenListSniff.php b/PHPCSDebug/Sniffs/Debug/TokenListSniff.php index f19bfba..069612a 100644 --- a/PHPCSDebug/Sniffs/Debug/TokenListSniff.php +++ b/PHPCSDebug/Sniffs/Debug/TokenListSniff.php @@ -128,7 +128,7 @@ public function process(File $phpcsFile, $stackPtr) $sep, 'CC', \str_pad($token['level'], 2, ' ', \STR_PAD_LEFT), $sep, '(', \str_pad($parenthesesCount, 2, ' ', \STR_PAD_LEFT), ')', $sep, \str_pad($token['type'], 26), // Longest token type name is 26 chars. - $sep, '[', $token['length'], ']: ', $content, \PHP_EOL; + $sep, '[', \str_pad($token['length'], 3, ' ', \STR_PAD_LEFT), ']: ', $content, \PHP_EOL; } // Only do this once per file. diff --git a/PHPCSDebug/Tests/Debug/TokenListUnitTest.php b/PHPCSDebug/Tests/Debug/TokenListUnitTest.php index 1c00391..fe64ccf 100644 --- a/PHPCSDebug/Tests/Debug/TokenListUnitTest.php +++ b/PHPCSDebug/Tests/Debug/TokenListUnitTest.php @@ -39,10 +39,10 @@ public function testOutput() $expected = "\n"; $expected .= 'Ptr | Ln | Col | Cond | ( #) | Token Type | [len]: Content' . "\n"; $expected .= '-------------------------------------------------------------------------' . "\n"; - $expected .= ' 0 | L1 | C 1 | CC 0 | ( 0) | T_OPEN_TAG | [5]: expectOutputString($expected); $this->setOutputCallback([$this, 'normalizeLineEndings']); From ad4d5cf663bd1192b02952f80a9738e12f3c2a04 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 27 Apr 2022 14:30:46 +0200 Subject: [PATCH 23/29] GH Actions/CSQA: move the composer validate check up ... to be run before making adjustments to the `composer.json` file. --- .github/workflows/cs.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/cs.yml b/.github/workflows/cs.yml index 52ad1f6..6657929 100644 --- a/.github/workflows/cs.yml +++ b/.github/workflows/cs.yml @@ -33,6 +33,11 @@ jobs: coverage: none tools: cs2pr + # Validate the composer.json file. + # @link https://getcomposer.org/doc/03-cli.md#validate + - name: Validate Composer installation + run: composer validate --no-check-all --strict + - name: 'Composer: adjust dependencies' run: | # The sniff stage doesn't run the unit tests, so no need for PHPUnit. @@ -70,8 +75,3 @@ jobs: - name: Show PHPCS results in PR run: cs2pr ./phpcs-report.xml - - # Validate the composer.json file. - # @link https://getcomposer.org/doc/03-cli.md#validate - - name: Validate Composer installation - run: composer validate --no-check-all --strict From a4db61caee04d70c29f0260f8b09e40229537031 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 27 Apr 2022 14:31:54 +0200 Subject: [PATCH 24/29] Composer: rename some scripts ... to be in line with the names of similar scripts in other repos in this organisation. --- .github/workflows/cs.yml | 2 +- composer.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cs.yml b/.github/workflows/cs.yml index 6657929..9a876b2 100644 --- a/.github/workflows/cs.yml +++ b/.github/workflows/cs.yml @@ -71,7 +71,7 @@ jobs: # Check the code-style consistency of the PHP files. - name: Check PHP code style continue-on-error: true - run: composer check-cs -- --report-full --report-checkstyle=./phpcs-report.xml + run: composer checkcs -- --report-full --report-checkstyle=./phpcs-report.xml - name: Show PHPCS results in PR run: cs2pr ./phpcs-report.xml diff --git a/composer.json b/composer.json index 0f0eff2..1b2b2b6 100644 --- a/composer.json +++ b/composer.json @@ -46,10 +46,10 @@ "lint": [ "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --show-deprecated --exclude vendor --exclude .git" ], - "check-cs": [ + "checkcs": [ "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs" ], - "fix-cs": [ + "fixcs": [ "@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf" ], "run-tests": [ From 46fa914312886f2eac212fdb73fa4fad41bd4708 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 27 Apr 2022 22:10:21 +0200 Subject: [PATCH 25/29] README: more badge fixes --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 73ab527..c1e0062 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,8 @@ PHPCSDevTools for developers of PHP_CodeSniffer sniffs [![Last Commit to Unstable](https://img.shields.io/github/last-commit/PHPCSStandards/PHPCSDevTools/develop.svg)](https://github.com/PHPCSStandards/PHPCSDevTools/commits/develop) [![Minimum PHP Version](https://img.shields.io/packagist/php-v/phpcsstandards/phpcsdevtools.svg?maxAge=3600)](https://packagist.org/packages/phpcsstandards/phpcsdevtools) -[![Build Status CS](https://github.com/PHPCSStandards/PHPCSDevTools/actions/workflows/cs.yml/badge.svg?branch=develop)](https://github.com/PHPCSStandards/PHPCSDevTools/actions/workflows/cs.yml) -[![Build Status Test](https://github.com/PHPCSStandards/PHPCSDevTools/actions/workflows/test.yml/badge.svg?branch=develop)](https://github.com/PHPCSStandards/PHPCSDevTools/actions/workflows/test.yml) +[![Build Status CS](https://github.com/PHPCSStandards/PHPCSDevTools/actions/workflows/cs.yml/badge.svg)](https://github.com/PHPCSStandards/PHPCSDevTools/actions/workflows/cs.yml) +[![Build Status Test](https://github.com/PHPCSStandards/PHPCSDevTools/actions/workflows/test.yml/badge.svg)](https://github.com/PHPCSStandards/PHPCSDevTools/actions/workflows/test.yml) [![Tested on PHP 5.4 to nightly](https://img.shields.io/badge/tested%20on-PHP%205.4%20|%205.5%20|%205.6%20|%207.0%20|%207.1%20|%207.2%20|%207.3%20|%207.4%20|%208.0%20|%208.1%20|%20nightly-brightgreen.svg?maxAge=2419200)](https://github.com/PHPCSStandards/PHPCSDevTools/actions?query=workflow%3ATest) [![License: LGPLv3](https://poser.pugx.org/phpcsstandards/phpcsdevtools/license)](https://github.com/PHPCSStandards/PHPCSDevTools/blob/stable/LICENSE) From 913f6bc1a2ae99f985ca0b357a1a9ed758b0e02b Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 27 Apr 2022 23:34:03 +0200 Subject: [PATCH 26/29] README: add link to changelog in badges --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c1e0062..12f4b48 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ PHPCSDevTools for developers of PHP_CodeSniffer sniffs [![Latest Stable Version](https://poser.pugx.org/phpcsstandards/phpcsdevtools/v/stable)](https://packagist.org/packages/phpcsstandards/phpcsdevtools) [![Release Date of the Latest Version](https://img.shields.io/github/release-date/PHPCSStandards/PHPCSDevTools.svg?maxAge=1800)](https://github.com/PHPCSStandards/PHPCSDevTools/releases) +[![Changelog](https://img.shields.io/github/v/release/PHPCSStandards/PHPCSDevTools?label=Changelog&sort=semver)](https://github.com/PHPCSStandards/PHPCSDevTools/blob/stable/CHANGELOG.md) :construction: [![Latest Unstable Version](https://img.shields.io/badge/unstable-dev--develop-e68718.svg?maxAge=2419200)](https://packagist.org/packages/phpcsstandards/phpcsdevtools#dev-develop) [![Last Commit to Unstable](https://img.shields.io/github/last-commit/PHPCSStandards/PHPCSDevTools/develop.svg)](https://github.com/PHPCSStandards/PHPCSDevTools/commits/develop) From 9c1cba4a80a54a30daeb40773512776e04a1ce51 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 28 Apr 2022 17:09:22 +0200 Subject: [PATCH 27/29] README: minor language/grammer fixes --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 12f4b48..bc85bc0 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ PHPCSDevTools for developers of PHP_CodeSniffer sniffs -This is a set of tools to aid developers of sniffs for [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer). +This is a set of tools to assist developers of sniffs for [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer). * [Installation](#installation) + [Composer Project-based Installation](#composer-project-based-installation) @@ -65,7 +65,7 @@ Composer will automatically install dependencies and register the PHPCSDebug sta ```bash phpcs --config-set installed_paths /path/to/PHPCSDevTools ``` - :warning: **Warning**: The `installed_paths` command overwrites any previously set `installed_paths`. If you have previously set `installed_paths` for other external standards, run `phpcs --config-show` first and then run the `installed_paths` command with all the paths you need separated by comma's, i.e.: + :warning: **Warning**: The `installed_paths` command overwrites any previously set `installed_paths`. If you have previously set `installed_paths` for other external standards, run `phpcs --config-show` first and then run the `installed_paths` command with all the paths you need separated by commas, i.e.: ```bash phpcs --config-set installed_paths /path/1,/path/2,/path/3 ``` From c2b5efb8a60efbb4462ab2ccae0fb9035020983b Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 28 Apr 2022 21:35:18 +0200 Subject: [PATCH 28/29] GH Actions: auto-deploy website on push to `stable` This commit: * Adds a new `update-website.yml` workflow which will automatically update the website whenever a commit is pushed to the `stable` branch. The script will also execute whenever changes are made to the workflow or the build scripts, but in that case, it will only do a _dry run_. * This workflow will call the new `.github/build/update-website.php` script to prepare files to be updated on the website. * ... which will in turn call the `.github/build/Website.php` class which does the actually preparing. Initially, the build script will: * Create a `deploy` directory to store files to be moved to the website. * Copy the `README.md` file to `index.md`. * Edit this file to: - Add frontmatter to indicate to Jekyll the file should be processed. - Remove the title and description as those would be duplicate. - Remove most of the badges. - For the remaining badges, turn them into HTML as Jekyll doesn't handle them correctly. The build script has been set up using modern PHP and expects PHP 7.2 or higher to run (using PHP 8.1 in the workflow). Includes: * Adding a new `lintlt72` script to the `composer.json` file which will exclude the website build scripts from linting. * Implementing use of the `lintlt72` script in the appropriate places in the `quicktest` and `test` workflows. * Minor tweak to the `README` to ensure a URL will be hyperlinked. Ref: * [Action runner which handles moving the prepared files to the gh-pages branch](https://github.com/crazy-max/ghaction-github-pages) --- .github/build/Website.php | 285 +++++++++++++++++++++++++++ .github/build/update-website.php | 27 +++ .github/workflows/quicktest.yml | 11 +- .github/workflows/test.yml | 8 +- .github/workflows/update-website.yml | 100 ++++++++++ .gitignore | 1 + README.md | 2 +- composer.json | 3 + 8 files changed, 429 insertions(+), 8 deletions(-) create mode 100644 .github/build/Website.php create mode 100644 .github/build/update-website.php create mode 100644 .github/workflows/update-website.yml diff --git a/.github/build/Website.php b/.github/build/Website.php new file mode 100644 index 0000000..9ebb41d --- /dev/null +++ b/.github/build/Website.php @@ -0,0 +1,285 @@ + string target> + */ + const FILES_TO_COPY = [ + 'README.md' => 'index.md', + ]; + + /** + * Frontmatter. + * + * @var string + */ + const FRONTMATTER = '--- +--- +'; + + /** + * Resolved path to project root (with trailing slash). + * + * @var string + */ + private $realRoot; + + /** + * Resolved path to target directory (with trailing slash). + * + * @var string + */ + private $realTarget; + + /** + * Constructor + * + * @return void + */ + public function __construct() + { + // Check if the target directory exists and if not, create it. + $targetDir = self::PROJECT_ROOT . self::TARGET_DIR; + + if (@\is_dir($targetDir) === false) { + if (@\mkdir($targetDir, 0777, true) === false) { + throw new RuntimeException(\sprintf('Failed to create the %s directory.', $targetDir)); + } + } + + $realPath = \realpath($targetDir); + if ($realPath === false) { + throw new RuntimeException(\sprintf('Failed to find the %s directory.', $targetDir)); + } + + $this->realRoot = \realpath(self::PROJECT_ROOT) . '/'; + $this->realTarget = $realPath . '/'; + } + + /** + * Run the transformation. + * + * @return int Exit code. + */ + public function run(): int + { + $exitcode = 0; + + try { + $this->copyFiles(); + $this->transformIndex(); + } catch (RuntimeException $e) { + echo 'ERROR: ', $e->getMessage(), \PHP_EOL; + $exitcode = 1; + } + + return $exitcode; + } + + /** + * Copy files to the target directory. + * + * @return void + */ + private function copyFiles(): void + { + foreach (self::FILES_TO_COPY as $source => $target) { + $source = $this->realRoot . $source; + if (empty($target)) { + $target = $this->realTarget . $source; + } else { + $target = $this->realTarget . $target; + } + + // Bit round-about way of copying the files, but we need to make sure the target dir exists. + $contents = $this->getContents($source); + $this->putContents($target, $contents); + } + } + + /** + * Transform the README to a usable homepage. + * + * - Remove the title and subtitle as those would become duplicate. + * - Remove most of the badges, except for the first three. + * - Transform those badges into HTML. + * - Add frontmatter. + * + * @return void + * + * @throws \RuntimeException When any of the regexes do not yield any results. + */ + private function transformIndex(): void + { + // Read the file. + $target = $this->realTarget . '/index.md'; + $contents = $this->getContents($target); + + // Grab the start of the document. + $matched = \preg_match('`^(.+)\* \[Installation\]`s', $contents, $matches); + if ($matched !== 1) { + throw new RuntimeException('Failed to match start of document. Adjust the regex'); + } + + $startOfDoc = $matches[1]; + + // Grab the first few badges from the start of the document. + $matched = \preg_match( + '`((?:\[!\[[^\]]+\]\([^\)]+\)\]\([^\)]+\)[\n\r]+)+):construction:`', + $startOfDoc, + $matches + ); + if ($matched !== 1) { + throw new RuntimeException('Failed to match badges. Adjust the regex'); + } + + $badges = \explode("\n", $matches[1]); + $badges = \array_filter($badges); + $badges = \array_map([$this, 'mdBadgeToHtml'], $badges); + $badges = \implode("\n ", $badges); + + $replacement = \sprintf( + '%s + + + +', + self::FRONTMATTER, + ' ' . $badges + ); + + $contents = \str_replace($startOfDoc, $replacement, $contents); + + $this->putContents($target, $contents); + } + + /** + * Transform markdown badges into HTML badges. + * + * Jekyll runs into trouble doing this when we also want to keep the wrapper div with aria-hidden="true". + * + * @param string $mdBadge Markdown badge code. + * + * @return string + */ + private function mdBadgeToHtml(string $mdBadge): string + { + $mdBadge = trim($mdBadge); + + $matched = \preg_match( + '`^\[!\[(?[^\]]+)\]\((?[^\)]+)\)\]\((?[^\)]+)\)$`', + $mdBadge, + $matches + ); + if ($matched !== 1) { + throw new RuntimeException(\sprintf('Failed to parse the badge. Adjust the regex. Received: %s', $mdBadge)); + } + + return \sprintf( + '%s', + $matches['href'], + $matches['imgurl'], + $matches['alt'] + ); + } + + /** + * Retrieve the contents of a file. + * + * @param string $source Path to the source file. + * + * @return string + * + * @throws \RuntimeException When the contents of the file could not be retrieved. + */ + private function getContents(string $source): string + { + $contents = \file_get_contents($source); + if (!$contents) { + throw new RuntimeException(\sprintf('Failed to read doc file: %s', $source)); + } + + return $contents; + } + + /** + * Write a string to a file. + * + * @param string $target Path to the target file. + * @param string $contents File contents to write. + * + * @return void + * + * @throws \RuntimeException When the target directory could not be created. + * @throws \RuntimeException When the file could not be written to the target directory. + */ + private function putContents(string $target, string $contents): void + { + // Check if the target directory exists and if not, create it. + $targetDir = \dirname($target); + + if (@\is_dir($targetDir) === false) { + if (@\mkdir($targetDir, 0777, true) === false) { + throw new RuntimeException(\sprintf('Failed to create the %s directory.', $targetDir)); + } + } + + // Make sure the file always ends on a new line. + $contents = \rtrim($contents) . "\n"; + if (\file_put_contents($target, $contents) === false) { + throw new RuntimeException(\sprintf('Failed to write to target location: %s', $target)); + } + } +} diff --git a/.github/build/update-website.php b/.github/build/update-website.php new file mode 100644 index 0000000..4dc353a --- /dev/null +++ b/.github/build/update-website.php @@ -0,0 +1,27 @@ +#!/usr/bin/env php +run(); + +exit($websiteUpdateSuccess); diff --git a/.github/workflows/quicktest.yml b/.github/workflows/quicktest.yml index 0090f33..a563388 100644 --- a/.github/workflows/quicktest.yml +++ b/.github/workflows/quicktest.yml @@ -25,15 +25,12 @@ jobs: matrix: php: ['5.4', 'latest'] phpcs_version: ['dev-master'] - lint: [true] include: - php: '7.2' phpcs_version: '3.1.0' - lint: false - php: '5.4' phpcs_version: '3.1.0' - lint: false name: "QTest${{ matrix.lint && ' + Lint' || '' }}: PHP ${{ matrix.php }} - PHPCS ${{ matrix.phpcs_version }}" @@ -71,10 +68,14 @@ jobs: - name: Install Composer dependencies uses: "ramsey/composer-install@v2" - - name: Lint against parse errors - if: ${{ matrix.lint }} + - name: Lint against parse errors (PHP 7.2+) + if: ${{ matrix.phpcs_version == 'dev-master' && matrix.php >= '7.2' }} run: composer lint + - name: Lint against parse errors (PHP < 7.2) + if: ${{ matrix.phpcs_version == 'dev-master' && matrix.php < '7.2' }} + run: composer lintlt72 + # Check that any sniffs available are feature complete. # This also acts as an integration test for the feature completeness script, # which is why it is run against various PHP versions and not in the "Sniff" stage. diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a3e99f8..0c00111 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -120,10 +120,14 @@ jobs: with: composer-options: --ignore-platform-reqs - - name: Lint against parse errors - if: matrix.phpcs_version == 'dev-master' + - name: Lint against parse errors (PHP 7.2+) + if: ${{ matrix.phpcs_version == 'dev-master' && matrix.php >= '7.2' }} run: composer lint -- --checkstyle | cs2pr + - name: Lint against parse errors (PHP < 7.2) + if: ${{ matrix.phpcs_version == 'dev-master' && matrix.php < '7.2' }} + run: composer lintlt72 -- --checkstyle | cs2pr + # Check that any sniffs available are feature complete. # This also acts as an integration test for the feature completeness script, # which is why it is run against various PHP versions and not in the "Sniff" stage. diff --git a/.github/workflows/update-website.yml b/.github/workflows/update-website.yml new file mode 100644 index 0000000..91c0e88 --- /dev/null +++ b/.github/workflows/update-website.yml @@ -0,0 +1,100 @@ +name: Build website + +on: + # Trigger the workflow whenever a new tag is created. + push: + branches: + - 'stable' + # And whenever this workflow or one of the associated scripts is updated (for a dry-run). + pull_request: + branches-ignore: + - 'stable' + paths: + - '.github/workflows/update-website.yml' + - '.github/build/**' + # Also allow manually triggering the workflow. + workflow_dispatch: + +# Cancels all previous workflow runs for the same branch that have not yet completed. +concurrency: + # The concurrency group contains the workflow name and the branch name. + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + prepare: + name: "Update website files" + # Don't run on forks. + if: github.repository == 'PHPCSStandards/PHPCSDevTools' + + runs-on: ubuntu-latest + steps: + # By default use the `stable` branch as the published docs should always + # reflect the latest release. + # For testing changes to the workflow or the scripts, use the PR branch + # to have access to the latest version of the workflow/scripts. + - name: Determine branch to use + id: base_branch + env: + REF: ${{ github.ref }} + run: | + if [ "${{ github.event_name }}" == "pull_request" ]; then + echo "::set-output name=BRANCH::$REF" + else + echo '::set-output name=BRANCH::stable' + fi + + - name: Checkout code + uses: actions/checkout@v3 + with: + ref: ${{ steps.base_branch.outputs.BRANCH }} + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.1' + ini-values: error_reporting=-1, display_errors=On, log_errors_max_len=0 + coverage: none + + - name: Prepare the files which will be deployed to the GH Pages website + run: php .github/build/update-website.php + + - name: "Set variable: short sha" + id: set_sha + env: + SHA: ${{ github.sha }} + run: | + shortsha=$(echo "$SHA" | cut -b 1-6) + echo "::set-output name=SHORTSHA::$shortsha" + + - name: Prepare commit message + id: commit_msg + env: + REF_NAME: ${{ github.ref_name }} + COMMIT_MSG: ${{ github.event.head_commit.message }} + run: | + if [[ "${{ github.event_name }}" == 'push' && "${{ github.ref_type }}" == 'tag' ]]; then + echo "::set-output name=MSG::Update website for release of version $REF_NAME" + else + echo "::set-output name=MSG::Sync website after commit (sha: ${{ steps.set_sha.outputs.SHORTSHA }})" + fi + + - name: Check GitHub Pages status + uses: crazy-max/ghaction-github-status@v2 + with: + pages_threshold: major_outage + + - name: Deploy the website + if: success() + uses: crazy-max/ghaction-github-pages@v2 + with: + build_dir: 'deploy' + target_branch: 'gh-pages' + keep_history: true + #allow_empty_commit: false # Turn on after verification that it all works as expected. + jekyll: true + commit_message: ${{ steps.commit_msg.outputs.MSG }} + dry_run: ${{ steps.base_branch.outputs.BRANCH != 'stable' }} + verbose: ${{ matrix.verbose }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 63850bb..8561573 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +deploy/ vendor/ composer.lock .phpcs.xml diff --git a/README.md b/README.md index bc85bc0..6802da1 100644 --- a/README.md +++ b/README.md @@ -184,4 +184,4 @@ If unsure whether the changes you are proposing would be welcome, open an issue License ------- -This code is released under the GNU Lesser General Public License (LGPLv3). For more information, visit http://www.gnu.org/copyleft/lesser.html +This code is released under the [GNU Lesser General Public License (LGPLv3)](http://www.gnu.org/copyleft/lesser.html). diff --git a/composer.json b/composer.json index 1b2b2b6..f0549bc 100644 --- a/composer.json +++ b/composer.json @@ -46,6 +46,9 @@ "lint": [ "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --show-deprecated --exclude vendor --exclude .git" ], + "lintlt72": [ + "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --show-deprecated --exclude vendor --exclude .git --exclude .github/build" + ], "checkcs": [ "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs" ], From b61f5e5d87a5dab3b08a8ff89fff1cd7052843f5 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 27 Apr 2022 16:34:11 +0200 Subject: [PATCH 29/29] Readme/Changelog: update for release of v 1.1.1 Includes * Mention of all relevant changes. * Adding a link for the version diff. * Updating the `VERSION` document with the version nr for the release. * Updating the PHPCSDebug output sample in the README --- CHANGELOG.md | 12 ++++++++++++ README.md | 52 ++++++++++++++++++++++++++-------------------------- VERSION | 2 +- 3 files changed, 39 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 542ffc0..6629530 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,17 @@ This projects adheres to [Keep a CHANGELOG](http://keepachangelog.com/) and uses _Nothing yet._ +## [1.1.1] - 2022-04-27 + +### Changed +* `PHPCSDebug.Debug.TokenList`: readability improvement (alignment of content length). +* All functionality is now also tested against PHP 8.1. +* Update to the installation instructions to allow for Composer 2.2+. +* Minor other documentation improvements. +* The documentation of the project will now also be available at . +* Miscellaneous updates to the development environment and CI scripts. + + ## [1.1.0] - 2020-12-20 ### Added @@ -38,6 +49,7 @@ Initial release containing: [Unreleased]: https://github.com/PHPCSStandards/PHPCSDevTools/compare/stable...HEAD +[1.1.1]: https://github.com/PHPCSStandards/PHPCSDevTools/compare/1.1.0...1.1.1 [1.1.0]: https://github.com/PHPCSStandards/PHPCSDevTools/compare/1.0.1...1.1.0 [1.0.1]: https://github.com/PHPCSStandards/PHPCSDevTools/compare/1.0.0...1.0.1 diff --git a/README.md b/README.md index 6802da1..f0f6886 100644 --- a/README.md +++ b/README.md @@ -145,32 +145,32 @@ The output will look something along the lines of: ``` Ptr | Ln | Col | Cond | ( #) | Token Type | [len]: Content ------------------------------------------------------------------------- - 0 | L1 | C 1 | CC 0 | ( 0) | T_OPEN_TAG | [5]: