1111 required : true
1212 type : string
1313 description : ' Playwright project name to run'
14+ multisite :
15+ required : false
16+ type : boolean
17+ default : false
18+ description : ' If true, convert the site to multisite and create a subsite.'
1419
1520jobs :
1621 playwright-test :
1722 name : Playwright tests (${{ inputs.test-mode == 'default' && 'Default Mode' || 'File-based Execution' }})
1823 runs-on : ubuntu-22.04
24+ services :
25+ mysql :
26+ image : mysql:8.0
27+ env :
28+ MYSQL_DATABASE : wordpress
29+ MYSQL_USER : wordpress
30+ MYSQL_PASSWORD : wordpress
31+ MYSQL_ROOT_PASSWORD : root
32+ options : >-
33+ --health-cmd="mysqladmin ping -h localhost -proot"
34+ --health-interval=10s
35+ --health-timeout=5s
36+ --health-retries=10
37+
38+ wordpress :
39+ image : wordpress:php8.1-apache
40+ env :
41+ WORDPRESS_DB_HOST : mysql:3306
42+ WORDPRESS_DB_USER : wordpress
43+ WORDPRESS_DB_PASSWORD : wordpress
44+ WORDPRESS_DB_NAME : wordpress
45+ WORDPRESS_DEBUG : 1
46+ WORDPRESS_CONFIG_EXTRA : |
47+ define( 'FS_METHOD', 'direct' );
48+ define( 'WP_DEBUG_LOG', true );
49+ define( 'WP_DEBUG_DISPLAY', false );
50+ define( 'SCRIPT_DEBUG', true );
51+ define( 'WP_ENVIRONMENT_TYPE', 'local' );
52+ ports :
53+ - 8888:80
1954 steps :
2055 - name : Checkout source code
2156 uses : actions/checkout@v4
5994 restore-keys : |
6095 ${{ runner.os }}-deps-
6196
62- - name : Install workflow dependencies (wp-env, playwright)
97+ - name : Install workflow dependencies
6398 if : steps.deps-cache.outputs.cache-hit != 'true'
6499 run : npm run prepare-environment:ci && npm run bundle
65100
@@ -72,28 +107,111 @@ jobs:
72107 node_modules
73108 key : ${{ runner.os }}-deps-${{ steps.deps-hash.outputs.deps_hash }}
74109
75- - name : Start WordPress environment
110+ - name : Wait for WordPress to be reachable
111+ run : |
112+ for i in $(seq 1 60); do
113+ if curl -fsS http://localhost:8888/wp-login.php >/dev/null; then
114+ echo "WordPress is reachable."
115+ exit 0
116+ fi
117+ echo "Waiting for WordPress... ($i/60)"
118+ sleep 2
119+ done
120+
121+ echo "WordPress did not start in time."
122+ echo "::group::WordPress container logs"
123+ docker logs "${{ job.services.wordpress.id }}" || true
124+ echo "::endgroup::"
125+ exit 1
126+
127+ - name : Download WP-CLI
128+ run : |
129+ curl -fsSL -o "${RUNNER_TEMP}/wp-cli.phar" https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
130+
131+ - name : Install WordPress (and optionally multisite)
132+ env :
133+ WP_CONTAINER : ${{ job.services.wordpress.id }}
134+ WP_URL : http://localhost:8888
135+ WP_ADMIN_USER : admin
136+ WP_ADMIN_PASSWORD : password
137+ WP_ADMIN_EMAIL : admin@example.org
138+ run : |
139+ set -euo pipefail
140+
141+ docker cp "${RUNNER_TEMP}/wp-cli.phar" "$WP_CONTAINER:/tmp/wp-cli.phar"
142+
143+ # Install WordPress if it isn't already installed.
144+ if ! docker exec -u root -w /var/www/html "$WP_CONTAINER" php /tmp/wp-cli.phar core is-installed --allow-root >/dev/null 2>&1; then
145+ docker exec -u root -w /var/www/html "$WP_CONTAINER" php /tmp/wp-cli.phar core install \
146+ --url="$WP_URL" \
147+ --title="Test Blog" \
148+ --admin_user="$WP_ADMIN_USER" \
149+ --admin_password="$WP_ADMIN_PASSWORD" \
150+ --admin_email="$WP_ADMIN_EMAIL" \
151+ --skip-email \
152+ --allow-root
153+ fi
154+
155+ if [ "${{ inputs.multisite }}" = "true" ]; then
156+ # Convert single site -> multisite (subdirectory). Subdomains don't work with localhost.
157+ if ! docker exec -u root -w /var/www/html "$WP_CONTAINER" php /tmp/wp-cli.phar core is-installed --network --allow-root >/dev/null 2>&1; then
158+ docker exec -u root -w /var/www/html "$WP_CONTAINER" php /tmp/wp-cli.phar core multisite-convert \
159+ --title="Test Network" \
160+ --base=/ \
161+ --allow-root
162+ fi
163+
164+ # Create a subsite for future multisite test coverage.
165+ if ! docker exec -u root -w /var/www/html "$WP_CONTAINER" php /tmp/wp-cli.phar site list --field=path --allow-root | grep -qx "/subsite/"; then
166+ docker exec -u root -w /var/www/html "$WP_CONTAINER" php /tmp/wp-cli.phar site create \
167+ --slug=subsite \
168+ --title="Subsite" \
169+ --email="$WP_ADMIN_EMAIL" \
170+ --allow-root
171+ fi
172+ fi
173+
174+ - name : Install plugin into WordPress container
175+ env :
176+ WP_CONTAINER : ${{ job.services.wordpress.id }}
76177 run : |
77- npx wp-env start
178+ set -euo pipefail
179+
180+ docker exec -u root -w /var/www/html "$WP_CONTAINER" rm -rf wp-content/plugins/code-snippets
181+ docker cp src "$WP_CONTAINER:/var/www/html/wp-content/plugins/code-snippets"
182+ docker exec -u root -w /var/www/html "$WP_CONTAINER" chown -R www-data:www-data wp-content/plugins/code-snippets
78183
79184 - name : Activate code-snippets plugin
80- run : npx wp-env run cli wp plugin activate code-snippets
185+ env :
186+ WP_CONTAINER : ${{ job.services.wordpress.id }}
187+ run : |
188+ set -euo pipefail
189+ if [ "${{ inputs.multisite }}" = "true" ]; then
190+ docker exec -u root -w /var/www/html "$WP_CONTAINER" php /tmp/wp-cli.phar plugin activate code-snippets --network --allow-root
191+ else
192+ docker exec -u root -w /var/www/html "$WP_CONTAINER" php /tmp/wp-cli.phar plugin activate code-snippets --allow-root
193+ fi
81194
82195 - name : WordPress debug information
196+ env :
197+ WP_CONTAINER : ${{ job.services.wordpress.id }}
83198 run : |
84- npx wp-env run cli wp core version
85- npx wp-env run cli wp --info
199+ docker exec -u root -w /var/www/html "$WP_CONTAINER" php /tmp/wp-cli.phar core version --allow-root
200+ docker exec -u root -w /var/www/html "$WP_CONTAINER" php /tmp/wp-cli.phar --allow-root --info
86201
87202 - name : Install playwright/test
88203 run : |
89204 npx playwright install chromium
90205
91206 - name : Run Playwright tests
92207 run : npm run test:playwright -- --project=${{ inputs.project-name }}
93-
94- - name : Stop WordPress environment
95- if : always()
96- run : npx wp-env stop
208+
209+ - name : Print WordPress logs on failure
210+ if : failure()
211+ run : |
212+ echo "::group::WordPress container logs"
213+ docker logs "${{ job.services.wordpress.id }}" || true
214+ echo "::endgroup::"
97215
98216 - uses : actions/upload-artifact@v4
99217 if : always()
0 commit comments