From ec3cc04b2b9ce11683d012bd1a3ec0cd6b1b6a68 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 25 Mar 2025 11:28:13 +0100 Subject: [PATCH 1/3] GH Actions: use the xmllint-validate action runner Instead of doing all the installation steps for xmllint validation in the workflow, use the :sparkles: new dedicated `phpcsstandards/xmllint-validate` action runner instead. Notes: * This does mean that the `bin/xml-lint` script is now no longer used in CI. I've left the script in place as there may be contributors who want to run these checks locally and the script can help them with that, though happy to remove the script if nobody uses it. Ref: https://github.com/marketplace/actions/xmllint-validate --- .github/workflows/basics.yml | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/.github/workflows/basics.yml b/.github/workflows/basics.yml index 8a6c8fa1..9ae66670 100644 --- a/.github/workflows/basics.yml +++ b/.github/workflows/basics.yml @@ -22,6 +22,9 @@ jobs: name: 'Basic CS and QA checks' runs-on: ubuntu-latest + env: + XMLLINT_INDENT: ' ' # This is a tab character. + steps: - name: Checkout code uses: actions/checkout@v4 @@ -33,21 +36,6 @@ jobs: coverage: none tools: cs2pr - # Updating the lists can fail intermittently, typically after Microsoft has released a new package. - # This should not be blocking for this job, so ignore any errors from this step. - # Ref: https://github.com/dotnet/core/issues/4167 - - name: Update the available packages list - continue-on-error: true - run: sudo apt-get update - - - name: Install xmllint - run: 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 - - name: Enable showing XML issues inline - uses: korelstar/xmllint-problem-matcher@v1 - # Validate the composer.json file. # @link https://getcomposer.org/doc/03-cli.md#validate - name: Validate Composer installation @@ -65,8 +53,19 @@ jobs: # Bust the cache at least once a month - output format: YYYY-MM. custom-cache-suffix: $(date -u "+%Y-%m") - - name: 'Validate XML against schema and check code style' - run: ./bin/xml-lint + # Validate the XML file. + - name: Validate rulesets against schema + uses: phpcsstandards/xmllint-validate@v1 + with: + pattern: "./*/ruleset.xml" + xsd-file: "vendor/squizlabs/php_codesniffer/phpcs.xsd" + + # Check the code-style consistency of the XML file. + # Note: this needs xmllint, but that will be installed via the phpcsstandards/xmllint-validate action runner in the previous step. + - name: Check XML code style + run: | + diff -B --tabsize=4 ./WordPressVIPMinimum/ruleset.xml <(xmllint --format "./WordPressVIPMinimum/ruleset.xml") + diff -B --tabsize=4 ./WordPress-VIP-Go/ruleset.xml <(xmllint --format "./WordPress-VIP-Go/ruleset.xml") # Check the code-style consistency of the PHP files. - name: Check PHP code style From 771cb525cbb5491f7230bd85d8f9cec4ff454566 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 25 Mar 2025 11:28:50 +0100 Subject: [PATCH 2/3] GH Actions: add some additional XML validation checks ... for dev tool files. --- .github/workflows/basics.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/.github/workflows/basics.yml b/.github/workflows/basics.yml index 9ae66670..b3143c46 100644 --- a/.github/workflows/basics.yml +++ b/.github/workflows/basics.yml @@ -67,6 +67,30 @@ jobs: diff -B --tabsize=4 ./WordPressVIPMinimum/ruleset.xml <(xmllint --format "./WordPressVIPMinimum/ruleset.xml") diff -B --tabsize=4 ./WordPress-VIP-Go/ruleset.xml <(xmllint --format "./WordPress-VIP-Go/ruleset.xml") + # Validate dev tool related XML files. + - name: Validate Project PHPCS ruleset against schema + uses: phpcsstandards/xmllint-validate@v1 + with: + pattern: ".phpcs.xml.dist" + xsd-file: "vendor/squizlabs/php_codesniffer/phpcs.xsd" + + # Notes: + # - PHPUnit 9.5 (which will be installed in this job) doesn't ship XSD files further back than 8.5. + # - PHPUnit 9.3 introduced some new configuration options and deprecated the old versions of those. + # For cross-version compatibility with older PHPUnit versions, those new config options cannot be used yet, + # which is why the PHPUnit 9 validation is done against the PHPUnit 9.2 schema. + - name: "Validate PHPUnit config for use with PHPUnit 8" + uses: phpcsstandards/xmllint-validate@v1 + with: + pattern: "phpunit.xml.dist" + xsd-file: "vendor/phpunit/phpunit/schema/8.5.xsd" + + - name: "Validate PHPUnit config for use with PHPUnit 9" + uses: phpcsstandards/xmllint-validate@v1 + with: + pattern: "phpunit.xml.dist" + xsd-file: "vendor/phpunit/phpunit/schema/9.2.xsd" + # Check the code-style consistency of the PHP files. - name: Check PHP code style id: phpcs From 5e625129cb711203f0e1aa84e701593f64d2b093 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 25 Mar 2025 11:36:50 +0100 Subject: [PATCH 3/3] Remove the `bin/xml-lint` script ... now it is no longer used in CI. --- .github/CONTRIBUTING.md | 2 +- bin/xml-lint | 17 ----------------- composer.json | 5 ++--- 3 files changed, 3 insertions(+), 21 deletions(-) delete mode 100755 bin/xml-lint diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 8a17c256..5da9ed79 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -61,7 +61,7 @@ This package contains Composer scripts to quickly run the developer checks which After `composer install`, you can do: -- `composer lint`: Lint PHP and XML files in against parse errors. +- `composer lint`: Lint PHP files against parse errors. - `composer cs`: Check the code style and code quality of the codebase via PHPCS. - `composer test`: Run the unit tests for the VIPCS sniffs. - `composer test-coverage`: Run the unit tests for the VIPCS sniffs with coverage enabled. diff --git a/bin/xml-lint b/bin/xml-lint deleted file mode 100755 index 6ab4e113..00000000 --- a/bin/xml-lint +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash -# -# Check XML files. -# -# @link http://xmlsoft.org/xmllint.html -# -# EXAMPLE TO RUN LOCALLY: -# -# ./bin/xml-lint - -# Validate the ruleset XML files. -xmllint --noout --schema ./vendor/squizlabs/php_codesniffer/phpcs.xsd ./*/ruleset.xml - -# Check the code-style consistency of the XML files. -export XMLLINT_INDENT=" " # This is a tab character. -diff -B --tabsize=4 ./WordPressVIPMinimum/ruleset.xml <(xmllint --format "./WordPressVIPMinimum/ruleset.xml") -diff -B --tabsize=4 ./WordPress-VIP-Go/ruleset.xml <(xmllint --format "./WordPress-VIP-Go/ruleset.xml") diff --git a/composer.json b/composer.json index e02138dc..4908900a 100644 --- a/composer.json +++ b/composer.json @@ -39,8 +39,7 @@ "scripts": { "test-ruleset": "bin/ruleset-tests", "lint": [ - "bin/php-lint", - "bin/xml-lint" + "bin/php-lint" ], "cs": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs", "test": "bin/unit-tests", @@ -57,7 +56,7 @@ ] }, "scripts-descriptions": { - "lint": "VIPCS: Lint PHP and XML files in against parse errors.", + "lint": "VIPCS: Lint PHP files against parse errors.", "cs": "VIPCS: Check the code style and code quality of the codebase via PHPCS.", "test": "VIPCS: Run the unit tests for the VIPCS sniffs.", "test-coverage": "VIPCS: Run the unit tests for the VIPCS sniffs with coverage enabled.",