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
155 changes: 17 additions & 138 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,22 @@ on:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
e2e:
name: PHP ${{ matrix.php }} - WP ${{ matrix.wordpress }}
runs-on: ubuntu-24.04
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
php: ["8.2", "8.3", "8.4"]
wordpress: ["6.7", "6.8"]
exclude:
# Exclude older PHP versions with newer WordPress
- php: "7.4"
wordpress: "6.5.3"

services:
mysql:
image: mysql:8.0
env:
MYSQL_DATABASE: wordpress
MYSQL_ROOT_PASSWORD: root
ports: [3306:3306]
options: >-
--health-cmd="mysqladmin ping -h 127.0.0.1 -uroot -proot"
--health-interval=10s
--health-timeout=5s
--health-retries=5

env:
WP_VERSION: ${{ matrix.wordpress }}
WP_SITE_URL: http://localhost:8100
WP_DB_NAME: wordpress
WP_DB_USER: root
WP_DB_PASS: root
WP_DB_HOST: 127.0.0.1

steps:
- name: Check MySQL tables
run: |
echo "Listing databases:"
mysql -h 127.0.0.1 -uroot -proot -e "SHOW DATABASES;"

echo "Checking if 'wordpress' database has any tables:"
mysql -h 127.0.0.1 -uroot -proot -D wordpress -e "SHOW TABLES;" || echo "No tables found (yet)."

- name: Checkout plugin
uses: actions/checkout@v6
with:
Expand All @@ -59,106 +31,10 @@ jobs:
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
# Note: Specified version is only for running tests,
# as the WordPress PHP version is set inside the FrankenPHP Dockerfile.
# Host PHP is used only to run Pest; WordPress PHP is set via WP_ENV_PHP_VERSION below.
php-version: 8.4
extensions: mysqli, zip, gd
coverage: none
tools: wp-cli

- name: Cache WordPress archive
id: cache-wordpress
uses: actions/cache@v5
with:
path: /tmp/wp
key: wp-${{ matrix.wordpress }}

- name: Download WordPress
if: steps.cache-wordpress.outputs.cache-hit != 'true'
run: |
mkdir -p /tmp/wp
curl -O https://wordpress.org/wordpress-${WP_VERSION}.tar.gz
tar -xzf wordpress-${WP_VERSION}.tar.gz --strip-components=1 -C /tmp/wp
rm wordpress-${WP_VERSION}.tar.gz

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

- name: Build FrankenPHP image (with cache)
id: build
uses: docker/build-push-action@v7
env:
DOCKER_BUILD_SUMMARY: false
with:
context: .
file: .github/docker/Dockerfile
tags: frankenphp-${{ matrix.php }}
load: true
build-args: |
PHP_VERSION=${{ matrix.php }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Start FrankenPHP server
run: |
docker run -d \
--name frankenphp \
--network host \
-p 8100:8100 \
-v /tmp/wp:/var/www/html \
-v $GITHUB_WORKSPACE:/var/www/html/wp-content/plugins/simpleanalytics \
-v $GITHUB_WORKSPACE/Caddyfile:/etc/frankenphp/Caddyfile \
frankenphp-${{ matrix.php }}

- name: Wait for FrankenPHP to be ready
run: |
for i in $(seq 1 30); do
curl -s -o /dev/null http://localhost:8100 && echo "Server is up" && exit 0
echo "Waiting... ($i/30)"
sleep 2
done
echo "Server did not start in time" && exit 1

- name: Verify MySQL is accepting connections
run: |
for i in $(seq 1 10); do
mysql -h 127.0.0.1 -uroot -proot -e "SELECT 1" && echo "MySQL ready" && exit 0
echo "Waiting for MySQL... ($i/10)"
sleep 2
done
echo "MySQL not ready" && exit 1

- name: Install WordPress
run: |
rm -f /tmp/wp/wp-config.php
wp config create \
--dbname="$WP_DB_NAME" \
--dbuser="$WP_DB_USER" \
--dbpass="$WP_DB_PASS" \
--dbhost="$WP_DB_HOST" \
--path=/tmp/wp \
--skip-check
wp config set DISABLE_WP_CRON true --raw --path=/tmp/wp
wp core install \
--url="${WP_SITE_URL}" \
--title="Test Site" \
--admin_user=admin \
--admin_password=admin \
--admin_email=test@example.com \
--path=/tmp/wp \
--skip-email \
--allow-root
wp user create author author@local.test --role=author --user_pass=author --path=/tmp/wp --allow-root
wp user create editor editor@local.test --role=editor --user_pass=editor --path=/tmp/wp --allow-root
wp user create subscriber subscriber@local.test --role=subscriber --user_pass=subscriber --path=/tmp/wp --allow-root

- name: Show current config values
run: wp config list --path=/tmp/wp --allow-root

- name: Warm up WordPress
run: |
curl -s -o /dev/null -w "wp-login.php: HTTP %{http_code} in %{time_total}s\n" http://localhost:8100/wp-login.php
curl -s -o /dev/null -w "homepage: HTTP %{http_code} in %{time_total}s\n" http://localhost:8100/

- name: Install pnpm
uses: pnpm/action-setup@v5
Expand All @@ -174,8 +50,17 @@ jobs:
- name: Install pnpm dependencies
run: pnpm install

- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Set WordPress version override
run: |
echo '{"core": "https://wordpress.org/wordpress-${{ matrix.wordpress }}.zip"}' > .wp-env.override.json

- name: Start wp-env
run: pnpm exec wp-env start
env:
WP_ENV_PHP_VERSION: ${{ matrix.php }}

- name: Install Playwright browsers
run: pnpm run tests:install

- name: Cache composer dependencies
uses: actions/cache@v5
Expand All @@ -196,9 +81,3 @@ jobs:
name: test-results-php${{ matrix.php }}-wp${{ matrix.wordpress }}
path: tests/Browser/Screenshots
retention-days: 30

- name: Show FrankenPHP logs
if: always()
run: |
echo "=== FrankenPHP logs ==="
docker logs frankenphp || echo "No logs found"
9 changes: 9 additions & 0 deletions .wp-env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"plugins": ["."],
"config": {
"DISABLE_WP_CRON": true
},
"lifecycleScripts": {
"afterStart": "bash bin/wp-env-setup.sh"
}
}
13 changes: 13 additions & 0 deletions bin/wp-env-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
# Runs after `wp-env start` to set up test users and admin password.
# Safe to re-run: user creation failures (already exists) are ignored.
set -e

WP_ENV="./node_modules/.bin/wp-env"

echo "Creating test users..."
$WP_ENV run cli wp user create author author@local.test --role=author --user_pass=author --allow-root 2>/dev/null || true
$WP_ENV run cli wp user create editor editor@local.test --role=editor --user_pass=editor --allow-root 2>/dev/null || true
$WP_ENV run cli wp user create subscriber subscriber@local.test --role=subscriber --user_pass=subscriber --allow-root 2>/dev/null || true

echo "wp-env setup complete."
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
"scripts": {
"dev": "tailwindcss -i resources/css/settings.css -o build/css/settings.css --watch",
"build": "tailwindcss build -i resources/css/settings.css -o build/css/settings.css",
"wp-env": "wp-env",
"tests:install": "playwright install --with-deps chromium",
"tests": "playwright test"
},
"devDependencies": {
"@tailwindcss/forms": "^0.5.11",
"@types/node": "^22.19.17",
"@wordpress/env": "^10.19.0",
"playwright": "^1.59.1",
"tailwindcss": "^3.4.19"
}
Expand Down
Loading
Loading