Skip to content

Commit 551925a

Browse files
committed
wip
1 parent 45260dd commit 551925a

File tree

9 files changed

+3444
-468
lines changed

9 files changed

+3444
-468
lines changed

.github/workflows/tests.yml

Lines changed: 17 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -7,50 +7,22 @@ on:
77
branches:
88
- main
99

10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
1014
jobs:
1115
e2e:
1216
name: PHP ${{ matrix.php }} - WP ${{ matrix.wordpress }}
1317
runs-on: ubuntu-24.04
18+
timeout-minutes: 20
1419
strategy:
1520
fail-fast: false
1621
matrix:
1722
php: ["8.2", "8.3", "8.4"]
1823
wordpress: ["6.7", "6.8"]
19-
exclude:
20-
# Exclude older PHP versions with newer WordPress
21-
- php: "7.4"
22-
wordpress: "6.5.3"
23-
24-
services:
25-
mysql:
26-
image: mysql:8.0
27-
env:
28-
MYSQL_DATABASE: wordpress
29-
MYSQL_ROOT_PASSWORD: root
30-
ports: [3306:3306]
31-
options: >-
32-
--health-cmd="mysqladmin ping -h 127.0.0.1 -uroot -proot"
33-
--health-interval=10s
34-
--health-timeout=5s
35-
--health-retries=5
36-
37-
env:
38-
WP_VERSION: ${{ matrix.wordpress }}
39-
WP_SITE_URL: http://localhost:8100
40-
WP_DB_NAME: wordpress
41-
WP_DB_USER: root
42-
WP_DB_PASS: root
43-
WP_DB_HOST: 127.0.0.1
4424

4525
steps:
46-
- name: Check MySQL tables
47-
run: |
48-
echo "Listing databases:"
49-
mysql -h 127.0.0.1 -uroot -proot -e "SHOW DATABASES;"
50-
51-
echo "Checking if 'wordpress' database has any tables:"
52-
mysql -h 127.0.0.1 -uroot -proot -D wordpress -e "SHOW TABLES;" || echo "No tables found (yet)."
53-
5426
- name: Checkout plugin
5527
uses: actions/checkout@v6
5628
with:
@@ -59,106 +31,10 @@ jobs:
5931
- name: Set up PHP
6032
uses: shivammathur/setup-php@v2
6133
with:
62-
# Note: Specified version is only for running tests,
63-
# as the WordPress PHP version is set inside the FrankenPHP Dockerfile.
34+
# Host PHP is used only to run Pest; WordPress PHP is set via WP_ENV_PHP_VERSION below.
6435
php-version: 8.4
6536
extensions: mysqli, zip, gd
6637
coverage: none
67-
tools: wp-cli
68-
69-
- name: Cache WordPress archive
70-
id: cache-wordpress
71-
uses: actions/cache@v5
72-
with:
73-
path: /tmp/wp
74-
key: wp-${{ matrix.wordpress }}
75-
76-
- name: Download WordPress
77-
if: steps.cache-wordpress.outputs.cache-hit != 'true'
78-
run: |
79-
mkdir -p /tmp/wp
80-
curl -O https://wordpress.org/wordpress-${WP_VERSION}.tar.gz
81-
tar -xzf wordpress-${WP_VERSION}.tar.gz --strip-components=1 -C /tmp/wp
82-
rm wordpress-${WP_VERSION}.tar.gz
83-
84-
- name: Set up Docker Buildx
85-
uses: docker/setup-buildx-action@v4
86-
87-
- name: Build FrankenPHP image (with cache)
88-
id: build
89-
uses: docker/build-push-action@v7
90-
env:
91-
DOCKER_BUILD_SUMMARY: false
92-
with:
93-
context: .
94-
file: .github/docker/Dockerfile
95-
tags: frankenphp-${{ matrix.php }}
96-
load: true
97-
build-args: |
98-
PHP_VERSION=${{ matrix.php }}
99-
cache-from: type=gha
100-
cache-to: type=gha,mode=max
101-
102-
- name: Start FrankenPHP server
103-
run: |
104-
docker run -d \
105-
--name frankenphp \
106-
--network host \
107-
-p 8100:8100 \
108-
-v /tmp/wp:/var/www/html \
109-
-v $GITHUB_WORKSPACE:/var/www/html/wp-content/plugins/simpleanalytics \
110-
-v $GITHUB_WORKSPACE/Caddyfile:/etc/frankenphp/Caddyfile \
111-
frankenphp-${{ matrix.php }}
112-
113-
- name: Wait for FrankenPHP to be ready
114-
run: |
115-
for i in $(seq 1 30); do
116-
curl -s -o /dev/null http://localhost:8100 && echo "Server is up" && exit 0
117-
echo "Waiting... ($i/30)"
118-
sleep 2
119-
done
120-
echo "Server did not start in time" && exit 1
121-
122-
- name: Verify MySQL is accepting connections
123-
run: |
124-
for i in $(seq 1 10); do
125-
mysql -h 127.0.0.1 -uroot -proot -e "SELECT 1" && echo "MySQL ready" && exit 0
126-
echo "Waiting for MySQL... ($i/10)"
127-
sleep 2
128-
done
129-
echo "MySQL not ready" && exit 1
130-
131-
- name: Install WordPress
132-
run: |
133-
rm -f /tmp/wp/wp-config.php
134-
wp config create \
135-
--dbname="$WP_DB_NAME" \
136-
--dbuser="$WP_DB_USER" \
137-
--dbpass="$WP_DB_PASS" \
138-
--dbhost="$WP_DB_HOST" \
139-
--path=/tmp/wp \
140-
--skip-check
141-
wp config set DISABLE_WP_CRON true --raw --path=/tmp/wp
142-
wp core install \
143-
--url="${WP_SITE_URL}" \
144-
--title="Test Site" \
145-
--admin_user=admin \
146-
--admin_password=admin \
147-
--admin_email=test@example.com \
148-
--path=/tmp/wp \
149-
--skip-email \
150-
--allow-root
151-
wp user create author author@local.test --role=author --user_pass=author --path=/tmp/wp --allow-root
152-
wp user create editor editor@local.test --role=editor --user_pass=editor --path=/tmp/wp --allow-root
153-
wp user create subscriber subscriber@local.test --role=subscriber --user_pass=subscriber --path=/tmp/wp --allow-root
154-
155-
- name: Show current config values
156-
run: wp config list --path=/tmp/wp --allow-root
157-
158-
- name: Warm up WordPress
159-
run: |
160-
curl -s -o /dev/null -w "wp-login.php: HTTP %{http_code} in %{time_total}s\n" http://localhost:8100/wp-login.php
161-
curl -s -o /dev/null -w "homepage: HTTP %{http_code} in %{time_total}s\n" http://localhost:8100/
16238

16339
- name: Install pnpm
16440
uses: pnpm/action-setup@v5
@@ -174,8 +50,17 @@ jobs:
17450
- name: Install pnpm dependencies
17551
run: pnpm install
17652

177-
- name: Install Playwright Browsers
178-
run: npx playwright install --with-deps
53+
- name: Set WordPress version override
54+
run: |
55+
echo '{"core": "https://wordpress.org/wordpress-${{ matrix.wordpress }}.zip"}' > .wp-env.override.json
56+
57+
- name: Start wp-env
58+
run: pnpm exec wp-env start
59+
env:
60+
WP_ENV_PHP_VERSION: ${{ matrix.php }}
61+
62+
- name: Install Playwright browsers
63+
run: pnpm run tests:install
17964

18065
- name: Cache composer dependencies
18166
uses: actions/cache@v5
@@ -196,9 +81,3 @@ jobs:
19681
name: test-results-php${{ matrix.php }}-wp${{ matrix.wordpress }}
19782
path: tests/Browser/Screenshots
19883
retention-days: 30
199-
200-
- name: Show FrankenPHP logs
201-
if: always()
202-
run: |
203-
echo "=== FrankenPHP logs ==="
204-
docker logs frankenphp || echo "No logs found"

.wp-env.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"plugins": ["."],
3+
"config": {
4+
"DISABLE_WP_CRON": true
5+
},
6+
"lifecycleScripts": {
7+
"afterStart": "bash bin/wp-env-setup.sh"
8+
}
9+
}

bin/wp-env-setup.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
# Runs after `wp-env start` to set up test users and admin password.
3+
# Safe to re-run: user creation failures (already exists) are ignored.
4+
set -e
5+
6+
WP_ENV="./node_modules/.bin/wp-env"
7+
8+
echo "Creating test users..."
9+
$WP_ENV run cli wp user create author author@local.test --role=author --user_pass=author --allow-root 2>/dev/null || true
10+
$WP_ENV run cli wp user create editor editor@local.test --role=editor --user_pass=editor --allow-root 2>/dev/null || true
11+
$WP_ENV run cli wp user create subscriber subscriber@local.test --role=subscriber --user_pass=subscriber --allow-root 2>/dev/null || true
12+
13+
echo "wp-env setup complete."

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
"scripts": {
44
"dev": "tailwindcss -i resources/css/settings.css -o build/css/settings.css --watch",
55
"build": "tailwindcss build -i resources/css/settings.css -o build/css/settings.css",
6+
"wp-env": "wp-env",
67
"tests:install": "playwright install --with-deps chromium",
78
"tests": "playwright test"
89
},
910
"devDependencies": {
1011
"@tailwindcss/forms": "^0.5.11",
1112
"@types/node": "^22.19.17",
13+
"@wordpress/env": "^10.19.0",
1214
"playwright": "^1.59.1",
1315
"tailwindcss": "^3.4.19"
1416
}

0 commit comments

Comments
 (0)