Skip to content
Merged
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
63 changes: 63 additions & 0 deletions .github/actions/playwright/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Run Playwright tests
description: Run E2E tests with browsers from the matching official Playwright image.
inputs:
test-script:
description: Composer script that runs the E2E tests.
required: true
runs:
using: composite
steps:
- name: Resolve Playwright version
id: playwright
shell: bash
working-directory: wordpress
run: |
node <<'NODE' >> "$GITHUB_ENV"
const { createRequire } = require( 'node:module' );
const { realpathSync } = require( 'node:fs' );
const path = require( 'node:path' );
const testRequire = createRequire( require.resolve( '@playwright/test/package.json' ) );
const playwright = testRequire.resolve( 'playwright/package.json' );
console.log( `PLAYWRIGHT_VERSION=${require( playwright ).version}` );
console.log( `PLAYWRIGHT_PACKAGE=${path.dirname( playwright )}` );
console.log( `PLAYWRIGHT_NODE_MODULES=${realpathSync( 'node_modules' )}` );
NODE

- name: Start Playwright browser server
shell: bash
run: |
# Pull the WordPress images meanwhile, so the test script can start them sooner.
npm --prefix wordpress run env:pull -- --quiet &
wordpress_pull=$!

# Bound each attempt, as a stalled pull would otherwise run into the job timeout.
for attempt in 1 2 3; do
timeout 3m docker compose -f "$GITHUB_ACTION_PATH/docker-compose.yml" pull && break
if [ "$attempt" -eq 3 ]; then
echo "Failed to pull the Playwright image after $attempt attempts." >&2
exit 1
fi
echo "Pulling the Playwright image failed. Retrying in $(( attempt * 10 )) seconds..."
sleep $(( attempt * 10 ))
done

docker compose -f "$GITHUB_ACTION_PATH/docker-compose.yml" up --wait --wait-timeout 60
wait "$wordpress_pull"

- name: Run E2E tests
shell: bash
env:
TEST_SCRIPT: ${{ inputs.test-script }}
PW_TEST_CONNECT_WS_ENDPOINT: ws://127.0.0.1:3000/
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1'
run: composer run "$TEST_SCRIPT"

- name: Show browser server logs
if: ( failure() || cancelled() ) && steps.playwright.outcome == 'success'
shell: bash
run: docker compose -f "$GITHUB_ACTION_PATH/docker-compose.yml" logs

- name: Stop Playwright browser server
if: always() && steps.playwright.outcome == 'success'
shell: bash
run: docker compose -f "$GITHUB_ACTION_PATH/docker-compose.yml" down
22 changes: 22 additions & 0 deletions .github/actions/playwright/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: sqlite-playwright
services:
playwright:
image: mcr.microsoft.com/playwright:v${PLAYWRIGHT_VERSION}-noble
init: true
network_mode: host
ipc: host
volumes:
- ${PLAYWRIGHT_NODE_MODULES}:${PLAYWRIGHT_NODE_MODULES}:ro
entrypoint: node
command: [ '${PLAYWRIGHT_PACKAGE}/cli.js', run-server, --host, '127.0.0.1', --port, '3000' ]
healthcheck:
test:
- CMD
- node
- -e
- "fetch('http://127.0.0.1:3000/').then(r => process.exit(r.ok ? 0 : 1)).catch(() => process.exit(1))"
start_period: 30s
start_interval: 1s
interval: 30s
timeout: 5s
retries: 3
11 changes: 5 additions & 6 deletions .github/workflows/end-to-end-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,18 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Set UID and GID for PHP in WordPress images
run: |
echo "PHP_FPM_UID=$(id -u)" >> $GITHUB_ENV
echo "PHP_FPM_GID=$(id -g)" >> $GITHUB_ENV

- name: Install Playwright browsers
run: npx playwright install --with-deps
- name: Prepare WordPress
run: composer run wp-setup

- name: Run end-to-end tests
run: composer run test-e2e
uses: ./.github/actions/playwright
with:
test-script: test-e2e

- name: Stop Docker containers
if: always()
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/sqlite-plugin-phpunit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Set UID and GID for PHP in WordPress images
run: |
echo "PHP_FPM_UID=$(id -u)" >> $GITHUB_ENV
Expand Down
11 changes: 5 additions & 6 deletions .github/workflows/wp-tests-end-to-end.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,18 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Set UID and GID for PHP in WordPress images
run: |
echo "PHP_FPM_UID=$(id -u)" >> $GITHUB_ENV
echo "PHP_FPM_GID=$(id -g)" >> $GITHUB_ENV

- name: Install Playwright browsers
run: npx playwright install --with-deps
- name: Prepare WordPress
run: composer run wp-setup

- name: Run WordPress end-to-end tests
run: composer run wp-test-e2e
uses: ./.github/actions/playwright
with:
test-script: wp-test-e2e

- name: Stop Docker containers
if: always()
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/wp-tests-phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Set UID and GID for PHP in WordPress images
run: |
echo "PHP_FPM_UID=$(id -u)" >> $GITHUB_ENV
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"wp-test-php": [
"@wp-test-ensure-env @no_additional_args",
"@wp-test-remove-database @no_additional_args",
"npm --prefix wordpress run test:php -- @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"
],
"wp-test-sqlite-plugin-php": [
"@wp-test-php /var/www/tests-sqlite-database-integration/phpunit"
Expand Down
6 changes: 5 additions & 1 deletion wp-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ sed -i.bak "s#class WpdbExposedMethodsForTesting extends wpdb {#class WpdbExpose
echo "Disabling the PHP OPcache revalidation delay..."
printf '\nopcache.revalidate_freq = 0\n' >> "$WP_DIR/tools/local-env/php-config.ini"

# 7. Install dependencies.
# 7. Create the ".env" file early, so that Docker commands before "env:start" use it too.
echo "Creating the '.env' file..."
cp "$WP_DIR/.env.example" "$WP_DIR/.env"

# 8. Install dependencies.
echo "Installing dependencies..."
npm --prefix "$WP_DIR" install
npm --prefix "$WP_DIR" run build:dev
Loading