-
Notifications
You must be signed in to change notification settings - Fork 4
201 lines (174 loc) · 7.75 KB
/
tests.yml
File metadata and controls
201 lines (174 loc) · 7.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
name: E2E Tests
on:
push:
pull_request:
jobs:
e2e:
name: PHP ${{ matrix.php }} - WP ${{ matrix.wordpress }}
runs-on: ubuntu-24.04
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@v4
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@v3
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@v3
- name: Build FrankenPHP image (with cache)
id: build
uses: docker/build-push-action@v6
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@v4
with:
version: 10
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: "pnpm"
- name: Install pnpm dependencies
run: pnpm install
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Cache composer dependencies
uses: actions/cache@v3
with:
path: vendor
key: composer-${{ hashFiles('composer.lock') }}
- name: Run composer install
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Run Pest tests
run: ./vendor/bin/pest -v --ci --bail --colors=always
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
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"