From a697b23fd16306608338e8f0525d0234113cc93a Mon Sep 17 00:00:00 2001 From: Luca Tumedei Date: Fri, 23 Oct 2026 11:01:04 +0200 Subject: [PATCH] Build/Test Tools: Cache and retry WP-CLI downloads The install, upgrade, and performance test jobs installed WP-CLI through the setup-php `tools` input. setup-php downloads the phar with a single unauthenticated curl call, and when that returns an error it only logs "Could not setup wp-cli" and lets the step pass. The job then fails on the first `wp` command with "command not found". Bursts of these failures have broken most jobs of whole upgrade testing runs. Install WP-CLI in dedicated steps instead. The phar is cached in 6 hour windows, so jobs still pick up new WP-CLI releases without each of them downloading it. A cache miss downloads with curl retries; if that keeps failing, the previous window's phar is used with a warning, and without one the step fails, reporting the error where it happens. PHP 5.4 and 5.5 install jobs keep using WP-CLI 2.4.0. --- .github/workflows/install-testing.yml | 38 ++++++++++++++++- .../reusable-performance-test-v2.yml | 41 ++++++++++++++++++- .../workflows/reusable-upgrade-testing.yml | 38 ++++++++++++++++- 3 files changed, 114 insertions(+), 3 deletions(-) diff --git a/.github/workflows/install-testing.yml b/.github/workflows/install-testing.yml index ed0446e4e083e..ab578acf148b9 100644 --- a/.github/workflows/install-testing.yml +++ b/.github/workflows/install-testing.yml @@ -131,7 +131,43 @@ jobs: with: php-version: '${{ matrix.php }}' coverage: none - tools: ${{ contains( fromJSON('["5.4", "5.5"]'), matrix.php ) && 'wp-cli:2.4.0' || 'wp-cli' }} + + # Not installed with the setup-php `tools` input: that downloads WP-CLI in a single attempt + # and only logs an error on failure, so the job breaks later with `wp: command not found`. + # The phar is cached in 6 hour windows, so jobs keep getting new WP-CLI releases without each + # downloading it. When a new window's download fails, the previous window's phar is used instead. + - name: Get the WP-CLI cache window + id: get-wp-cli-window + run: echo "window=$(( $(/bin/date -u '+%s') / WP_CLI_CACHE_SECONDS ))" >> "$GITHUB_OUTPUT" + env: + WP_CLI_CACHE_SECONDS: 21600 # 6 hours. + + - name: Cache WP-CLI + id: cache-wp-cli + uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 + with: + path: ${{ runner.temp }}/wp-cli.phar + key: ${{ runner.os }}-wp-cli-${{ contains( fromJSON('["5.4", "5.5"]'), matrix.php ) && '2.4.0' || 'latest' }}-${{ steps.get-wp-cli-window.outputs.window }} + restore-keys: ${{ runner.os }}-wp-cli-${{ contains( fromJSON('["5.4", "5.5"]'), matrix.php ) && '2.4.0' || 'latest' }}- + + - name: Install WP-CLI + run: | + if [ "$CACHE_HIT" != 'true' ]; then + if curl --fail --silent --show-error --location --retry 5 --retry-all-errors \ + --output "${RUNNER_TEMP}/wp-cli.phar.download" "$WP_CLI_URL"; then + mv "${RUNNER_TEMP}/wp-cli.phar.download" "${RUNNER_TEMP}/wp-cli.phar" + elif [ -f "${RUNNER_TEMP}/wp-cli.phar" ]; then + echo "::warning::Could not download WP-CLI, using the previously cached version." + else + echo "::error::Could not download WP-CLI." + exit 1 + fi + fi + sudo install -m 0755 "${RUNNER_TEMP}/wp-cli.phar" /usr/local/bin/wp + wp --version + env: + CACHE_HIT: ${{ steps.cache-wp-cli.outputs.cache-hit }} + WP_CLI_URL: ${{ contains( fromJSON('["5.4", "5.5"]'), matrix.php ) && 'https://github.com/wp-cli/wp-cli/releases/download/v2.4.0/wp-cli-2.4.0.phar' || 'https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar' }} - name: Download WordPress run: wp core download --version="${WP_VERSION}" diff --git a/.github/workflows/reusable-performance-test-v2.yml b/.github/workflows/reusable-performance-test-v2.yml index 6b0e43e136c37..82c6c96ba0089 100644 --- a/.github/workflows/reusable-performance-test-v2.yml +++ b/.github/workflows/reusable-performance-test-v2.yml @@ -140,9 +140,48 @@ jobs: uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # 2.37.2 with: php-version: ${{ inputs.php-version }} - tools: wp-cli coverage: none + # Not installed with the setup-php `tools` input: that downloads WP-CLI in a single attempt + # and only logs an error on failure, so the job breaks later with `wp: command not found`. + # The phar is cached in 6 hour windows, so jobs keep getting new WP-CLI releases without each + # downloading it. When a new window's download fails, the previous window's phar is used instead. + - name: Get the WP-CLI cache window + id: get-wp-cli-window + if: ${{ inputs.subject == 'base' }} + run: echo "window=$(( $(/bin/date -u '+%s') / WP_CLI_CACHE_SECONDS ))" >> "$GITHUB_OUTPUT" + env: + WP_CLI_CACHE_SECONDS: 21600 # 6 hours. + + - name: Cache WP-CLI + id: cache-wp-cli + if: ${{ inputs.subject == 'base' }} + uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 + with: + path: ${{ runner.temp }}/wp-cli.phar + key: ${{ runner.os }}-wp-cli-latest-${{ steps.get-wp-cli-window.outputs.window }} + restore-keys: ${{ runner.os }}-wp-cli-latest- + + - name: Install WP-CLI + if: ${{ inputs.subject == 'base' }} + run: | + if [ "$CACHE_HIT" != 'true' ]; then + if curl --fail --silent --show-error --location --retry 5 --retry-all-errors \ + --output "${RUNNER_TEMP}/wp-cli.phar.download" "$WP_CLI_URL"; then + mv "${RUNNER_TEMP}/wp-cli.phar.download" "${RUNNER_TEMP}/wp-cli.phar" + elif [ -f "${RUNNER_TEMP}/wp-cli.phar" ]; then + echo "::warning::Could not download WP-CLI, using the previously cached version." + else + echo "::error::Could not download WP-CLI." + exit 1 + fi + fi + sudo install -m 0755 "${RUNNER_TEMP}/wp-cli.phar" /usr/local/bin/wp + wp --version + env: + CACHE_HIT: ${{ steps.cache-wp-cli.outputs.cache-hit }} + WP_CLI_URL: https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar + - name: Log debug information run: | npm --version diff --git a/.github/workflows/reusable-upgrade-testing.yml b/.github/workflows/reusable-upgrade-testing.yml index 95645aee79981..2231b6c8f3e8c 100644 --- a/.github/workflows/reusable-upgrade-testing.yml +++ b/.github/workflows/reusable-upgrade-testing.yml @@ -89,7 +89,43 @@ jobs: with: php-version: '${{ inputs.php }}' coverage: none - tools: wp-cli + + # Not installed with the setup-php `tools` input: that downloads WP-CLI in a single attempt + # and only logs an error on failure, so the job breaks later with `wp: command not found`. + # The phar is cached in 6 hour windows, so jobs keep getting new WP-CLI releases without each + # downloading it. When a new window's download fails, the previous window's phar is used instead. + - name: Get the WP-CLI cache window + id: get-wp-cli-window + run: echo "window=$(( $(/bin/date -u '+%s') / WP_CLI_CACHE_SECONDS ))" >> "$GITHUB_OUTPUT" + env: + WP_CLI_CACHE_SECONDS: 21600 # 6 hours. + + - name: Cache WP-CLI + id: cache-wp-cli + uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 + with: + path: ${{ runner.temp }}/wp-cli.phar + key: ${{ runner.os }}-wp-cli-latest-${{ steps.get-wp-cli-window.outputs.window }} + restore-keys: ${{ runner.os }}-wp-cli-latest- + + - name: Install WP-CLI + run: | + if [ "$CACHE_HIT" != 'true' ]; then + if curl --fail --silent --show-error --location --retry 5 --retry-all-errors \ + --output "${RUNNER_TEMP}/wp-cli.phar.download" "$WP_CLI_URL"; then + mv "${RUNNER_TEMP}/wp-cli.phar.download" "${RUNNER_TEMP}/wp-cli.phar" + elif [ -f "${RUNNER_TEMP}/wp-cli.phar" ]; then + echo "::warning::Could not download WP-CLI, using the previously cached version." + else + echo "::error::Could not download WP-CLI." + exit 1 + fi + fi + sudo install -m 0755 "${RUNNER_TEMP}/wp-cli.phar" /usr/local/bin/wp + wp --version + env: + CACHE_HIT: ${{ steps.cache-wp-cli.outputs.cache-hit }} + WP_CLI_URL: https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar - name: Download WordPress ${{ inputs.wp }} run: wp core download --version="${WP_VERSION}"