Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/actions/wordpress/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Prepare WordPress
description: Restore the WordPress repository and its dependencies from the cache, or set them up.
runs:
using: composite
steps:
- name: Resolve WordPress cache key
id: wordpress
shell: bash
env:
# "wp-setup.sh" and the "db.php" source file decide what ends up in the "wordpress" folder.
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 right after the setup, so that the cache doesn't include anything created by the tests.
- 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 }}
6 changes: 1 addition & 5 deletions .github/workflows/end-to-end-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,9 @@ 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
with:
test-script: test-e2e

- name: Stop Docker containers
if: always()
run: composer run wp-test-clean
7 changes: 3 additions & 4 deletions .github/workflows/sqlite-plugin-phpunit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ 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

- 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
6 changes: 1 addition & 5 deletions .github/workflows/wp-tests-end-to-end.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,9 @@ 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
with:
test-script: wp-test-e2e

- name: Stop Docker containers
if: always()
run: composer run wp-test-clean
7 changes: 3 additions & 4 deletions .github/workflows/wp-tests-phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +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

- name: Stop Docker containers
if: always()
run: composer run wp-test-clean
10 changes: 7 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/bin/phpunit ]; 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 opcache.enable_cli=1 -d opcache.memory_consumption=256 -d opcache.jit=tracing -d opcache.jit_buffer_size=64M ./vendor/bin/phpunit @additional_args"
],
Expand Down
10 changes: 10 additions & 0 deletions wp-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,13 @@ cp "$WP_DIR/.env.example" "$WP_DIR/.env"
echo "Installing dependencies..."
npm --prefix "$WP_DIR" install
npm --prefix "$WP_DIR" run build:dev

# 9. Create "wp-tests-config.php" like "env:install" does, so that PHPUnit doesn't need the full environment.
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"
Loading