Skip to content
Open
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
175 changes: 19 additions & 156 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,159 +7,27 @@ on:
branches:
- main

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

jobs:
e2e:
name: PHP ${{ matrix.php }} - WP ${{ matrix.wordpress }}
name: WP ${{ matrix.wordpress }} / PHP ${{ matrix.php }}
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:
persist-credentials: false

- 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.
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
with:
Expand All @@ -174,31 +42,26 @@ jobs:
- name: Install pnpm dependencies
run: pnpm install

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

- name: Cache composer dependencies
uses: actions/cache@v5
with:
path: vendor
key: composer-${{ hashFiles('composer.lock') }}
- name: Start wp-env
run: pnpm exec wp-env start

- name: Run composer install
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Install Playwright browsers
run: pnpm run tests:install

- name: Run Pest tests
run: ./vendor/bin/pest -v --ci --bail --colors=always
- name: Run Playwright tests
run: pnpm exec playwright test

- name: Upload test results
if: always()
uses: actions/upload-artifact@v7
with:
name: test-results-php${{ matrix.php }}-wp${{ matrix.wordpress }}
path: tests/Browser/Screenshots
path: test-results
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."
15 changes: 1 addition & 14 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
{
"require-dev": {
"rector/rector": "^1.2",
"pestphp/pest": "^4.1",
"pestphp/pest-plugin-browser": "^4.1",
"symfony/var-dumper": "^7.3"
},
"autoload": {
"psr-4": {
"Tests\\": "tests/"
}
},
"config": {
"allow-plugins": {
"pestphp/pest-plugin": true
}
"rector/rector": "^1.2"
}
}
Loading
Loading