Make WordPress Core

Changeset 63447


Ignore:
Timestamp:
09/03/2026 04:03:37 PM (2 months ago)
Author:
lancewillett
Message:

Build/Test Tools: Smoke test upgraded sites over HTTP.

Upgrade tests previously stopped after checking the WordPress version on disk. Serve upgraded single-site installations with PHP's built-in server and verify the front end, REST API, database upgrade page, 404 handling, login, dashboard, and server log.

Disable cron and external HTTP requests during the check, and disable the runner's PHP JIT for the temporary server. Multisite remains excluded because moving a network to a temporary port requires coordinated configuration and database changes.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13355

Props adrianmoldovanwp.
See #66036.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/.github/workflows/reusable-upgrade-testing.yml

    r62742 r63447  
    5757  # - Updates the database.
    5858  # - Checks the version of WordPress after the upgrade.
     59  # - Serves the upgraded site and confirms it renders.
    5960  upgrade-tests:
    6061    name: PHP ${{ inputs.php }} with ${{ 'mariadb' == inputs.db-type && 'MariaDB' || 'MySQL' }} ${{ inputs.db-version }}${{ inputs.multisite && ' multisite' || '' }}
    … …  
    6364    runs-on: ${{ inputs.os }}
    6465    timeout-minutes: 20
     66
     67    env:
     68      WP_ADMIN_USER: admin
     69      WP_ADMIN_PASSWORD: password
    6570
    6671    services:
    … …  
    98103        run: |
    99104          wp core ${{ inputs.multisite && 'multisite-install' || 'install' }} \
    100           --url=http://localhost/ --title="Upgrade Test" --admin_user=admin \
    101           --admin_password=password --admin_email=me@example.org --skip-email
     105          --url=http://localhost/ --title="Upgrade Test" --admin_user="${WP_ADMIN_USER}" \
     106          --admin_password="${WP_ADMIN_PASSWORD}" --admin_email=me@example.org --skip-email
    102107
    103108      - name: Pre-upgrade version check
    … …  
    136141      - name: Post-upgrade version check
    137142        run: wp core version
     143
     144      - name: Post-upgrade smoke check
     145        # A network's domain lives in wp-config.php and the database, not just an option.
     146        if: ${{ ! inputs.multisite }}
     147        run: |
     148          site_url="http://127.0.0.1:${SITE_PORT}"
     149          server_log="${RUNNER_TEMP}/server.log"
     150          jar="${RUNNER_TEMP}/cookies.txt"
     151          response="${RUNNER_TEMP}/response.txt"
     152          code="${RUNNER_TEMP}/http-code.txt"
     153          http_code=''
     154
     155          # Nothing undoes these, so this step stays last.
     156          wp option update home "${site_url}"
     157          wp option update siteurl "${site_url}"
     158          # Both make requests no check asked for, and the update checks call api.wordpress.org.
     159          wp config set DISABLE_WP_CRON true --raw
     160          wp config set WP_HTTP_BLOCK_EXTERNAL true --raw
     161
     162          # opcache counts php -S as a web SAPI, so the runner's JIT runs here and segfaults.
     163          php -d opcache.jit=disable -S "127.0.0.1:${SITE_PORT}" -t . > "${server_log}" 2>&1 &
     164          server_pid=$!
     165
     166          stop_server() {
     167            local status=$?
     168            kill "${server_pid}" 2> /dev/null || true
     169            wait "${server_pid}" 2> /dev/null || true
     170            [ "${status}" -eq 0 ] || cat "${server_log}" || true
     171            exit "${status}"
     172          }
     173          trap stop_server EXIT
     174
     175          # No connection prints 000 and exits 7, which set -e would take as fatal.
     176          deadline=$(( SECONDS + 30 ))
     177          while :; do
     178            ready_code="$(curl --silent --max-time 5 --output /dev/null --write-out '%{http_code}' "${site_url}/" || true)"
     179            [ "${ready_code}" = '000' ] || break
     180            [ "${SECONDS}" -lt "${deadline}" ] || { echo '::error::the server never answered'; exit 1; }
     181            sleep 1
     182          done
     183
     184          fail() {
     185            echo "::error::${1}"
     186            tail -n 20 "${response}"
     187            exit 1
     188          }
     189
     190          # An HTTP error returns to the caller. No reply at all is fatal.
     191          fetch() {
     192            local path="${1}" status=0
     193            shift
     194            : > "${response}"
     195            curl --silent --show-error --max-time 30 --output "${response}" \
     196              --write-out '%{http_code}' --cookie "${jar}" --cookie-jar "${jar}" \
     197              "$@" "${site_url}${path}" > "${code}" || status=$?
     198            http_code="$(cat "${code}")"
     199            [ "${status}" -eq 0 ] || [ "${status}" -eq 22 ] \
     200              || fail "${path} got no reply and curl exited ${status}"
     201            return "${status}"
     202          }
     203
     204          check() {
     205            local path="${1}" marker status=0
     206            shift
     207            fetch "${path}" --fail-with-body || status=$?
     208            [ "${status}" -eq 0 ] || fail "${path} returned HTTP ${http_code}"
     209            for marker in "$@"; do
     210              grep -qF -e "${marker}" "${response}" || fail "${path} did not contain: ${marker}"
     211            done
     212            echo "ok  ${path}"
     213          }
     214
     215          version="$(wp core version)"
     216
     217          # A fatal mid-page still returns 200, so every check also asks for the closing tag.
     218          check '/' "content=\"WordPress ${version}\"" 'Hello world!' '</html>'
     219
     220          fetch '/?rest_route=/' --fail-with-body || fail "/?rest_route=/ returned HTTP ${http_code}"
     221          jq -e '.name == "Upgrade Test"' "${response}" > /dev/null \
     222            || fail 'the REST index was not the expected JSON'
     223          echo 'ok  /?rest_route=/'
     224
     225          # It prints this for an empty database too, which the checks above rule out.
     226          check '/wp-admin/upgrade.php' 'No Update Required' '</html>'
     227
     228          fetch '/?p=99999999' || true
     229          [ "${http_code}" = '404' ] || fail "a missing post returned ${http_code}, expected 404"
     230          grep -qF '</html>' "${response}" || fail 'the 404 page was cut short'
     231          echo 'ok  404 handling'
     232
     233          login_status=0
     234          fetch '/wp-login.php' --fail-with-body \
     235            --data-urlencode "log=${WP_ADMIN_USER}" --data-urlencode "pwd=${WP_ADMIN_PASSWORD}" || login_status=$?
     236          [ "${login_status}" -eq 0 ] || fail "logging in returned HTTP ${http_code}"
     237          grep -qF 'wordpress_logged_in_' "${jar}" || fail 'logging in did not set an authentication cookie'
     238          echo 'ok  login'
     239
     240          # The admin bar renders only for a logged-in user.
     241          check '/wp-admin/' 'id="wpadminbar"' '</html>'
     242
     243          # Catches a fatal during shutdown. An empty log would let the grep pass silently.
     244          [ -s "${server_log}" ] || { echo '::error::the server wrote no log'; exit 1; }
     245          if grep -qE 'Fatal error|Uncaught|Segmentation fault' "${server_log}"; then
     246            echo '::error::the server logged a fatal error'
     247            exit 1
     248          fi
     249          echo 'ok  server log'
     250        env:
     251          SITE_PORT: 8889
Note: See TracChangeset for help on using the changeset viewer.