diff --git a/.github/actions/smoke-check/action.yml b/.github/actions/smoke-check/action.yml index 4a115e0f6d754..73da5b84bf54b 100644 --- a/.github/actions/smoke-check/action.yml +++ b/.github/actions/smoke-check/action.yml @@ -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: diff --git a/.github/actions/smoke-check/smoke-check.sh b/.github/actions/smoke-check/smoke-check.sh index d3ab33e068f9e..cd265333c0e9c 100755 --- a/.github/actions/smoke-check/smoke-check.sh +++ b/.github/actions/smoke-check/smoke-check.sh @@ -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}" @@ -20,9 +22,12 @@ http_code='' version="$(wp core version)" -# 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. @@ -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 @@ -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 ] \ @@ -108,6 +114,12 @@ echo 'ok login' # The admin bar renders only for a logged-in user. check '/wp-admin/' 'id="wpadminbar"' '' +if wp core is-installed --network; then + check '/wp-admin/network/' 'id="wpadminbar"' ' network-admin' '' +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 diff --git a/.github/workflows/install-testing.yml b/.github/workflows/install-testing.yml index eb238338b3e87..fd47856680616 100644 --- a/.github/workflows/install-testing.yml +++ b/.github/workflows/install-testing.yml @@ -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 }} diff --git a/.github/workflows/reusable-upgrade-testing.yml b/.github/workflows/reusable-upgrade-testing.yml index 6510ba6818249..ef0ea40fae82c 100644 --- a/.github/workflows/reusable-upgrade-testing.yml +++ b/.github/workflows/reusable-upgrade-testing.yml @@ -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 }} diff --git a/.github/workflows/upgrade-develop-testing.yml b/.github/workflows/upgrade-develop-testing.yml index 1073c46786c0b..97744c960054f 100644 --- a/.github/workflows/upgrade-develop-testing.yml +++ b/.github/workflows/upgrade-develop-testing.yml @@ -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: diff --git a/.github/workflows/upgrade-testing.yml b/.github/workflows/upgrade-testing.yml index 59eec3837613a..62d5438372584 100644 --- a/.github/workflows/upgrade-testing.yml +++ b/.github/workflows/upgrade-testing.yml @@ -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'