From 06cb6fb6786e7abdefcff94acf7136afc2424dbb Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Sun, 9 Aug 2026 17:46:58 +0200 Subject: [PATCH 1/7] Add WP-CLI testing workflow --- .github/workflows/wp-cli-tests.yml | 205 +++++++++++++++++++++++++++++ 1 file changed, 205 insertions(+) create mode 100644 .github/workflows/wp-cli-tests.yml diff --git a/.github/workflows/wp-cli-tests.yml b/.github/workflows/wp-cli-tests.yml new file mode 100644 index 0000000000000..46395ce6cf457 --- /dev/null +++ b/.github/workflows/wp-cli-tests.yml @@ -0,0 +1,205 @@ +# Runs the WP-CLI functional test suites against a WordPress build from this repository. +# +# WP-CLI is another official WordPress project, and a change to WordPress can break its test suites. +# Today those breakages surface up to a day later, when WP-CLI runs its own tests against the nightly +# build, and WP-CLI maintainers then have to work out whether the cause is a regression in WordPress +# or a test of theirs that needs hardening. +# +# This workflow shortens that loop. It is dispatched manually, so it adds nothing to the checks that +# run on a pull request, and is meant to answer a single question: does this WordPress build break +# WP-CLI? +# +# The test suites themselves are not defined here. They come from https://github.com/wp-cli/automated-tests, +# which already knows how to run the functional tests of every bundled WP-CLI package, so that the list +# of packages stays owned by WP-CLI rather than duplicated in this repository. +name: WP-CLI Tests + +on: + workflow_dispatch: + inputs: + run-id: + description: 'The ID of a "Test Build Processes" run whose WordPress build should be tested. Leave empty to build the selected branch instead.' + type: string + php-version: + description: 'The version of PHP to test with.' + type: string + default: '8.3' + packages: + description: 'A comma separated list of the WP-CLI packages to test.' + type: string + default: 'wp-cli-bundle,config-command,core-command,cron-command,db-command,entity-command,export-command,extension-command,import-command,media-command,rewrite-command,role-command,search-replace-command,site-health-command' + +# Cancels all previous workflow runs that have not completed. +concurrency: + group: ${{ github.workflow }}-${{ inputs.run-id || github.ref }} + cancel-in-progress: true + +# Disable permissions for all available scopes by default. +# Any needed permissions should be configured at the job level. +permissions: {} + +jobs: + # Builds and packages WordPress from the selected branch. + # + # Skipped when a run ID is given, as that run already produced a build to test. + build: + name: Build + uses: ./.github/workflows/reusable-build-package.yml + permissions: + contents: read + if: ${{ inputs.run-id == '' }} + + # Turns the list of packages into a matrix. + prepare-matrix: + name: Prepare package matrix + runs-on: ubuntu-24.04 + permissions: {} + timeout-minutes: 5 + outputs: + packages: ${{ steps.packages.outputs.packages }} + + steps: + - name: Build the list of packages to test + id: packages + env: + PACKAGES: ${{ inputs.packages }} + run: | + PACKAGE_JSON="$( jq -Rc 'split(",") | map(sub("^\\s+";"") | sub("\\s+$";"")) | map(select(length > 0))' <<< "${PACKAGES}" )" + + if [ "${PACKAGE_JSON}" = '[]' ]; then + echo "::error::No packages to test." + exit 1 + fi + + echo "packages=${PACKAGE_JSON}" >> "${GITHUB_OUTPUT}" + + # Runs the functional tests of a single WP-CLI package against the WordPress build. + # + # Performs the following steps: + # - Checks out the WP-CLI test suites. + # - Sets up PHP and the extensions the test suites need. + # - Installs the test suites. + # - Sets up a MySQL server and prepares the test database. + # - Downloads the WordPress build to test. + # - Runs the functional tests of the package against that build. + test: + name: ${{ matrix.package }} + runs-on: ubuntu-24.04 + permissions: + contents: read + # Downloading the build of another workflow run requires reading that run. + actions: read + # The larger suites, such as those of `entity-command` and `wp-cli-bundle`, are slow. + timeout-minutes: 45 + needs: [ build, prepare-matrix ] + if: | + always() && + needs.prepare-matrix.result == 'success' && + ( needs.build.result == 'success' || needs.build.result == 'skipped' ) + + strategy: + fail-fast: false + matrix: + package: ${{ fromJSON( needs.prepare-matrix.outputs.packages ) }} + + env: + WP_CLI_TEST_DBROOTUSER: root + WP_CLI_TEST_DBROOTPASS: root + WP_CLI_TEST_DBNAME: wp_cli_test + WP_CLI_TEST_DBUSER: wp_cli_test + WP_CLI_TEST_DBPASS: password1 + WP_CLI_TEST_DBHOST: 127.0.0.1:3306 + + steps: + - name: Check out the WP-CLI test suites + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + with: + repository: wp-cli/automated-tests + ref: main + show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} + persist-credentials: false + + - name: Set up PHP ${{ inputs.php-version }} + uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # 2.37.2 + with: + php-version: '${{ inputs.php-version }}' + extensions: gd, imagick, mysql, zip, pdo_sqlite, exif, fileinfo + coverage: none + tools: composer + + - name: Install Ghostscript + run: | + sudo apt-get update + sudo apt-get install ghostscript -y + + - name: Change ImageMagick policy to allow pdf->png conversion + run: sudo sed -i 's/^.*policy.*coder.*none.*PDF.*//' /etc/ImageMagick-6/policy.xml + + # Installing `wp-cli/wp-cli-tests` from its main branch pulls in `WP_CLI_TEST_CORE_ZIP`, which + # is what lets the test suites install WordPress from the build instead of from WordPress.org. + # + # TODO: Drop the constraint once wp-cli/wp-cli-tests 5.2.3 is released. + - name: Install the WP-CLI test suites + env: + COMPOSER_ROOT_VERSION: dev-main + run: composer require --no-interaction --no-progress "wp-cli/wp-cli-tests:dev-main" + + - name: Set up MySQL + id: setup-mysql + uses: shogo82148/actions-setup-mysql@3dcedf762c5e82d781a9e414462785b30208e79c # v1 + with: + mysql-version: '8.0' + auto-start: true + root-password: ${{ env.WP_CLI_TEST_DBROOTPASS }} + user: ${{ env.WP_CLI_TEST_DBUSER }} + password: ${{ env.WP_CLI_TEST_DBPASS }} + my-cnf: | + default_authentication_plugin=mysql_native_password + + - name: Prepare the test database + run: composer prepare-tests + + # Without a run ID this is the ZIP built by the `build` job, which wraps WordPress in a + # `wordpress/` folder. With one it is the ZIP built for WordPress Playground, which wraps it in + # a `build/` folder instead. The test suites handle both. + - name: Download the WordPress build + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + pattern: ${{ inputs.run-id != '' && 'wordpress-build-*' || 'wordpress-develop' }} + merge-multiple: true + path: ${{ runner.temp }}/wordpress-build + run-id: ${{ inputs.run-id || github.run_id }} + github-token: ${{ github.token }} + + - name: Locate the WordPress build + id: build + run: | + ARCHIVE="$( find "${RUNNER_TEMP}/wordpress-build" -maxdepth 1 -name '*.zip' | head -n 1 )" + + if [ -z "${ARCHIVE}" ]; then + echo "::error::No WordPress archive found in the downloaded artifact." + exit 1 + fi + + echo "archive=${ARCHIVE}" >> "${GITHUB_OUTPUT}" + + - name: Check the test environment + env: + TEST_PACKAGE: 'wp-cli/${{ matrix.package }}' + WP_VERSION: trunk + WP_CLI_TEST_CORE_ZIP: ${{ steps.build.outputs.archive }} + WP_CLI_TEST_DBSOCKET: '${{ steps.setup-mysql.outputs.base-dir }}/tmp/mysql.sock' + WP_CLI_TEST_DEBUG_BEHAT_ENV: 1 + run: composer behat + + # `WP_VERSION` still decides which version specific tags, such as `@require-wp-6.9`, are + # filtered out. A development build cannot be compared against those, so it is reported as + # `trunk`, which runs every scenario. Leaving it unset would resolve it to the current release + # and silently skip the scenarios that only apply to newer versions of WordPress. + - name: Run the ${{ matrix.package }} tests + env: + TEST_PACKAGE: 'wp-cli/${{ matrix.package }}' + WP_VERSION: trunk + WP_CLI_TEST_CORE_ZIP: ${{ steps.build.outputs.archive }} + WP_CLI_TEST_DBSOCKET: '${{ steps.setup-mysql.outputs.base-dir }}/tmp/mysql.sock' + run: composer test \ No newline at end of file From 00ef4e1efb47c7a075d52b2945dceaaee4eb5a22 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 11 Aug 2026 10:50:38 +0200 Subject: [PATCH 2/7] temp test --- .github/workflows/wp-cli-tests.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/wp-cli-tests.yml b/.github/workflows/wp-cli-tests.yml index 46395ce6cf457..47f7a75277810 100644 --- a/.github/workflows/wp-cli-tests.yml +++ b/.github/workflows/wp-cli-tests.yml @@ -28,6 +28,12 @@ on: description: 'A comma separated list of the WP-CLI packages to test.' type: string default: 'wp-cli-bundle,config-command,core-command,cron-command,db-command,entity-command,export-command,extension-command,import-command,media-command,rewrite-command,role-command,search-replace-command,site-health-command' + push: + branches: + - trunk + pull_request: + branches: + - trunk # Cancels all previous workflow runs that have not completed. concurrency: From 47e37b56201b6a012b7e807b9fdcd56732d66cc0 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 11 Aug 2026 11:47:59 +0200 Subject: [PATCH 3/7] use mysql service --- .github/workflows/wp-cli-tests.yml | 45 ++++++++++++++++++------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/.github/workflows/wp-cli-tests.yml b/.github/workflows/wp-cli-tests.yml index 47f7a75277810..f75b091ff17fe 100644 --- a/.github/workflows/wp-cli-tests.yml +++ b/.github/workflows/wp-cli-tests.yml @@ -85,7 +85,7 @@ jobs: # - Checks out the WP-CLI test suites. # - Sets up PHP and the extensions the test suites need. # - Installs the test suites. - # - Sets up a MySQL server and prepares the test database. + # - Prepares the test database on the MySQL service container. # - Downloads the WordPress build to test. # - Runs the functional tests of the package against that build. test: @@ -116,7 +116,27 @@ jobs: WP_CLI_TEST_DBPASS: password1 WP_CLI_TEST_DBHOST: 127.0.0.1:3306 + services: + # Unlike the other workflows in this repository, the port is published on a fixed number rather + # than a random one, because the test framework reads the host and port from a single + # `WP_CLI_TEST_DBHOST` environment variable that several of its scripts consume. + database: + image: mysql:8.0 + ports: + - 3306:3306 + options: >- + --health-cmd="mysqladmin ping" + --health-interval="30s" + --health-timeout="10s" + --health-retries="5" + -e MYSQL_ROOT_PASSWORD="root" + steps: + # This checkout replaces the contents of the workspace, so every `composer` invocation below + # runs against wp-cli/automated-tests rather than against this repository. None of the files of + # this repository are needed here: the WordPress being tested arrives as the build downloaded + # further down. The `behat`, `prepare-tests` and `test` scripts used below are the ones defined + # by that repository. - name: Check out the WP-CLI test suites uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 with: @@ -133,10 +153,13 @@ jobs: coverage: none tools: composer - - name: Install Ghostscript + # Ghostscript is needed by the tests of `media-command`, and the MySQL client by the test + # framework itself, which shells out to it to create the test database and to detect the + # version of the database server. + - name: Install Ghostscript and the MySQL client run: | sudo apt-get update - sudo apt-get install ghostscript -y + sudo apt-get install ghostscript mysql-client -y - name: Change ImageMagick policy to allow pdf->png conversion run: sudo sed -i 's/^.*policy.*coder.*none.*PDF.*//' /etc/ImageMagick-6/policy.xml @@ -150,18 +173,6 @@ jobs: COMPOSER_ROOT_VERSION: dev-main run: composer require --no-interaction --no-progress "wp-cli/wp-cli-tests:dev-main" - - name: Set up MySQL - id: setup-mysql - uses: shogo82148/actions-setup-mysql@3dcedf762c5e82d781a9e414462785b30208e79c # v1 - with: - mysql-version: '8.0' - auto-start: true - root-password: ${{ env.WP_CLI_TEST_DBROOTPASS }} - user: ${{ env.WP_CLI_TEST_DBUSER }} - password: ${{ env.WP_CLI_TEST_DBPASS }} - my-cnf: | - default_authentication_plugin=mysql_native_password - - name: Prepare the test database run: composer prepare-tests @@ -194,7 +205,6 @@ jobs: TEST_PACKAGE: 'wp-cli/${{ matrix.package }}' WP_VERSION: trunk WP_CLI_TEST_CORE_ZIP: ${{ steps.build.outputs.archive }} - WP_CLI_TEST_DBSOCKET: '${{ steps.setup-mysql.outputs.base-dir }}/tmp/mysql.sock' WP_CLI_TEST_DEBUG_BEHAT_ENV: 1 run: composer behat @@ -207,5 +217,4 @@ jobs: TEST_PACKAGE: 'wp-cli/${{ matrix.package }}' WP_VERSION: trunk WP_CLI_TEST_CORE_ZIP: ${{ steps.build.outputs.archive }} - WP_CLI_TEST_DBSOCKET: '${{ steps.setup-mysql.outputs.base-dir }}/tmp/mysql.sock' - run: composer test \ No newline at end of file + run: composer test From 9d361dea03bc335072f524e9c2ba7f56610229b5 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 11 Aug 2026 11:55:07 +0200 Subject: [PATCH 4/7] default --- .github/workflows/wp-cli-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/wp-cli-tests.yml b/.github/workflows/wp-cli-tests.yml index f75b091ff17fe..78dc4268d04bc 100644 --- a/.github/workflows/wp-cli-tests.yml +++ b/.github/workflows/wp-cli-tests.yml @@ -23,7 +23,7 @@ on: php-version: description: 'The version of PHP to test with.' type: string - default: '8.3' + default: '8.5' packages: description: 'A comma separated list of the WP-CLI packages to test.' type: string @@ -68,7 +68,7 @@ jobs: - name: Build the list of packages to test id: packages env: - PACKAGES: ${{ inputs.packages }} + PACKAGES: ${{ inputs.packages || 'wp-cli-bundle,config-command,core-command,cron-command,db-command,entity-command,export-command,extension-command,import-command,media-command,rewrite-command,role-command,search-replace-command,site-health-command' }} run: | PACKAGE_JSON="$( jq -Rc 'split(",") | map(sub("^\\s+";"") | sub("\\s+$";"")) | map(select(length > 0))' <<< "${PACKAGES}" )" From 546161cf6fed9d6006d443cc3676bfe4b6069c31 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 27 Nov 2026 11:58:00 +0000 Subject: [PATCH 5/7] Compare WP-CLI test results against a build of trunk Some scenarios fail against any development build, for reasons unrelated to the change being tested: the build does not ship the plugins a release does, and WordPress.org knows no checksums for its version. When the tests fail, they are now run again against a build of trunk, and the job only fails for scenarios that fail against the build being tested but not against trunk. When they pass, which is the usual case, trunk is not tested at all. Also adds ability-command and ai-command to the default packages, and falls back to a default PHP version when the workflow is not dispatched manually. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01UWTd5px5bFguWCn4KndpM3 --- .github/workflows/wp-cli-tests.yml | 165 +++++++++++++++++++++++++++-- 1 file changed, 159 insertions(+), 6 deletions(-) diff --git a/.github/workflows/wp-cli-tests.yml b/.github/workflows/wp-cli-tests.yml index 78dc4268d04bc..b9d72abf96aa3 100644 --- a/.github/workflows/wp-cli-tests.yml +++ b/.github/workflows/wp-cli-tests.yml @@ -9,6 +9,11 @@ # run on a pull request, and is meant to answer a single question: does this WordPress build break # WP-CLI? # +# Some scenarios fail against any development build, for reasons that have nothing to do with the +# change being tested: the build does not ship the plugins a release does, and WordPress.org knows +# no checksums for its version. So when the tests fail, they are run again against a build of trunk, +# and only the scenarios that fail against the build being tested but not against trunk count. +# # The test suites themselves are not defined here. They come from https://github.com/wp-cli/automated-tests, # which already knows how to run the functional tests of every bundled WP-CLI package, so that the list # of packages stays owned by WP-CLI rather than duplicated in this repository. @@ -20,14 +25,17 @@ on: run-id: description: 'The ID of a "Test Build Processes" run whose WordPress build should be tested. Leave empty to build the selected branch instead.' type: string + baseline-ref: + description: 'The branch of WordPress/wordpress-develop to compare the results against.' + type: string + default: 'trunk' php-version: description: 'The version of PHP to test with.' type: string default: '8.5' packages: - description: 'A comma separated list of the WP-CLI packages to test.' + description: 'A comma separated list of the WP-CLI packages to test. Leave empty to test the default ones.' type: string - default: 'wp-cli-bundle,config-command,core-command,cron-command,db-command,entity-command,export-command,extension-command,import-command,media-command,rewrite-command,role-command,search-replace-command,site-health-command' push: branches: - trunk @@ -40,6 +48,11 @@ concurrency: group: ${{ github.workflow }}-${{ inputs.run-id || github.ref }} cancel-in-progress: true +env: + # Used when no packages are given, as is the case for every event but a manual dispatch. + DEFAULT_PACKAGES: 'wp-cli-bundle,ability-command,ai-command,config-command,core-command,cron-command,db-command,entity-command,export-command,extension-command,import-command,media-command,rewrite-command,role-command,search-replace-command,site-health-command' + DEFAULT_PHP_VERSION: '8.5' + # Disable permissions for all available scopes by default. # Any needed permissions should be configured at the job level. permissions: {} @@ -55,6 +68,48 @@ jobs: contents: read if: ${{ inputs.run-id == '' }} + # Builds and packages trunk, to compare the results against. + # + # Only used when the tests fail, but built up front and in parallel, so that comparing does not + # have to wait for a build. + build-baseline: + name: Build baseline + runs-on: ubuntu-24.04 + permissions: + contents: read + timeout-minutes: 20 + + steps: + - name: Check out ${{ inputs.baseline-ref || 'trunk' }} + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + with: + repository: WordPress/wordpress-develop + ref: ${{ inputs.baseline-ref || 'trunk' }} + show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} + persist-credentials: false + + - name: Set up Node.js + uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 + with: + node-version-file: '.nvmrc' + cache: npm + + - name: Install npm Dependencies + run: npm ci + + - name: Build WordPress + run: npm run build + + - name: Create ZIP of built files + run: mv build wordpress && zip -q -r baseline.zip wordpress/. + + - name: Upload ZIP as a GitHub Actions artifact + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: wordpress-baseline + path: baseline.zip + if-no-files-found: error + # Turns the list of packages into a matrix. prepare-matrix: name: Prepare package matrix @@ -68,7 +123,7 @@ jobs: - name: Build the list of packages to test id: packages env: - PACKAGES: ${{ inputs.packages || 'wp-cli-bundle,config-command,core-command,cron-command,db-command,entity-command,export-command,extension-command,import-command,media-command,rewrite-command,role-command,search-replace-command,site-health-command' }} + PACKAGES: ${{ inputs.packages || env.DEFAULT_PACKAGES }} run: | PACKAGE_JSON="$( jq -Rc 'split(",") | map(sub("^\\s+";"") | sub("\\s+$";"")) | map(select(length > 0))' <<< "${PACKAGES}" )" @@ -88,6 +143,7 @@ jobs: # - Prepares the test database on the MySQL service container. # - Downloads the WordPress build to test. # - Runs the functional tests of the package against that build. + # - If any fail, runs them against the baseline build as well, and compares the results. test: name: ${{ matrix.package }} runs-on: ubuntu-24.04 @@ -97,10 +153,11 @@ jobs: actions: read # The larger suites, such as those of `entity-command` and `wp-cli-bundle`, are slow. timeout-minutes: 45 - needs: [ build, prepare-matrix ] + needs: [ build, build-baseline, prepare-matrix ] if: | always() && needs.prepare-matrix.result == 'success' && + needs.build-baseline.result == 'success' && ( needs.build.result == 'success' || needs.build.result == 'skipped' ) strategy: @@ -145,10 +202,10 @@ jobs: show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} persist-credentials: false - - name: Set up PHP ${{ inputs.php-version }} + - name: Set up PHP ${{ inputs.php-version || env.DEFAULT_PHP_VERSION }} uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # 2.37.2 with: - php-version: '${{ inputs.php-version }}' + php-version: '${{ inputs.php-version || env.DEFAULT_PHP_VERSION }}' extensions: gd, imagick, mysql, zip, pdo_sqlite, exif, fileinfo coverage: none tools: composer @@ -200,6 +257,12 @@ jobs: echo "archive=${ARCHIVE}" >> "${GITHUB_OUTPUT}" + - name: Download the baseline build + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + name: wordpress-baseline + path: ${{ runner.temp }}/wordpress-baseline + - name: Check the test environment env: TEST_PACKAGE: 'wp-cli/${{ matrix.package }}' @@ -212,9 +275,99 @@ jobs: # filtered out. A development build cannot be compared against those, so it is reported as # `trunk`, which runs every scenario. Leaving it unset would resolve it to the current release # and silently skip the scenarios that only apply to newer versions of WordPress. + # + # A failure here does not fail the job by itself: whether it counts is decided by comparing + # against the baseline below. - name: Run the ${{ matrix.package }} tests + id: tests + continue-on-error: true env: TEST_PACKAGE: 'wp-cli/${{ matrix.package }}' WP_VERSION: trunk WP_CLI_TEST_CORE_ZIP: ${{ steps.build.outputs.archive }} + WP_CLI_TEST_JUNIT_DIR: ${{ runner.temp }}/junit/build run: composer test + + - name: Run the ${{ matrix.package }} tests against the baseline + if: ${{ steps.tests.outcome == 'failure' }} + continue-on-error: true + env: + TEST_PACKAGE: 'wp-cli/${{ matrix.package }}' + WP_VERSION: trunk + WP_CLI_TEST_CORE_ZIP: ${{ runner.temp }}/wordpress-baseline/baseline.zip + WP_CLI_TEST_JUNIT_DIR: ${{ runner.temp }}/junit/baseline + run: composer test + + # Reads the JUnit reports of both runs. A scenario identifies by the file and line it is + # defined on, which is stable here because both runs use the same version of WP-CLI. The rerun + # reports have the final say, so that a scenario which failed and then passed counts as flaky. + - name: Compare the results against the baseline + if: ${{ steps.tests.outcome == 'failure' }} + env: + BUILD_REPORTS: ${{ runner.temp }}/junit/build + BASELINE_REPORTS: ${{ runner.temp }}/junit/baseline + run: | + python3 -I - "${BUILD_REPORTS}" "${BASELINE_REPORTS}" <<'PY' + import glob, os, sys + import xml.etree.ElementTree as ET + + FAILED = ('failed', 'undefined') + + def load(path, into): + root = ET.parse(path).getroot() + for case in root.iter('testcase'): + key = case.get('file') + ':' + case.get('line') + into[key] = {'suite': root.get('name'), 'name': case.get('name'), 'key': key, 'status': case.get('status')} + + def read_run(directory): + scenarios, flaky, rerun = {}, set(), {} + for path in sorted(glob.glob(os.path.join(directory, '*.xml'))): + load(path, scenarios) + for path in sorted(glob.glob(os.path.join(directory, 'rerun', '*.xml'))): + load(path, rerun) + # The rerun has the final say: failing and then passing is flaky, not failing. + for key, scenario in rerun.items(): + if key in scenarios and scenarios[key]['status'] in FAILED and scenario['status'] not in FAILED: + flaky.add(key) + scenarios[key] = scenario + return scenarios, flaky + + def failing(scenarios): + return {key for key, scenario in scenarios.items() if scenario['status'] in FAILED} + + candidate, flaky = read_run(sys.argv[1]) + baseline, _ = read_run(sys.argv[2]) + + if not candidate: + print('::error::The run against the build being tested produced no results.') + sys.exit(1) + + broken = sorted(failing(candidate) - failing(baseline)) + known = sorted(failing(candidate) & failing(baseline)) + + lines = [] + if broken: + lines += ['### %d scenario(s) fail only with this build' % len(broken), '', '| Scenario | Defined in |', '| --- | --- |'] + lines += ['| %s | `%s` |' % (candidate[key]['name'], key) for key in broken] + for key in broken: + print('::error title=Fails only with this build::%s (%s)' % (candidate[key]['name'], key)) + else: + lines.append('### No new failures') + if known: + lines += ['', '%d scenario(s) also fail against the baseline build, so this build did not cause them:' % len(known), ''] + lines += ['- %s (`%s`)' % (candidate[key]['name'], key) for key in known] + if flaky: + lines += ['', '%d scenario(s) failed and then passed on the rerun, and were treated as flaky.' % len(flaky)] + + summary = '\n'.join(lines) + '\n' + print(summary) + if os.environ.get('GITHUB_STEP_SUMMARY'): + with open(os.environ['GITHUB_STEP_SUMMARY'], 'a') as handle: + handle.write(summary) + + sys.exit(1 if broken else 0) + PY + + - name: Report a clean run + if: ${{ steps.tests.outcome == 'success' }} + run: echo '### All scenarios passed' >> "${GITHUB_STEP_SUMMARY}" From 75761a80332ac0fbb35427bafea4e9a9a37d5c8a Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 27 Nov 2026 13:26:18 +0000 Subject: [PATCH 6/7] Nest the WP-CLI test jobs under a single entry Every job of the WP-CLI tests workflow was top level, so a run listed the builds, the package matrix and one job per package side by side. The jobs now live in reusable-wp-cli-tests-v1.yml, called by a single job, which nests them under one entry in the run view. The jobs themselves are unchanged. Following review, the comparison against the baseline now identifies a scenario by its file, line and name rather than its file and line alone, as Behat reports the line of a scenario's last step, which every example of a scenario outline shares; their results were collapsing into one. It also counts a scenario as failing when Behat attached a to it, which is how a failing hook such as a scenario teardown is reported while the status stays "passed". The header comment no longer claims the list of packages is owned by WP-CLI, as the default list is kept here and can be overridden. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01UWTd5pRsu8Cf9gdKvUEqTW --- .../workflows/reusable-wp-cli-tests-v1.yml | 358 ++++++++++++++++++ .github/workflows/wp-cli-tests.yml | 331 +--------------- 2 files changed, 373 insertions(+), 316 deletions(-) create mode 100644 .github/workflows/reusable-wp-cli-tests-v1.yml diff --git a/.github/workflows/reusable-wp-cli-tests-v1.yml b/.github/workflows/reusable-wp-cli-tests-v1.yml new file mode 100644 index 0000000000000..96e23e101a8dd --- /dev/null +++ b/.github/workflows/reusable-wp-cli-tests-v1.yml @@ -0,0 +1,358 @@ +## +# A reusable workflow that runs the WP-CLI functional test suites against a WordPress build. +# +# The jobs live here rather than in wp-cli-tests.yml so that the run view shows them nested under +# a single entry for that workflow's one calling job, instead of as a flat list of a dozen or more +# top-level jobs. See wp-cli-tests.yml for what the workflow is for. +## +name: WP-CLI tests + +on: + workflow_call: + inputs: + run-id: + description: 'The ID of a "Test Build Processes" run whose WordPress build should be tested. Empty to build the calling branch instead.' + type: string + default: '' + baseline-ref: + description: 'The branch of WordPress/wordpress-develop to compare the results against. Empty for trunk.' + type: string + default: '' + php-version: + description: 'The version of PHP to test with. Empty for the default.' + type: string + default: '' + packages: + description: 'A comma separated list of the WP-CLI packages to test. Empty for the default ones.' + type: string + default: '' + +env: + # Inputs are passed through from the calling workflow, where they are empty for every event but + # a manual dispatch, so the defaults are applied here rather than as input defaults. + DEFAULT_PACKAGES: 'wp-cli-bundle,ability-command,ai-command,config-command,core-command,cron-command,db-command,entity-command,export-command,extension-command,import-command,media-command,rewrite-command,role-command,search-replace-command,site-health-command' + DEFAULT_PHP_VERSION: '8.5' + +# Disable permissions for all available scopes by default. +# Any needed permissions should be configured at the job level. +permissions: {} + +jobs: + # Builds and packages WordPress from the selected branch. + # + # Skipped when a run ID is given, as that run already produced a build to test. + build: + name: Build + uses: ./.github/workflows/reusable-build-package.yml + permissions: + contents: read + if: ${{ inputs.run-id == '' }} + + # Builds and packages trunk, to compare the results against. + # + # Only used when the tests fail, but built up front and in parallel, so that comparing does not + # have to wait for a build. + build-baseline: + name: Build baseline + runs-on: ubuntu-24.04 + permissions: + contents: read + timeout-minutes: 20 + + steps: + - name: Check out ${{ inputs.baseline-ref || 'trunk' }} + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + with: + repository: WordPress/wordpress-develop + ref: ${{ inputs.baseline-ref || 'trunk' }} + show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} + persist-credentials: false + + - name: Set up Node.js + uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 + with: + node-version-file: '.nvmrc' + cache: npm + + - name: Install npm Dependencies + run: npm ci + + - name: Build WordPress + run: npm run build + + - name: Create ZIP of built files + run: mv build wordpress && zip -q -r baseline.zip wordpress/. + + - name: Upload ZIP as a GitHub Actions artifact + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: wordpress-baseline + path: baseline.zip + if-no-files-found: error + + # Turns the list of packages into a matrix. + prepare-matrix: + name: Prepare package matrix + runs-on: ubuntu-24.04 + permissions: {} + timeout-minutes: 5 + outputs: + packages: ${{ steps.packages.outputs.packages }} + + steps: + - name: Build the list of packages to test + id: packages + env: + PACKAGES: ${{ inputs.packages || env.DEFAULT_PACKAGES }} + run: | + PACKAGE_JSON="$( jq -Rc 'split(",") | map(sub("^\\s+";"") | sub("\\s+$";"")) | map(select(length > 0))' <<< "${PACKAGES}" )" + + if [ "${PACKAGE_JSON}" = '[]' ]; then + echo "::error::No packages to test." + exit 1 + fi + + echo "packages=${PACKAGE_JSON}" >> "${GITHUB_OUTPUT}" + + # Runs the functional tests of a single WP-CLI package against the WordPress build. + # + # Performs the following steps: + # - Checks out the WP-CLI test suites. + # - Sets up PHP and the extensions the test suites need. + # - Installs the test suites. + # - Prepares the test database on the MySQL service container. + # - Downloads the WordPress build to test. + # - Runs the functional tests of the package against that build. + # - If any fail, runs them against the baseline build as well, and compares the results. + test: + name: ${{ matrix.package }} + runs-on: ubuntu-24.04 + permissions: + contents: read + # Downloading the build of another workflow run requires reading that run. + actions: read + # The larger suites, such as those of `entity-command` and `wp-cli-bundle`, are slow. + timeout-minutes: 45 + needs: [ build, build-baseline, prepare-matrix ] + if: | + always() && + needs.prepare-matrix.result == 'success' && + needs.build-baseline.result == 'success' && + ( needs.build.result == 'success' || needs.build.result == 'skipped' ) + + strategy: + fail-fast: false + matrix: + package: ${{ fromJSON( needs.prepare-matrix.outputs.packages ) }} + + env: + WP_CLI_TEST_DBROOTUSER: root + WP_CLI_TEST_DBROOTPASS: root + WP_CLI_TEST_DBNAME: wp_cli_test + WP_CLI_TEST_DBUSER: wp_cli_test + WP_CLI_TEST_DBPASS: password1 + WP_CLI_TEST_DBHOST: 127.0.0.1:3306 + + services: + # Unlike the other workflows in this repository, the port is published on a fixed number rather + # than a random one, because the test framework reads the host and port from a single + # `WP_CLI_TEST_DBHOST` environment variable that several of its scripts consume. + database: + image: mysql:8.0 + ports: + - 3306:3306 + options: >- + --health-cmd="mysqladmin ping" + --health-interval="30s" + --health-timeout="10s" + --health-retries="5" + -e MYSQL_ROOT_PASSWORD="root" + + steps: + # This checkout replaces the contents of the workspace, so every `composer` invocation below + # runs against wp-cli/automated-tests rather than against this repository. None of the files of + # this repository are needed here: the WordPress being tested arrives as the build downloaded + # further down. The `behat`, `prepare-tests` and `test` scripts used below are the ones defined + # by that repository. + - name: Check out the WP-CLI test suites + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + with: + repository: wp-cli/automated-tests + ref: main + show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} + persist-credentials: false + + - name: Set up PHP ${{ inputs.php-version || env.DEFAULT_PHP_VERSION }} + uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # 2.37.2 + with: + php-version: '${{ inputs.php-version || env.DEFAULT_PHP_VERSION }}' + extensions: gd, imagick, mysql, zip, pdo_sqlite, exif, fileinfo + coverage: none + tools: composer + + # Ghostscript is needed by the tests of `media-command`, and the MySQL client by the test + # framework itself, which shells out to it to create the test database and to detect the + # version of the database server. + - name: Install Ghostscript and the MySQL client + run: | + sudo apt-get update + sudo apt-get install ghostscript mysql-client -y + + - name: Change ImageMagick policy to allow pdf->png conversion + run: sudo sed -i 's/^.*policy.*coder.*none.*PDF.*//' /etc/ImageMagick-6/policy.xml + + # Installing `wp-cli/wp-cli-tests` from its main branch pulls in `WP_CLI_TEST_CORE_ZIP`, which + # is what lets the test suites install WordPress from the build instead of from WordPress.org. + # + # TODO: Drop the constraint once wp-cli/wp-cli-tests 5.2.3 is released. + - name: Install the WP-CLI test suites + env: + COMPOSER_ROOT_VERSION: dev-main + run: composer require --no-interaction --no-progress "wp-cli/wp-cli-tests:dev-main" + + - name: Prepare the test database + run: composer prepare-tests + + # Without a run ID this is the ZIP built by the `build` job, which wraps WordPress in a + # `wordpress/` folder. With one it is the ZIP built for WordPress Playground, which wraps it in + # a `build/` folder instead. The test suites handle both. + - name: Download the WordPress build + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + pattern: ${{ inputs.run-id != '' && 'wordpress-build-*' || 'wordpress-develop' }} + merge-multiple: true + path: ${{ runner.temp }}/wordpress-build + run-id: ${{ inputs.run-id || github.run_id }} + github-token: ${{ github.token }} + + - name: Locate the WordPress build + id: build + run: | + ARCHIVE="$( find "${RUNNER_TEMP}/wordpress-build" -maxdepth 1 -name '*.zip' | head -n 1 )" + + if [ -z "${ARCHIVE}" ]; then + echo "::error::No WordPress archive found in the downloaded artifact." + exit 1 + fi + + echo "archive=${ARCHIVE}" >> "${GITHUB_OUTPUT}" + + - name: Download the baseline build + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + name: wordpress-baseline + path: ${{ runner.temp }}/wordpress-baseline + + - name: Check the test environment + env: + TEST_PACKAGE: 'wp-cli/${{ matrix.package }}' + WP_VERSION: trunk + WP_CLI_TEST_CORE_ZIP: ${{ steps.build.outputs.archive }} + WP_CLI_TEST_DEBUG_BEHAT_ENV: 1 + run: composer behat + + # `WP_VERSION` still decides which version specific tags, such as `@require-wp-6.9`, are + # filtered out. A development build cannot be compared against those, so it is reported as + # `trunk`, which runs every scenario. Leaving it unset would resolve it to the current release + # and silently skip the scenarios that only apply to newer versions of WordPress. + # + # A failure here does not fail the job by itself: whether it counts is decided by comparing + # against the baseline below. + - name: Run the ${{ matrix.package }} tests + id: tests + continue-on-error: true + env: + TEST_PACKAGE: 'wp-cli/${{ matrix.package }}' + WP_VERSION: trunk + WP_CLI_TEST_CORE_ZIP: ${{ steps.build.outputs.archive }} + WP_CLI_TEST_JUNIT_DIR: ${{ runner.temp }}/junit/build + run: composer test + + - name: Run the ${{ matrix.package }} tests against the baseline + if: ${{ steps.tests.outcome == 'failure' }} + continue-on-error: true + env: + TEST_PACKAGE: 'wp-cli/${{ matrix.package }}' + WP_VERSION: trunk + WP_CLI_TEST_CORE_ZIP: ${{ runner.temp }}/wordpress-baseline/baseline.zip + WP_CLI_TEST_JUNIT_DIR: ${{ runner.temp }}/junit/baseline + run: composer test + + # Reads the JUnit reports of both runs. Behat sets a test case's `line` to that of its last step, + # which every example of a scenario outline shares, so a scenario identifies by its file, that + # line and its name, which carries the example number. All are stable here because both runs use + # the same version of WP-CLI. A scenario fails if its status says so or if Behat attached a + # `` to it, which is how a failing hook such as a scenario teardown is reported while + # the status stays `passed`. The rerun reports have the final say, so that a scenario which + # failed and then passed counts as flaky. + - name: Compare the results against the baseline + if: ${{ steps.tests.outcome == 'failure' }} + env: + BUILD_REPORTS: ${{ runner.temp }}/junit/build + BASELINE_REPORTS: ${{ runner.temp }}/junit/baseline + run: | + python3 -I - "${BUILD_REPORTS}" "${BASELINE_REPORTS}" <<'PY' + import glob, os, sys + import xml.etree.ElementTree as ET + + FAILED = ('failed', 'undefined') + + def load(path, into): + root = ET.parse(path).getroot() + for case in root.iter('testcase'): + key = case.get('file') + ':' + case.get('line') + failed = case.get('status') in FAILED or case.find('failure') is not None + into[(key, case.get('name') or '')] = {'suite': root.get('name'), 'name': case.get('name'), 'key': key, 'failed': failed} + + def read_run(directory): + scenarios, flaky, rerun = {}, set(), {} + for path in sorted(glob.glob(os.path.join(directory, '*.xml'))): + load(path, scenarios) + for path in sorted(glob.glob(os.path.join(directory, 'rerun', '*.xml'))): + load(path, rerun) + # The rerun has the final say: failing and then passing is flaky, not failing. + for key, scenario in rerun.items(): + if key in scenarios and scenarios[key]['failed'] and not scenario['failed']: + flaky.add(key) + scenarios[key] = scenario + return scenarios, flaky + + def failing(scenarios): + return {key for key, scenario in scenarios.items() if scenario['failed']} + + candidate, flaky = read_run(sys.argv[1]) + baseline, _ = read_run(sys.argv[2]) + + if not candidate: + print('::error::The run against the build being tested produced no results.') + sys.exit(1) + + broken = sorted(failing(candidate) - failing(baseline)) + known = sorted(failing(candidate) & failing(baseline)) + + lines = [] + if broken: + lines += ['### %d scenario(s) fail only with this build' % len(broken), '', '| Scenario | Location |', '| --- | --- |'] + lines += ['| %s | `%s` |' % (candidate[key]['name'], candidate[key]['key']) for key in broken] + for key in broken: + print('::error title=Fails only with this build::%s (%s)' % (candidate[key]['name'], candidate[key]['key'])) + else: + lines.append('### No new failures') + if known: + lines += ['', '%d scenario(s) also fail against the baseline build, so this build did not cause them:' % len(known), ''] + lines += ['- %s (`%s`)' % (candidate[key]['name'], candidate[key]['key']) for key in known] + if flaky: + lines += ['', '%d scenario(s) failed and then passed on the rerun, and were treated as flaky.' % len(flaky)] + + summary = '\n'.join(lines) + '\n' + print(summary) + if os.environ.get('GITHUB_STEP_SUMMARY'): + with open(os.environ['GITHUB_STEP_SUMMARY'], 'a') as handle: + handle.write(summary) + + sys.exit(1 if broken else 0) + PY + + - name: Report a clean run + if: ${{ steps.tests.outcome == 'success' }} + run: echo '### All scenarios passed' >> "${GITHUB_STEP_SUMMARY}" diff --git a/.github/workflows/wp-cli-tests.yml b/.github/workflows/wp-cli-tests.yml index b9d72abf96aa3..eeb0c275663bc 100644 --- a/.github/workflows/wp-cli-tests.yml +++ b/.github/workflows/wp-cli-tests.yml @@ -15,8 +15,13 @@ # and only the scenarios that fail against the build being tested but not against trunk count. # # The test suites themselves are not defined here. They come from https://github.com/wp-cli/automated-tests, -# which already knows how to run the functional tests of every bundled WP-CLI package, so that the list -# of packages stays owned by WP-CLI rather than duplicated in this repository. +# which already knows how to run the functional tests of every bundled WP-CLI package, so that how to +# install and run them stays owned by WP-CLI rather than duplicated in this repository. Which of those +# packages are tested by default is a convenience list kept in reusable-wp-cli-tests-v1.yml, and can be +# overridden through the `packages` input. +# +# The jobs themselves live in reusable-wp-cli-tests-v1.yml, called by the single job below, so that +# the run view shows them nested under one entry rather than as a flat list. name: WP-CLI Tests on: @@ -48,326 +53,20 @@ concurrency: group: ${{ github.workflow }}-${{ inputs.run-id || github.ref }} cancel-in-progress: true -env: - # Used when no packages are given, as is the case for every event but a manual dispatch. - DEFAULT_PACKAGES: 'wp-cli-bundle,ability-command,ai-command,config-command,core-command,cron-command,db-command,entity-command,export-command,extension-command,import-command,media-command,rewrite-command,role-command,search-replace-command,site-health-command' - DEFAULT_PHP_VERSION: '8.5' - # Disable permissions for all available scopes by default. # Any needed permissions should be configured at the job level. permissions: {} jobs: - # Builds and packages WordPress from the selected branch. - # - # Skipped when a run ID is given, as that run already produced a build to test. - build: - name: Build - uses: ./.github/workflows/reusable-build-package.yml - permissions: - contents: read - if: ${{ inputs.run-id == '' }} - - # Builds and packages trunk, to compare the results against. - # - # Only used when the tests fail, but built up front and in parallel, so that comparing does not - # have to wait for a build. - build-baseline: - name: Build baseline - runs-on: ubuntu-24.04 - permissions: - contents: read - timeout-minutes: 20 - - steps: - - name: Check out ${{ inputs.baseline-ref || 'trunk' }} - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 - with: - repository: WordPress/wordpress-develop - ref: ${{ inputs.baseline-ref || 'trunk' }} - show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} - persist-credentials: false - - - name: Set up Node.js - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 - with: - node-version-file: '.nvmrc' - cache: npm - - - name: Install npm Dependencies - run: npm ci - - - name: Build WordPress - run: npm run build - - - name: Create ZIP of built files - run: mv build wordpress && zip -q -r baseline.zip wordpress/. - - - name: Upload ZIP as a GitHub Actions artifact - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 - with: - name: wordpress-baseline - path: baseline.zip - if-no-files-found: error - - # Turns the list of packages into a matrix. - prepare-matrix: - name: Prepare package matrix - runs-on: ubuntu-24.04 - permissions: {} - timeout-minutes: 5 - outputs: - packages: ${{ steps.packages.outputs.packages }} - - steps: - - name: Build the list of packages to test - id: packages - env: - PACKAGES: ${{ inputs.packages || env.DEFAULT_PACKAGES }} - run: | - PACKAGE_JSON="$( jq -Rc 'split(",") | map(sub("^\\s+";"") | sub("\\s+$";"")) | map(select(length > 0))' <<< "${PACKAGES}" )" - - if [ "${PACKAGE_JSON}" = '[]' ]; then - echo "::error::No packages to test." - exit 1 - fi - - echo "packages=${PACKAGE_JSON}" >> "${GITHUB_OUTPUT}" - - # Runs the functional tests of a single WP-CLI package against the WordPress build. - # - # Performs the following steps: - # - Checks out the WP-CLI test suites. - # - Sets up PHP and the extensions the test suites need. - # - Installs the test suites. - # - Prepares the test database on the MySQL service container. - # - Downloads the WordPress build to test. - # - Runs the functional tests of the package against that build. - # - If any fail, runs them against the baseline build as well, and compares the results. - test: - name: ${{ matrix.package }} - runs-on: ubuntu-24.04 + wp-cli-tests: + name: WP-CLI tests + uses: ./.github/workflows/reusable-wp-cli-tests-v1.yml permissions: contents: read # Downloading the build of another workflow run requires reading that run. actions: read - # The larger suites, such as those of `entity-command` and `wp-cli-bundle`, are slow. - timeout-minutes: 45 - needs: [ build, build-baseline, prepare-matrix ] - if: | - always() && - needs.prepare-matrix.result == 'success' && - needs.build-baseline.result == 'success' && - ( needs.build.result == 'success' || needs.build.result == 'skipped' ) - - strategy: - fail-fast: false - matrix: - package: ${{ fromJSON( needs.prepare-matrix.outputs.packages ) }} - - env: - WP_CLI_TEST_DBROOTUSER: root - WP_CLI_TEST_DBROOTPASS: root - WP_CLI_TEST_DBNAME: wp_cli_test - WP_CLI_TEST_DBUSER: wp_cli_test - WP_CLI_TEST_DBPASS: password1 - WP_CLI_TEST_DBHOST: 127.0.0.1:3306 - - services: - # Unlike the other workflows in this repository, the port is published on a fixed number rather - # than a random one, because the test framework reads the host and port from a single - # `WP_CLI_TEST_DBHOST` environment variable that several of its scripts consume. - database: - image: mysql:8.0 - ports: - - 3306:3306 - options: >- - --health-cmd="mysqladmin ping" - --health-interval="30s" - --health-timeout="10s" - --health-retries="5" - -e MYSQL_ROOT_PASSWORD="root" - - steps: - # This checkout replaces the contents of the workspace, so every `composer` invocation below - # runs against wp-cli/automated-tests rather than against this repository. None of the files of - # this repository are needed here: the WordPress being tested arrives as the build downloaded - # further down. The `behat`, `prepare-tests` and `test` scripts used below are the ones defined - # by that repository. - - name: Check out the WP-CLI test suites - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 - with: - repository: wp-cli/automated-tests - ref: main - show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} - persist-credentials: false - - - name: Set up PHP ${{ inputs.php-version || env.DEFAULT_PHP_VERSION }} - uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # 2.37.2 - with: - php-version: '${{ inputs.php-version || env.DEFAULT_PHP_VERSION }}' - extensions: gd, imagick, mysql, zip, pdo_sqlite, exif, fileinfo - coverage: none - tools: composer - - # Ghostscript is needed by the tests of `media-command`, and the MySQL client by the test - # framework itself, which shells out to it to create the test database and to detect the - # version of the database server. - - name: Install Ghostscript and the MySQL client - run: | - sudo apt-get update - sudo apt-get install ghostscript mysql-client -y - - - name: Change ImageMagick policy to allow pdf->png conversion - run: sudo sed -i 's/^.*policy.*coder.*none.*PDF.*//' /etc/ImageMagick-6/policy.xml - - # Installing `wp-cli/wp-cli-tests` from its main branch pulls in `WP_CLI_TEST_CORE_ZIP`, which - # is what lets the test suites install WordPress from the build instead of from WordPress.org. - # - # TODO: Drop the constraint once wp-cli/wp-cli-tests 5.2.3 is released. - - name: Install the WP-CLI test suites - env: - COMPOSER_ROOT_VERSION: dev-main - run: composer require --no-interaction --no-progress "wp-cli/wp-cli-tests:dev-main" - - - name: Prepare the test database - run: composer prepare-tests - - # Without a run ID this is the ZIP built by the `build` job, which wraps WordPress in a - # `wordpress/` folder. With one it is the ZIP built for WordPress Playground, which wraps it in - # a `build/` folder instead. The test suites handle both. - - name: Download the WordPress build - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 - with: - pattern: ${{ inputs.run-id != '' && 'wordpress-build-*' || 'wordpress-develop' }} - merge-multiple: true - path: ${{ runner.temp }}/wordpress-build - run-id: ${{ inputs.run-id || github.run_id }} - github-token: ${{ github.token }} - - - name: Locate the WordPress build - id: build - run: | - ARCHIVE="$( find "${RUNNER_TEMP}/wordpress-build" -maxdepth 1 -name '*.zip' | head -n 1 )" - - if [ -z "${ARCHIVE}" ]; then - echo "::error::No WordPress archive found in the downloaded artifact." - exit 1 - fi - - echo "archive=${ARCHIVE}" >> "${GITHUB_OUTPUT}" - - - name: Download the baseline build - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 - with: - name: wordpress-baseline - path: ${{ runner.temp }}/wordpress-baseline - - - name: Check the test environment - env: - TEST_PACKAGE: 'wp-cli/${{ matrix.package }}' - WP_VERSION: trunk - WP_CLI_TEST_CORE_ZIP: ${{ steps.build.outputs.archive }} - WP_CLI_TEST_DEBUG_BEHAT_ENV: 1 - run: composer behat - - # `WP_VERSION` still decides which version specific tags, such as `@require-wp-6.9`, are - # filtered out. A development build cannot be compared against those, so it is reported as - # `trunk`, which runs every scenario. Leaving it unset would resolve it to the current release - # and silently skip the scenarios that only apply to newer versions of WordPress. - # - # A failure here does not fail the job by itself: whether it counts is decided by comparing - # against the baseline below. - - name: Run the ${{ matrix.package }} tests - id: tests - continue-on-error: true - env: - TEST_PACKAGE: 'wp-cli/${{ matrix.package }}' - WP_VERSION: trunk - WP_CLI_TEST_CORE_ZIP: ${{ steps.build.outputs.archive }} - WP_CLI_TEST_JUNIT_DIR: ${{ runner.temp }}/junit/build - run: composer test - - - name: Run the ${{ matrix.package }} tests against the baseline - if: ${{ steps.tests.outcome == 'failure' }} - continue-on-error: true - env: - TEST_PACKAGE: 'wp-cli/${{ matrix.package }}' - WP_VERSION: trunk - WP_CLI_TEST_CORE_ZIP: ${{ runner.temp }}/wordpress-baseline/baseline.zip - WP_CLI_TEST_JUNIT_DIR: ${{ runner.temp }}/junit/baseline - run: composer test - - # Reads the JUnit reports of both runs. A scenario identifies by the file and line it is - # defined on, which is stable here because both runs use the same version of WP-CLI. The rerun - # reports have the final say, so that a scenario which failed and then passed counts as flaky. - - name: Compare the results against the baseline - if: ${{ steps.tests.outcome == 'failure' }} - env: - BUILD_REPORTS: ${{ runner.temp }}/junit/build - BASELINE_REPORTS: ${{ runner.temp }}/junit/baseline - run: | - python3 -I - "${BUILD_REPORTS}" "${BASELINE_REPORTS}" <<'PY' - import glob, os, sys - import xml.etree.ElementTree as ET - - FAILED = ('failed', 'undefined') - - def load(path, into): - root = ET.parse(path).getroot() - for case in root.iter('testcase'): - key = case.get('file') + ':' + case.get('line') - into[key] = {'suite': root.get('name'), 'name': case.get('name'), 'key': key, 'status': case.get('status')} - - def read_run(directory): - scenarios, flaky, rerun = {}, set(), {} - for path in sorted(glob.glob(os.path.join(directory, '*.xml'))): - load(path, scenarios) - for path in sorted(glob.glob(os.path.join(directory, 'rerun', '*.xml'))): - load(path, rerun) - # The rerun has the final say: failing and then passing is flaky, not failing. - for key, scenario in rerun.items(): - if key in scenarios and scenarios[key]['status'] in FAILED and scenario['status'] not in FAILED: - flaky.add(key) - scenarios[key] = scenario - return scenarios, flaky - - def failing(scenarios): - return {key for key, scenario in scenarios.items() if scenario['status'] in FAILED} - - candidate, flaky = read_run(sys.argv[1]) - baseline, _ = read_run(sys.argv[2]) - - if not candidate: - print('::error::The run against the build being tested produced no results.') - sys.exit(1) - - broken = sorted(failing(candidate) - failing(baseline)) - known = sorted(failing(candidate) & failing(baseline)) - - lines = [] - if broken: - lines += ['### %d scenario(s) fail only with this build' % len(broken), '', '| Scenario | Defined in |', '| --- | --- |'] - lines += ['| %s | `%s` |' % (candidate[key]['name'], key) for key in broken] - for key in broken: - print('::error title=Fails only with this build::%s (%s)' % (candidate[key]['name'], key)) - else: - lines.append('### No new failures') - if known: - lines += ['', '%d scenario(s) also fail against the baseline build, so this build did not cause them:' % len(known), ''] - lines += ['- %s (`%s`)' % (candidate[key]['name'], key) for key in known] - if flaky: - lines += ['', '%d scenario(s) failed and then passed on the rerun, and were treated as flaky.' % len(flaky)] - - summary = '\n'.join(lines) + '\n' - print(summary) - if os.environ.get('GITHUB_STEP_SUMMARY'): - with open(os.environ['GITHUB_STEP_SUMMARY'], 'a') as handle: - handle.write(summary) - - sys.exit(1 if broken else 0) - PY - - - name: Report a clean run - if: ${{ steps.tests.outcome == 'success' }} - run: echo '### All scenarios passed' >> "${GITHUB_STEP_SUMMARY}" + with: + run-id: ${{ inputs.run-id || '' }} + baseline-ref: ${{ inputs.baseline-ref || '' }} + php-version: ${{ inputs.php-version || '' }} + packages: ${{ inputs.packages || '' }} From 198c94dba22b78fc1a35b01ebea0b38525d8105a Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 27 Nov 2026 15:42:40 +0000 Subject: [PATCH 7/7] Set MYSQL_HOST and MYSQL_TCP_PORT for the WP-CLI tests config-command's SSL scenario runs the mysql client with the {MYSQL_HOST} and {MYSQL_PORT} placeholders, which wp-cli-tests fills from these variables. Without them the client fell back to the local socket and failed with ERROR 2002. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01CE81GsxUY597AdaMP1NXzk --- .github/workflows/reusable-wp-cli-tests-v1.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/reusable-wp-cli-tests-v1.yml b/.github/workflows/reusable-wp-cli-tests-v1.yml index 96e23e101a8dd..6c59f93963a78 100644 --- a/.github/workflows/reusable-wp-cli-tests-v1.yml +++ b/.github/workflows/reusable-wp-cli-tests-v1.yml @@ -152,6 +152,10 @@ jobs: WP_CLI_TEST_DBUSER: wp_cli_test WP_CLI_TEST_DBPASS: password1 WP_CLI_TEST_DBHOST: 127.0.0.1:3306 + # wp-cli-tests fills the {MYSQL_HOST} and {MYSQL_PORT} placeholders from these, for + # scenarios that call the mysql client directly. Unset, the client falls back to a local socket. + MYSQL_HOST: 127.0.0.1 + MYSQL_TCP_PORT: 3306 services: # Unlike the other workflows in this repository, the port is published on a fixed number rather