From 5e0d873e37907293881b306cb84dfb8a20194d40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jake=C5=A1?= Date: Fri, 6 Nov 2026 17:19:33 +0100 Subject: [PATCH 1/3] Remove the Docker cleanup steps from WordPress CI jobs GitHub-hosted runners are discarded after each job, so stopping the containers and removing their volumes only adds about 12 seconds to the job. --- .github/workflows/end-to-end-tests.yml | 4 ---- .github/workflows/sqlite-plugin-phpunit-tests.yml | 4 ---- .github/workflows/wp-tests-end-to-end.yml | 4 ---- .github/workflows/wp-tests-phpunit.yml | 4 ---- 4 files changed, 16 deletions(-) diff --git a/.github/workflows/end-to-end-tests.yml b/.github/workflows/end-to-end-tests.yml index 635f6d467..051b1c214 100644 --- a/.github/workflows/end-to-end-tests.yml +++ b/.github/workflows/end-to-end-tests.yml @@ -34,7 +34,3 @@ jobs: uses: ./.github/actions/playwright with: test-script: test-e2e - - - name: Stop Docker containers - if: always() - run: composer run wp-test-clean diff --git a/.github/workflows/sqlite-plugin-phpunit-tests.yml b/.github/workflows/sqlite-plugin-phpunit-tests.yml index b23049558..43c3f97db 100644 --- a/.github/workflows/sqlite-plugin-phpunit-tests.yml +++ b/.github/workflows/sqlite-plugin-phpunit-tests.yml @@ -36,7 +36,3 @@ jobs: - name: Run SQLite plugin multisite PHPUnit tests run: composer run wp-test-sqlite-plugin-php-multisite - - - name: Stop Docker containers - if: always() - run: composer run wp-test-clean diff --git a/.github/workflows/wp-tests-end-to-end.yml b/.github/workflows/wp-tests-end-to-end.yml index ae57bc179..5910c4653 100644 --- a/.github/workflows/wp-tests-end-to-end.yml +++ b/.github/workflows/wp-tests-end-to-end.yml @@ -34,7 +34,3 @@ jobs: uses: ./.github/actions/playwright with: test-script: wp-test-e2e - - - name: Stop Docker containers - if: always() - run: composer run wp-test-clean diff --git a/.github/workflows/wp-tests-phpunit.yml b/.github/workflows/wp-tests-phpunit.yml index 615ddc7b6..1409ef7a7 100644 --- a/.github/workflows/wp-tests-phpunit.yml +++ b/.github/workflows/wp-tests-phpunit.yml @@ -29,7 +29,3 @@ jobs: - name: Run WordPress PHPUnit tests run: node .github/workflows/wp-tests-phpunit-run.js - - - name: Stop Docker containers - if: always() - run: composer run wp-test-clean From 4247e59c7ab353d2cf038913a51468e28666c038 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jake=C5=A1?= Date: Fri, 6 Nov 2026 17:19:34 +0100 Subject: [PATCH 2/3] Run PHPUnit without the full WordPress environment PHPUnit runs in the PHP container and uses the SQLite drop-in, so it doesn't need MySQL, nginx, WP-CLI, a WordPress installation, or the Gutenberg and Query Monitor plugins. The only thing it needed from "env:install" is "wp-tests-config.php", so "wp-setup.sh" now creates that file, and it is the last thing the script does. This also makes the file a better check for a finished setup than "wp-load.php", which exists right after cloning. --- composer.json | 10 +++++++--- wp-setup.sh | 10 ++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 256a71e03..348419869 100644 --- a/composer.json +++ b/composer.json @@ -59,13 +59,17 @@ "npm --prefix wordpress run env:cli -- plugin install gutenberg --version=22.3.0", "npm --prefix wordpress run env:cli -- plugin install query-monitor" ], - "wp-test-ensure-env": [ - "if [ ! -f wordpress/src/wp-load.php ]; then composer run wp-setup; fi", + "wp-test-ensure-php-env": [ + "if [ ! -f wordpress/wp-tests-config.php ]; then composer run wp-setup; fi", "@putenv COMPOSE_IGNORE_ORPHANS=true", + "if [ ! -f wordpress/vendor/autoload.php ]; then npm --prefix wordpress run env:composer -- update -W; fi" + ], + "wp-test-ensure-env": [ + "@wp-test-ensure-php-env", "cd wordpress && if [ -z \"$(DOTENV_CONFIG_QUIET=true node tools/local-env/scripts/docker.js ps -q)\" ]; then cd ..; composer run wp-test-start; fi" ], "wp-test-php": [ - "@wp-test-ensure-env @no_additional_args", + "@wp-test-ensure-php-env @no_additional_args", "@wp-test-remove-database @no_additional_args", "cd wordpress && node tools/local-env/scripts/docker.js run --rm php php -d zend.enable_gc=0 -d opcache.enable_cli=1 -d opcache.memory_consumption=256 -d opcache.jit=tracing -d opcache.jit_buffer_size=64M ./vendor/bin/phpunit @additional_args" ], diff --git a/wp-setup.sh b/wp-setup.sh index e5e342030..bd85b72cd 100755 --- a/wp-setup.sh +++ b/wp-setup.sh @@ -88,3 +88,13 @@ cp "$WP_DIR/.env.example" "$WP_DIR/.env" echo "Installing dependencies..." npm --prefix "$WP_DIR" install npm --prefix "$WP_DIR" run build:dev + +# 10. Create "wp-tests-config.php" like "tools/local-env/scripts/install.js" does, so PHPUnit doesn't need "env:install". +echo "Creating the 'wp-tests-config.php' file..." +sed \ + -e "s/youremptytestdbnamehere/wordpress_develop_tests/" \ + -e "s/yourusernamehere/root/" \ + -e "s/yourpasswordhere/password/" \ + -e "s/localhost/mysql/" \ + "$WP_DIR/wp-tests-config-sample.php" > "$WP_DIR/wp-tests-config.php" +printf "\ndefine( 'FS_METHOD', 'direct' );\n" >> "$WP_DIR/wp-tests-config.php" From cb4fd457fd03d0c89bb6d3d1dcd889c11ded795e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jake=C5=A1?= Date: Fri, 6 Nov 2026 17:19:34 +0100 Subject: [PATCH 3/3] Cache the prepared WordPress folder on CI Installing the npm packages and building WordPress takes about 100 seconds of each WordPress CI job, and the result only changes when the WordPress branch moves or our setup changes. The cache includes Composer packages too, so that PHPUnit jobs don't depend on GitHub and Packagist being available. --- .github/actions/wordpress/action.yml | 36 +++++++++++++++++++ .github/workflows/end-to-end-tests.yml | 2 +- .../workflows/sqlite-plugin-phpunit-tests.yml | 3 ++ .github/workflows/wp-tests-end-to-end.yml | 2 +- .github/workflows/wp-tests-phpunit.yml | 3 ++ 5 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 .github/actions/wordpress/action.yml diff --git a/.github/actions/wordpress/action.yml b/.github/actions/wordpress/action.yml new file mode 100644 index 000000000..bc374fd84 --- /dev/null +++ b/.github/actions/wordpress/action.yml @@ -0,0 +1,36 @@ +name: Prepare WordPress +description: Set up the WordPress repository. +runs: + using: composite + steps: + - name: Resolve WordPress cache key + id: wordpress + shell: bash + env: + # The setup script builds the "wordpress" folder and copies "db.copy" into it. + SETUP_HASH: ${{ hashFiles( 'wp-setup.sh', 'packages/plugin-sqlite-database-integration/db.copy' ) }} + run: | + version="$( sed -n 's/^WP_VERSION="\(.*\)"$/\1/p' wp-setup.sh )" + commit="$( git ls-remote --exit-code https://github.com/WordPress/wordpress-develop.git "refs/heads/$version" | cut -f1 )" + echo "cache-key=wordpress-$( node --version )-$commit-$SETUP_HASH" >> "$GITHUB_OUTPUT" + + - name: Restore WordPress from the cache + id: cache + uses: actions/cache/restore@v6 + with: + path: wordpress + key: ${{ steps.wordpress.outputs.cache-key }} + + - name: Set up WordPress + if: steps.cache.outputs.cache-hit != 'true' + shell: bash + run: composer run wp-test-ensure-php-env + + # Save now rather than using "actions/cache", which saves at the end of the job. + # Saving after the tests would also cache files they create, like the SQLite database. + - name: Save WordPress to the cache + if: steps.cache.outputs.cache-hit != 'true' + uses: actions/cache/save@v6 + with: + path: wordpress + key: ${{ steps.wordpress.outputs.cache-key }} diff --git a/.github/workflows/end-to-end-tests.yml b/.github/workflows/end-to-end-tests.yml index 051b1c214..79aa72b81 100644 --- a/.github/workflows/end-to-end-tests.yml +++ b/.github/workflows/end-to-end-tests.yml @@ -28,7 +28,7 @@ jobs: echo "PHP_FPM_GID=$(id -g)" >> $GITHUB_ENV - name: Prepare WordPress - run: composer run wp-setup + uses: ./.github/actions/wordpress - name: Run end-to-end tests uses: ./.github/actions/playwright diff --git a/.github/workflows/sqlite-plugin-phpunit-tests.yml b/.github/workflows/sqlite-plugin-phpunit-tests.yml index 43c3f97db..bdf6edd1f 100644 --- a/.github/workflows/sqlite-plugin-phpunit-tests.yml +++ b/.github/workflows/sqlite-plugin-phpunit-tests.yml @@ -31,6 +31,9 @@ jobs: echo "PHP_FPM_UID=$(id -u)" >> $GITHUB_ENV echo "PHP_FPM_GID=$(id -g)" >> $GITHUB_ENV + - name: Prepare WordPress + uses: ./.github/actions/wordpress + - name: Run SQLite plugin single-site PHPUnit tests run: composer run wp-test-sqlite-plugin-php diff --git a/.github/workflows/wp-tests-end-to-end.yml b/.github/workflows/wp-tests-end-to-end.yml index 5910c4653..3d698be25 100644 --- a/.github/workflows/wp-tests-end-to-end.yml +++ b/.github/workflows/wp-tests-end-to-end.yml @@ -28,7 +28,7 @@ jobs: echo "PHP_FPM_GID=$(id -g)" >> $GITHUB_ENV - name: Prepare WordPress - run: composer run wp-setup + uses: ./.github/actions/wordpress - name: Run WordPress end-to-end tests uses: ./.github/actions/playwright diff --git a/.github/workflows/wp-tests-phpunit.yml b/.github/workflows/wp-tests-phpunit.yml index 1409ef7a7..36269fb85 100644 --- a/.github/workflows/wp-tests-phpunit.yml +++ b/.github/workflows/wp-tests-phpunit.yml @@ -27,5 +27,8 @@ jobs: echo "PHP_FPM_UID=$(id -u)" >> $GITHUB_ENV echo "PHP_FPM_GID=$(id -g)" >> $GITHUB_ENV + - name: Prepare WordPress + uses: ./.github/actions/wordpress + - name: Run WordPress PHPUnit tests run: node .github/workflows/wp-tests-phpunit-run.js