Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .github/actions/smoke-check/action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'Smoke check a WordPress installation'
description: 'Serves an installed single site with PHP built-in web server and checks that its front end, REST API, and admin respond.'
description: 'Serves an installed single site or network with PHP built-in web server and checks that its front end, REST API, and admin respond.'

inputs:
admin-user:
Expand Down
30 changes: 21 additions & 9 deletions .github/actions/smoke-check/smoke-check.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#!/bin/bash
#
# Smoke checks an installed WordPress single site over HTTP.
# Smoke checks an installed WordPress single site or the main site of a network over HTTP.
#
# Runs from the root of the installation, with WP-CLI available. Multisite is not supported because
# a network's domain lives in wp-config.php and the database, not just an option.
# Runs from the root of the installation, with WP-CLI available. The site must be installed at
# http://localhost/. curl connects to the local server but sends Host: localhost, so a network finds its
# main site and no URL in the database changes. php -S does no rewrites, so subsites are not checked.

set -euo pipefail

: "${RUNNER_TEMP:?}" "${WP_ADMIN_USER:?}" "${WP_ADMIN_PASSWORD:?}"

site_port=8889
site_url="http://127.0.0.1:${site_port}"
site_url='http://localhost'
connect_to="localhost:80:127.0.0.1:${site_port}"
server_log="${RUNNER_TEMP}/server.log"
jar="${RUNNER_TEMP}/cookies.txt"
: > "${jar}"
Expand All @@ -20,9 +22,12 @@ http_code=''

version="$(wp core version)"
Comment thread
adimoldovan marked this conversation as resolved.
Resolved

# Nothing undoes these, so the site is only good for this check afterwards.
wp option update home "${site_url}"
wp option update siteurl "${site_url}"
# Every request sends Host: localhost, so another install URL would fail later with a vague error.
installed_url="$(wp option get siteurl)"
[ "${installed_url%/}" = "${site_url}" ] \
|| { echo "::error::the site must be installed at ${site_url}/, not ${installed_url}"; exit 1; }

# Nothing undoes these, so cron stays off and external requests stay blocked afterwards.
# A fresh install shows posts here already, but the front page check below needs it.
wp option update show_on_front posts
# Both make requests no check asked for, and the update checks call api.wordpress.org.
Expand All @@ -45,7 +50,8 @@ trap stop_server EXIT
# No connection prints 000 and exits 7, which set -e would take as fatal.
deadline=$(( SECONDS + 30 ))
while :; do
ready_code="$(curl --silent --max-time 5 --output /dev/null --write-out '%{http_code}' "${site_url}/" || true)"
ready_code="$(curl --silent --max-time 5 --output /dev/null --write-out '%{http_code}' \
--connect-to "${connect_to}" "${site_url}/" || true)"
[ "${ready_code}" = '000' ] || break
[ "${SECONDS}" -lt "${deadline}" ] || { echo '::error::the server never answered'; exit 1; }
sleep 1
Expand All @@ -63,7 +69,7 @@ fetch() {
shift
: > "${response}"
curl --silent --show-error --max-time 30 --output "${response}" \
--write-out '%{http_code}' --cookie "${jar}" --cookie-jar "${jar}" \
--write-out '%{http_code}' --cookie "${jar}" --cookie-jar "${jar}" --connect-to "${connect_to}" \
"$@" "${site_url}${path}" > "${code}" || status=$?
http_code="$(cat "${code}")"
[ "${status}" -eq 0 ] || [ "${status}" -eq 22 ] \
Expand Down Expand Up @@ -108,6 +114,12 @@ echo 'ok login'
# The admin bar renders only for a logged-in user.
check '/wp-admin/' 'id="wpadminbar"' '</html>'

if wp core is-installed --network; then
check '/wp-admin/network/' 'id="wpadminbar"' ' network-admin' '</html>'
else
echo 'skip /wp-admin/network/ (not a network)'
fi

# Catches a fatal during shutdown. An empty log would let the grep pass silently.
[ -s "${server_log}" ] || { echo '::error::the server wrote no log'; exit 1; }
if grep -qE 'Fatal error|Uncaught|Segmentation fault' "${server_log}"; then
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/install-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,7 @@ jobs:
--admin_password="${WP_ADMIN_PASSWORD}" --admin_email=me@example.org --skip-email

- name: Post-install smoke check
# A network's domain lives in wp-config.php and the database, not just an option.
if: ${{ ! matrix.multisite }}
uses: WordPress/wordpress-develop/.github/actions/smoke-check@trunk # zizmor: ignore[unpinned-uses]
uses: $/.github/actions/smoke-check
with:
admin-user: ${{ env.WP_ADMIN_USER }}
admin-password: ${{ env.WP_ADMIN_PASSWORD }}
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/reusable-upgrade-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,7 @@ jobs:
run: wp core version

- name: Post-upgrade smoke check
# A network's domain lives in wp-config.php and the database, not just an option.
if: ${{ ! inputs.multisite }}
uses: WordPress/wordpress-develop/.github/actions/smoke-check@trunk # zizmor: ignore[unpinned-uses]
uses: $/.github/actions/smoke-check
with:
admin-user: ${{ env.WP_ADMIN_USER }}
admin-password: ${{ env.WP_ADMIN_PASSWORD }}
1 change: 1 addition & 0 deletions .github/workflows/upgrade-develop-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ on:
- '.github/actions/setup-npm/**'
- '.github/actions/setup-wp-cli/**'
- '.github/actions/run-with-retry/**'
- '.github/actions/smoke-check/**'
- '.github/workflows/upgrade-develop-testing.yml'
- '.github/workflows/reusable-upgrade-testing.yml'
schedule:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/upgrade-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ on:
paths:
- '.github/actions/setup-wp-cli/**'
- '.github/actions/run-with-retry/**'
- '.github/actions/smoke-check/**'
- '.github/workflows/upgrade-testing.yml'
- '.github/workflows/reusable-upgrade-testing.yml'
- '.github/workflows/reusable-download-wordpress-release.yml'
Expand Down
Loading