Skip to content

Commit dc6c154

Browse files
committed
Speed up PHPUnit and avoid E2E setup timeouts
Run E2E browsers in the official image matching the installed Playwright version. Use Docker Compose for readiness and a composite action for test execution and cleanup, avoiding Ubuntu package downloads. Enable CLI OPcache with a 256 MB cache for WordPress PHPUnit while preserving test diagnostics and file-change checks. Remove unused Buildx setup from the WordPress test workflows. https://playwright.dev/docs/docker#remote-connection
1 parent dd0bcd6 commit dc6c154

7 files changed

Lines changed: 96 additions & 19 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Run Playwright tests
2+
description: Run E2E tests with browsers from the matching official Playwright image.
3+
inputs:
4+
test-script:
5+
description: Composer script that runs the E2E tests.
6+
required: true
7+
runs:
8+
using: composite
9+
steps:
10+
- name: Resolve Playwright version
11+
id: playwright
12+
shell: bash
13+
working-directory: wordpress
14+
run: |
15+
node <<'NODE' >> "$GITHUB_ENV"
16+
const { createRequire } = require( 'node:module' );
17+
const { realpathSync } = require( 'node:fs' );
18+
const path = require( 'node:path' );
19+
const testRequire = createRequire( require.resolve( '@playwright/test/package.json' ) );
20+
const playwright = testRequire.resolve( 'playwright/package.json' );
21+
console.log( `PLAYWRIGHT_VERSION=${require( playwright ).version}` );
22+
console.log( `PLAYWRIGHT_PACKAGE=${path.dirname( playwright )}` );
23+
console.log( `PLAYWRIGHT_NODE_MODULES=${realpathSync( 'node_modules' )}` );
24+
NODE
25+
26+
- name: Start Playwright browser server
27+
shell: bash
28+
run: |
29+
# Pull the WordPress images meanwhile, so the test script can start them sooner.
30+
npm --prefix wordpress run env:pull -- --quiet &
31+
wordpress_pull=$!
32+
33+
# Bound each attempt, as a stalled pull would otherwise run into the job timeout.
34+
for attempt in 1 2 3; do
35+
timeout 3m docker compose -f "$GITHUB_ACTION_PATH/docker-compose.yml" pull && break
36+
if [ "$attempt" -eq 3 ]; then
37+
echo "Failed to pull the Playwright image after $attempt attempts." >&2
38+
exit 1
39+
fi
40+
echo "Pulling the Playwright image failed. Retrying in $(( attempt * 10 )) seconds..."
41+
sleep $(( attempt * 10 ))
42+
done
43+
44+
docker compose -f "$GITHUB_ACTION_PATH/docker-compose.yml" up --wait --wait-timeout 60
45+
wait "$wordpress_pull"
46+
47+
- name: Run E2E tests
48+
shell: bash
49+
env:
50+
TEST_SCRIPT: ${{ inputs.test-script }}
51+
PW_TEST_CONNECT_WS_ENDPOINT: ws://127.0.0.1:3000/
52+
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1'
53+
run: composer run "$TEST_SCRIPT"
54+
55+
- name: Show browser server logs
56+
if: ( failure() || cancelled() ) && steps.playwright.outcome == 'success'
57+
shell: bash
58+
run: docker compose -f "$GITHUB_ACTION_PATH/docker-compose.yml" logs
59+
60+
- name: Stop Playwright browser server
61+
if: always() && steps.playwright.outcome == 'success'
62+
shell: bash
63+
run: docker compose -f "$GITHUB_ACTION_PATH/docker-compose.yml" down
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: sqlite-playwright
2+
services:
3+
playwright:
4+
image: mcr.microsoft.com/playwright:v${PLAYWRIGHT_VERSION}-noble
5+
init: true
6+
network_mode: host
7+
ipc: host
8+
volumes:
9+
- ${PLAYWRIGHT_NODE_MODULES}:${PLAYWRIGHT_NODE_MODULES}:ro
10+
entrypoint: node
11+
command: [ '${PLAYWRIGHT_PACKAGE}/cli.js', run-server, --host, '127.0.0.1', --port, '3000' ]
12+
healthcheck:
13+
test:
14+
- CMD
15+
- node
16+
- -e
17+
- "fetch('http://127.0.0.1:3000/').then(r => process.exit(r.ok ? 0 : 1)).catch(() => process.exit(1))"
18+
start_period: 30s
19+
start_interval: 1s
20+
interval: 30s
21+
timeout: 5s
22+
retries: 3

‎.github/workflows/end-to-end-tests.yml‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,18 @@ jobs:
2222
- name: Checkout repository
2323
uses: actions/checkout@v4
2424

25-
- name: Set up Docker Buildx
26-
uses: docker/setup-buildx-action@v3
27-
2825
- name: Set UID and GID for PHP in WordPress images
2926
run: |
3027
echo "PHP_FPM_UID=$(id -u)" >> $GITHUB_ENV
3128
echo "PHP_FPM_GID=$(id -g)" >> $GITHUB_ENV
3229
33-
- name: Install Playwright browsers
34-
run: npx playwright install --with-deps
30+
- name: Prepare WordPress
31+
run: composer run wp-setup
3532

3633
- name: Run end-to-end tests
37-
run: composer run test-e2e
34+
uses: ./.github/actions/playwright
35+
with:
36+
test-script: test-e2e
3837

3938
- name: Stop Docker containers
4039
if: always()

‎.github/workflows/sqlite-plugin-phpunit-tests.yml‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ jobs:
2626
- name: Checkout repository
2727
uses: actions/checkout@v4
2828

29-
- name: Set up Docker Buildx
30-
uses: docker/setup-buildx-action@v3
31-
3229
- name: Set UID and GID for PHP in WordPress images
3330
run: |
3431
echo "PHP_FPM_UID=$(id -u)" >> $GITHUB_ENV

‎.github/workflows/wp-tests-end-to-end.yml‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,18 @@ jobs:
2222
- name: Checkout repository
2323
uses: actions/checkout@v4
2424

25-
- name: Set up Docker Buildx
26-
uses: docker/setup-buildx-action@v3
27-
2825
- name: Set UID and GID for PHP in WordPress images
2926
run: |
3027
echo "PHP_FPM_UID=$(id -u)" >> $GITHUB_ENV
3128
echo "PHP_FPM_GID=$(id -g)" >> $GITHUB_ENV
3229
33-
- name: Install Playwright browsers
34-
run: npx playwright install --with-deps
30+
- name: Prepare WordPress
31+
run: composer run wp-setup
3532

3633
- name: Run WordPress end-to-end tests
37-
run: composer run wp-test-e2e
34+
uses: ./.github/actions/playwright
35+
with:
36+
test-script: wp-test-e2e
3837

3938
- name: Stop Docker containers
4039
if: always()

‎.github/workflows/wp-tests-phpunit.yml‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ jobs:
2222
- name: Checkout repository
2323
uses: actions/checkout@v4
2424

25-
- name: Set up Docker Buildx
26-
uses: docker/setup-buildx-action@v3
27-
2825
- name: Set UID and GID for PHP in WordPress images
2926
run: |
3027
echo "PHP_FPM_UID=$(id -u)" >> $GITHUB_ENV

‎composer.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"wp-test-php": [
6868
"@wp-test-ensure-env @no_additional_args",
6969
"@wp-test-remove-database @no_additional_args",
70-
"npm --prefix wordpress run test:php -- @additional_args"
70+
"cd wordpress && node tools/local-env/scripts/docker.js run --rm php php -d opcache.enable_cli=1 -d opcache.memory_consumption=256 ./vendor/bin/phpunit @additional_args"
7171
],
7272
"wp-test-sqlite-plugin-php": [
7373
"@wp-test-php /var/www/tests-sqlite-database-integration/phpunit"

0 commit comments

Comments
 (0)