From 36b9d57ce9cda5ee029b5f81dc35becd7a6e35d3 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 30 Jan 2024 11:42:59 -0800 Subject: [PATCH 01/13] Run build-cs composer install/update via post-install/update-cmd scripts --- composer.json | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/composer.json b/composer.json index f2071e17e7..06b946fb5f 100644 --- a/composer.json +++ b/composer.json @@ -20,18 +20,11 @@ "php": ">=7|^8" }, "scripts": { - "phpstan": [ - "composer --working-dir=build-cs update --no-interaction", - "build-cs/vendor/bin/phpstan analyse --memory-limit=2048M -c phpstan.neon.dist" - ], - "format": [ - "composer --working-dir=build-cs update --no-interaction", - "build-cs/vendor/bin/phpcbf --standard=phpcs.xml.dist --report-summary --report-source" - ], - "lint": [ - "composer --working-dir=build-cs update --no-interaction", - "build-cs/vendor/bin/phpcs --standard=phpcs.xml.dist" - ], + "post-install-cmd": "composer --working-dir=build-cs install --no-interaction", + "post-update-cmd": "composer --working-dir=build-cs update --no-interaction", + "phpstan": "build-cs/vendor/bin/phpstan analyse --memory-limit=2048M -c phpstan.neon.dist", + "format": "build-cs/vendor/bin/phpcbf --standard=phpcs.xml.dist --report-summary --report-source", + "lint": "build-cs/vendor/bin/phpcs --standard=phpcs.xml.dist", "test": "phpunit -c phpunit.xml.dist --verbose", "test-multisite": "phpunit -c tests/multisite.xml --verbose" }, From 3df9c5d9390240bb84b841438d8852e3a4c0159c Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Tue, 30 Jan 2024 12:00:27 -0800 Subject: [PATCH 02/13] Only run composer install/update for build-cs in PHP 8+ --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 06b946fb5f..9ddef17303 100644 --- a/composer.json +++ b/composer.json @@ -20,8 +20,8 @@ "php": ">=7|^8" }, "scripts": { - "post-install-cmd": "composer --working-dir=build-cs install --no-interaction", - "post-update-cmd": "composer --working-dir=build-cs update --no-interaction", + "post-install-cmd": "if [ $(php -r 'echo PHP_MAJOR_VERSION;') -ge 8 ]; then composer --working-dir=build-cs install --no-interaction; else echo 'Skipping composer install for build-cs since not on PHP 8.'; fi", + "post-update-cmd": "if [ $(php -r 'echo PHP_MAJOR_VERSION;') -ge 8 ]; then composer --working-dir=build-cs update --no-interaction; else echo 'Skipping composer update for build-cs since not on PHP 8.'; fi", "phpstan": "build-cs/vendor/bin/phpstan analyse --memory-limit=2048M -c phpstan.neon.dist", "format": "build-cs/vendor/bin/phpcbf --standard=phpcs.xml.dist --report-summary --report-source", "lint": "build-cs/vendor/bin/phpcs --standard=phpcs.xml.dist", From 2591052858b37a1d67d8f87a915141f6bd47cb79 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 31 Jan 2024 08:55:45 -0800 Subject: [PATCH 03/13] Remove redundant composer install/update --- package.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/package.json b/package.json index 8599872cd7..bc3287b7e9 100644 --- a/package.json +++ b/package.json @@ -31,11 +31,8 @@ "lint-js": "wp-scripts lint-js", "format-php": "composer format", "phpstan": "composer phpstan", - "prelint-php": "wp-env run composer 'install --no-interaction'", "lint-php": "composer lint", - "pretest-php": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/$(basename $(pwd)) composer update --no-interaction", "test-php": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/$(basename $(pwd)) composer test", - "pretest-php-multisite": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/$(basename $(pwd)) composer update --no-interaction", "test-php-multisite": "wp-env run tests-cli --env-cwd=/var/www/html/wp-content/plugins/$(basename $(pwd)) composer test-multisite", "wp-env": "wp-env", "prepare": "husky install" From cfd32761c221a3f921232f94691dc3cd4fce823f Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 31 Jan 2024 11:42:10 -0800 Subject: [PATCH 04/13] Align workflows for testing and use composer install in php-test --- .github/workflows/php-test-standalone-plugins.yml | 4 ++-- .github/workflows/php-test.yml | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/php-test-standalone-plugins.yml b/.github/workflows/php-test-standalone-plugins.yml index 410ae38028..ce8dd2eb28 100644 --- a/.github/workflows/php-test-standalone-plugins.yml +++ b/.github/workflows/php-test-standalone-plugins.yml @@ -66,14 +66,14 @@ jobs: with: node-version-file: '.nvmrc' cache: npm - - name: npm install - run: npm ci - name: General debug information run: | npm --version node --version composer --version php -v + - name: npm install + run: npm ci - name: Building standalone plugins run: npm run build-plugins - name: Running single site standalone plugin integration tests diff --git a/.github/workflows/php-test.yml b/.github/workflows/php-test.yml index 7b761dd0ab..d0d37a6f86 100644 --- a/.github/workflows/php-test.yml +++ b/.github/workflows/php-test.yml @@ -58,13 +58,22 @@ jobs: steps: - uses: styfle/cancel-workflow-action@0.11.0 - uses: actions/checkout@v3 + - uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} - name: Setup Node.js (.nvmrc) uses: actions/setup-node@v3 with: node-version-file: '.nvmrc' cache: npm - - name: Composer update - run: composer update + - name: General debug information + run: | + npm --version + node --version + composer --version + php -v + - name: Composer install + run: composer install - name: npm install run: npm ci - name: Install WordPress From e7c31a7078e3e30d679ff271c45d0c7639c3e457 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 31 Jan 2024 12:33:08 -0800 Subject: [PATCH 05/13] Revert "Align workflows for testing and use composer install in php-test" This reverts commit cfd32761c221a3f921232f94691dc3cd4fce823f. --- .github/workflows/php-test-standalone-plugins.yml | 4 ++-- .github/workflows/php-test.yml | 13 ++----------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/.github/workflows/php-test-standalone-plugins.yml b/.github/workflows/php-test-standalone-plugins.yml index ce8dd2eb28..410ae38028 100644 --- a/.github/workflows/php-test-standalone-plugins.yml +++ b/.github/workflows/php-test-standalone-plugins.yml @@ -66,14 +66,14 @@ jobs: with: node-version-file: '.nvmrc' cache: npm + - name: npm install + run: npm ci - name: General debug information run: | npm --version node --version composer --version php -v - - name: npm install - run: npm ci - name: Building standalone plugins run: npm run build-plugins - name: Running single site standalone plugin integration tests diff --git a/.github/workflows/php-test.yml b/.github/workflows/php-test.yml index d0d37a6f86..7b761dd0ab 100644 --- a/.github/workflows/php-test.yml +++ b/.github/workflows/php-test.yml @@ -58,22 +58,13 @@ jobs: steps: - uses: styfle/cancel-workflow-action@0.11.0 - uses: actions/checkout@v3 - - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - name: Setup Node.js (.nvmrc) uses: actions/setup-node@v3 with: node-version-file: '.nvmrc' cache: npm - - name: General debug information - run: | - npm --version - node --version - composer --version - php -v - - name: Composer install - run: composer install + - name: Composer update + run: composer update - name: npm install run: npm ci - name: Install WordPress From 1783ec2e80fa47866ed1d57007d0dd6890f52380 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 31 Jan 2024 12:35:00 -0800 Subject: [PATCH 06/13] Run composer install in container for php-test workflow --- .github/workflows/php-test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/php-test.yml b/.github/workflows/php-test.yml index 7b761dd0ab..762175c960 100644 --- a/.github/workflows/php-test.yml +++ b/.github/workflows/php-test.yml @@ -63,12 +63,12 @@ jobs: with: node-version-file: '.nvmrc' cache: npm - - name: Composer update - run: composer update - name: npm install run: npm ci - name: Install WordPress run: npm run wp-env start + - name: Composer install + run: npm run wp-env run tests-cli --env-cwd='wp-content/plugins/$(basename $(pwd))' composer install --no-interaction - name: Running single site unit tests run: npm run test-php - name: Running multisite unit tests From 9e926ddc45d7a0833ed67d3f1c9d4d926c763be7 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 31 Jan 2024 13:34:26 -0800 Subject: [PATCH 07/13] Fix passing --env-cwd arg by preceding with -- Co-authored-by: Joe McGill --- .github/workflows/php-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/php-test.yml b/.github/workflows/php-test.yml index 762175c960..f6254585ea 100644 --- a/.github/workflows/php-test.yml +++ b/.github/workflows/php-test.yml @@ -68,7 +68,7 @@ jobs: - name: Install WordPress run: npm run wp-env start - name: Composer install - run: npm run wp-env run tests-cli --env-cwd='wp-content/plugins/$(basename $(pwd))' composer install --no-interaction + run: npm run wp-env run tests-cli -- --env-cwd='wp-content/plugins/$(basename $(pwd))' composer install --no-interaction - name: Running single site unit tests run: npm run test-php - name: Running multisite unit tests From a67bfcd613523e1bc61441d7b6542638fafa0c96 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 31 Jan 2024 14:53:53 -0800 Subject: [PATCH 08/13] Use double quotes for string interpolation --- .github/workflows/php-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/php-test.yml b/.github/workflows/php-test.yml index f6254585ea..4321a707a2 100644 --- a/.github/workflows/php-test.yml +++ b/.github/workflows/php-test.yml @@ -68,7 +68,7 @@ jobs: - name: Install WordPress run: npm run wp-env start - name: Composer install - run: npm run wp-env run tests-cli -- --env-cwd='wp-content/plugins/$(basename $(pwd))' composer install --no-interaction + run: npm run wp-env run tests-cli -- --env-cwd="wp-content/plugins/$(basename $(pwd))" composer install --no-interaction - name: Running single site unit tests run: npm run test-php - name: Running multisite unit tests From 776ea67d037a3000ce8aec9ab872eac02394e920 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 31 Jan 2024 14:57:32 -0800 Subject: [PATCH 09/13] Run composer update instead of composer install --- .github/workflows/php-test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/php-test.yml b/.github/workflows/php-test.yml index 4321a707a2..148c2e07a3 100644 --- a/.github/workflows/php-test.yml +++ b/.github/workflows/php-test.yml @@ -67,8 +67,8 @@ jobs: run: npm ci - name: Install WordPress run: npm run wp-env start - - name: Composer install - run: npm run wp-env run tests-cli -- --env-cwd="wp-content/plugins/$(basename $(pwd))" composer install --no-interaction + - name: Composer update + run: npm run wp-env run tests-cli -- --env-cwd="wp-content/plugins/$(basename $(pwd))" composer update --no-interaction - name: Running single site unit tests run: npm run test-php - name: Running multisite unit tests From 36fe543ee05b371f0bc97b698ef9b56f0960a756 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 31 Jan 2024 15:04:25 -0800 Subject: [PATCH 10/13] Add note explaining why composer update is used --- .github/workflows/php-test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/php-test.yml b/.github/workflows/php-test.yml index 148c2e07a3..5fe4fc6c90 100644 --- a/.github/workflows/php-test.yml +++ b/.github/workflows/php-test.yml @@ -67,6 +67,9 @@ jobs: run: npm ci - name: Install WordPress run: npm run wp-env start + # Note that `composer update` is required instead of `composer install` + # for the sake of PHP versions older than 8.1, which is the version of + # PHP that the composer.lock was created for. - name: Composer update run: npm run wp-env run tests-cli -- --env-cwd="wp-content/plugins/$(basename $(pwd))" composer update --no-interaction - name: Running single site unit tests From 260e22e9de880f504d2b8bb583c4fd99e9e9a13a Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 31 Jan 2024 15:13:18 -0800 Subject: [PATCH 11/13] Dump current PHP version when bailing to install/update for build-cs --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 9ddef17303..801af755ef 100644 --- a/composer.json +++ b/composer.json @@ -20,8 +20,8 @@ "php": ">=7|^8" }, "scripts": { - "post-install-cmd": "if [ $(php -r 'echo PHP_MAJOR_VERSION;') -ge 8 ]; then composer --working-dir=build-cs install --no-interaction; else echo 'Skipping composer install for build-cs since not on PHP 8.'; fi", - "post-update-cmd": "if [ $(php -r 'echo PHP_MAJOR_VERSION;') -ge 8 ]; then composer --working-dir=build-cs update --no-interaction; else echo 'Skipping composer update for build-cs since not on PHP 8.'; fi", + "post-install-cmd": "if [ $(php -r 'echo PHP_MAJOR_VERSION;') -ge 8 ]; then composer --working-dir=build-cs install --no-interaction; else echo 'Skipping composer install for build-cs since not on PHP 8. You are running: '; php -v; fi", + "post-update-cmd": "if [ $(php -r 'echo PHP_MAJOR_VERSION;') -ge 8 ]; then composer --working-dir=build-cs update --no-interaction; else echo 'Skipping composer update for build-cs since not on PHP 8 You are running: '; php -v; fi", "phpstan": "build-cs/vendor/bin/phpstan analyse --memory-limit=2048M -c phpstan.neon.dist", "format": "build-cs/vendor/bin/phpcbf --standard=phpcs.xml.dist --report-summary --report-source", "lint": "build-cs/vendor/bin/phpcs --standard=phpcs.xml.dist", From 1193606390624aa73f650ea079ab215202d6ee7a Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 31 Jan 2024 15:19:11 -0800 Subject: [PATCH 12/13] Use better PHP version comparison to bail if less than 8.1 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 801af755ef..4aef4dfb4b 100644 --- a/composer.json +++ b/composer.json @@ -20,8 +20,8 @@ "php": ">=7|^8" }, "scripts": { - "post-install-cmd": "if [ $(php -r 'echo PHP_MAJOR_VERSION;') -ge 8 ]; then composer --working-dir=build-cs install --no-interaction; else echo 'Skipping composer install for build-cs since not on PHP 8. You are running: '; php -v; fi", - "post-update-cmd": "if [ $(php -r 'echo PHP_MAJOR_VERSION;') -ge 8 ]; then composer --working-dir=build-cs update --no-interaction; else echo 'Skipping composer update for build-cs since not on PHP 8 You are running: '; php -v; fi", + "post-install-cmd": "if php -r 'exit( version_compare( phpversion(), \"8.1\", \">=\" ) ? 0 : 1 );'; then composer --working-dir=build-cs install --no-interaction; else echo 'Skipping composer install for build-cs since not on PHP 8.1. You are running: '; php -v; fi", + "post-update-cmd": "if php -r 'exit( version_compare( phpversion(), \"8.1\", \">=\" ) ? 0 : 1 );'; then composer --working-dir=build-cs update --no-interaction; else echo 'Skipping composer update for build-cs since not on PHP 8.1 You are running: '; php -v; fi", "phpstan": "build-cs/vendor/bin/phpstan analyse --memory-limit=2048M -c phpstan.neon.dist", "format": "build-cs/vendor/bin/phpcbf --standard=phpcs.xml.dist --report-summary --report-source", "lint": "build-cs/vendor/bin/phpcs --standard=phpcs.xml.dist", From aad3002eedad6c998c1abe890697d6c3f61f573d Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 31 Jan 2024 15:23:04 -0800 Subject: [PATCH 13/13] Add missing period and indicate at least PHP 8.1 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 4aef4dfb4b..acb638d468 100644 --- a/composer.json +++ b/composer.json @@ -20,8 +20,8 @@ "php": ">=7|^8" }, "scripts": { - "post-install-cmd": "if php -r 'exit( version_compare( phpversion(), \"8.1\", \">=\" ) ? 0 : 1 );'; then composer --working-dir=build-cs install --no-interaction; else echo 'Skipping composer install for build-cs since not on PHP 8.1. You are running: '; php -v; fi", - "post-update-cmd": "if php -r 'exit( version_compare( phpversion(), \"8.1\", \">=\" ) ? 0 : 1 );'; then composer --working-dir=build-cs update --no-interaction; else echo 'Skipping composer update for build-cs since not on PHP 8.1 You are running: '; php -v; fi", + "post-install-cmd": "if php -r 'exit( version_compare( phpversion(), \"8.1\", \">=\" ) ? 0 : 1 );'; then composer --working-dir=build-cs install --no-interaction; else echo 'Skipping composer install for build-cs since not on PHP 8.1+. You are running: '; php -v; fi", + "post-update-cmd": "if php -r 'exit( version_compare( phpversion(), \"8.1\", \">=\" ) ? 0 : 1 );'; then composer --working-dir=build-cs update --no-interaction; else echo 'Skipping composer update for build-cs since not on PHP 8.1+. You are running: '; php -v; fi", "phpstan": "build-cs/vendor/bin/phpstan analyse --memory-limit=2048M -c phpstan.neon.dist", "format": "build-cs/vendor/bin/phpcbf --standard=phpcs.xml.dist --report-summary --report-source", "lint": "build-cs/vendor/bin/phpcs --standard=phpcs.xml.dist",