From be86f469f0f6333a04cada8d01321fa566e2b26a Mon Sep 17 00:00:00 2001 From: Lance Willett Date: Mon, 14 Sep 2026 13:32:58 -0700 Subject: [PATCH 1/2] Build/Test Tools: Limit PHPUnit for Core asset-only PRs. --- .github/workflows/phpunit-tests.yml | 86 ++++++++++++++++++++++++++--- 1 file changed, 79 insertions(+), 7 deletions(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 1e4a22bb61afc..72ea3e39782cb 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -83,6 +83,72 @@ concurrency: permissions: {} jobs: + # Reduce PR testing only when every changed file is an audited Core CSS or JS asset. + select-test-coverage: + name: Select PHPUnit coverage + runs-on: ubuntu-24.04 + permissions: + contents: read + if: | + github.repository == 'WordPress/wordpress-develop' || ( + github.event_name == 'pull_request' && ( + ! github.event.repository.private || + ! github.event.pull_request.draft || + contains( github.event.pull_request.labels.*.name, 'Draft Workflow Runs' ) + ) + ) + outputs: + assets-only: ${{ steps.select.outputs.assets-only }} + steps: + - name: Checkout the PR merge commit + if: github.event_name == 'pull_request' && ! contains( github.event.pull_request.labels.*.name, 'Full PHPUnit Matrix' ) + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + with: + fetch-depth: 2 + persist-credentials: false + show-progress: ${{ runner.debug == '1' && 'true' || 'false' }} + + - name: Select test coverage + id: select + env: + CHECK_ASSETS: ${{ github.event_name == 'pull_request' && ! contains( github.event.pull_request.labels.*.name, 'Full PHPUnit Matrix' ) }} + run: | + assets_only=false + if [[ "$CHECK_ASSETS" == 'true' ]]; then + # Compare the tested merge result with its base parent. Include both paths of a rename. + changed_files="$RUNNER_TEMP/phpunit-changed-files" + if git diff --no-renames --name-only -z HEAD^1 HEAD > "$changed_files" && [[ -s "$changed_files" ]]; then + assets_only=true + while IFS= read -r -d '' file; do + case "$file" in + src/js/*.js|src/js/*.css|src/wp-admin/css/*.css|src/wp-admin/js/*.js|src/wp-includes/css/*.css|src/wp-includes/js/*.js|src/wp-includes/js/*.css|src/wp-includes/build/*.js|src/wp-includes/build/*.css) + ;; + *) + assets_only=false + break + ;; + esac + done < "$changed_files" + fi + fi + echo "assets-only=$assets_only" >> "$GITHUB_OUTPUT" + + # One configuration keeps asset-dependent PHP tests visible on Core CSS/JS-only PRs. + test-assets: + name: Core assets + uses: ./.github/workflows/reusable-phpunit-tests-v3.yml + needs: [ select-test-coverage, prepare-gutenberg ] + permissions: + contents: read + if: needs.select-test-coverage.outputs.assets-only == 'true' + with: + php: '8.3' + db-type: 'mysql' + db-version: '8.4' + phpunit-test-groups: 'assets' + gutenberg-artifact: ${{ needs.prepare-gutenberg.result != 'skipped' }} + gutenberg-sha: ${{ needs.prepare-gutenberg.outputs.gutenberg-sha }} + # Downloads and verifies the Gutenberg build once for all PHPUnit jobs. prepare-gutenberg: name: Prepare Gutenberg Assets @@ -108,7 +174,7 @@ jobs: test-with-mysql: name: PHP ${{ matrix.php }} uses: ./.github/workflows/reusable-phpunit-tests-v3.yml - needs: prepare-gutenberg + needs: [ select-test-coverage, prepare-gutenberg ] permissions: contents: read secrets: @@ -116,6 +182,7 @@ jobs: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} WPT_REPORT_API_KEY: ${{ secrets.WPT_REPORT_API_KEY }} if: | + needs.select-test-coverage.outputs.assets-only != 'true' && startsWith( github.repository, 'WordPress/' ) && ( github.repository == 'WordPress/wordpress-develop' || ( github.event_name == 'pull_request' && ( @@ -202,13 +269,14 @@ jobs: test-with-mariadb: name: PHP ${{ matrix.php }} uses: ./.github/workflows/reusable-phpunit-tests-v3.yml - needs: prepare-gutenberg + needs: [ select-test-coverage, prepare-gutenberg ] permissions: contents: read secrets: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} WPT_REPORT_API_KEY: ${{ secrets.WPT_REPORT_API_KEY }} if: | + needs.select-test-coverage.outputs.assets-only != 'true' && startsWith( github.repository, 'WordPress/' ) && ( github.repository == 'WordPress/wordpress-develop' || ( github.event_name == 'pull_request' && ( @@ -270,13 +338,14 @@ jobs: test-innovation-releases: name: PHP ${{ matrix.php }} uses: ./.github/workflows/reusable-phpunit-tests-v3.yml - needs: prepare-gutenberg + needs: [ select-test-coverage, prepare-gutenberg ] permissions: contents: read secrets: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} WPT_REPORT_API_KEY: ${{ secrets.WPT_REPORT_API_KEY }} if: | + needs.select-test-coverage.outputs.assets-only != 'true' && startsWith( github.repository, 'WordPress/' ) && ( github.repository == 'WordPress/wordpress-develop' || ( github.event_name == 'pull_request' && ( @@ -326,13 +395,14 @@ jobs: html-api-test-groups: name: ${{ matrix.label }} uses: ./.github/workflows/reusable-phpunit-tests-v3.yml - needs: prepare-gutenberg + needs: [ select-test-coverage, prepare-gutenberg ] permissions: contents: read secrets: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} WPT_REPORT_API_KEY: ${{ secrets.WPT_REPORT_API_KEY }} if: | + needs.select-test-coverage.outputs.assets-only != 'true' && startsWith( github.repository, 'WordPress/' ) && ( github.repository == 'WordPress/wordpress-develop' || ( github.event_name == 'pull_request' && ( @@ -369,13 +439,14 @@ jobs: limited-matrix-for-forks: name: PHP ${{ matrix.php }} uses: ./.github/workflows/reusable-phpunit-tests-v3.yml - needs: prepare-gutenberg + needs: [ select-test-coverage, prepare-gutenberg ] permissions: contents: read secrets: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} WPT_REPORT_API_KEY: ${{ secrets.WPT_REPORT_API_KEY }} if: | + needs.select-test-coverage.outputs.assets-only != 'true' && ! startsWith( github.repository, 'WordPress/' ) && github.event_name == 'pull_request' && ( ! github.event.repository.private || @@ -436,10 +507,11 @@ jobs: pre-release-php-8-6: name: PHP ${{ matrix.php }} uses: ./.github/workflows/reusable-phpunit-tests-v3.yml - needs: prepare-gutenberg + needs: [ select-test-coverage, prepare-gutenberg ] permissions: contents: read if: | + needs.select-test-coverage.outputs.assets-only != 'true' && startsWith( github.repository, 'WordPress/' ) && ( github.repository == 'WordPress/wordpress-develop' || ( github.event_name == 'pull_request' && ( @@ -479,7 +551,7 @@ jobs: permissions: actions: read contents: read - needs: [ prepare-gutenberg, test-with-mysql, test-with-mariadb, test-innovation-releases, html-api-test-groups, limited-matrix-for-forks, pre-release-php-8-6 ] + needs: [ select-test-coverage, prepare-gutenberg, test-assets, test-with-mysql, test-with-mariadb, test-innovation-releases, html-api-test-groups, limited-matrix-for-forks, pre-release-php-8-6 ] if: ${{ github.repository == 'WordPress/wordpress-develop' && github.event_name != 'pull_request' && always() }} with: calling_status: ${{ contains( needs.*.result, 'cancelled' ) && 'cancelled' || contains( needs.*.result, 'failure' ) && 'failure' || 'success' }} From de8659a26cb66d3d77362e430ac5fd093fdd38ad Mon Sep 17 00:00:00 2001 From: Lance Willett Date: Wed, 16 Sep 2026 11:25:59 -0700 Subject: [PATCH 2/2] Build/Test Tools: Tighten Core asset workflow selection. Fail grouped PHPUnit runs when no tests are selected. Bound coverage selection to five minutes and log why normal coverage is retained. Allow admin color SCSS and unrelated documentation or JavaScript test files alongside audited assets, while preserving the workflow's explicit path inclusions. Remove generated-path patterns and document the single-site test-group constraint. --- .github/workflows/phpunit-tests.yml | 30 ++++++++++++++----- .../workflows/reusable-phpunit-tests-v3.yml | 2 +- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 72ea3e39782cb..5a893310fdb8d 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -83,10 +83,11 @@ concurrency: permissions: {} jobs: - # Reduce PR testing only when every changed file is an audited Core CSS or JS asset. + # Reduce PR testing only for audited Core assets and unrelated companion files. select-test-coverage: name: Select PHPUnit coverage runs-on: ubuntu-24.04 + timeout-minutes: 5 permissions: contents: read if: | @@ -118,22 +119,37 @@ jobs: # Compare the tested merge result with its base parent. Include both paths of a rename. changed_files="$RUNNER_TEMP/phpunit-changed-files" if git diff --no-renames --name-only -z HEAD^1 HEAD > "$changed_files" && [[ -s "$changed_files" ]]; then - assets_only=true while IFS= read -r -d '' file; do case "$file" in - src/js/*.js|src/js/*.css|src/wp-admin/css/*.css|src/wp-admin/js/*.js|src/wp-includes/css/*.css|src/wp-includes/js/*.js|src/wp-includes/js/*.css|src/wp-includes/build/*.js|src/wp-includes/build/*.css) + # Preserve the workflow's explicit inclusions before ignoring Markdown files. + SECURITY.md|tests/phpunit/*|tools/gutenberg/*|tools/local-env/*|tools/vendors/*|tools/webpack/*) ;; - *) - assets_only=false - break + src/js/*.js|src/js/*.css|src/wp-admin/css/*.css|src/wp-admin/css/colors/*.scss|src/wp-includes/css/*.css|src/wp-includes/build/*.js) + assets_only=true + continue + ;; + # These companion files are excluded by the workflow's path filters. + *.md|tests/qunit/*|typings/*|.eslintrc-jsdoc.js|.prettierrc.js|eslint.config.js|jsdoc.conf.json|tsconfig.json) + continue ;; esac + printf 'Running the normal PHPUnit matrix: %q is outside the audited asset paths.\n' "$file" + assets_only=false + break done < "$changed_files" + if [[ "$assets_only" == 'false' ]]; then + echo 'Reduced coverage requires an audited asset change and no other relevant changes.' + fi + else + echo 'Running the normal PHPUnit matrix: changed paths are unavailable or empty.' fi + else + echo 'Keeping the existing PHPUnit matrix for this event or the Full PHPUnit Matrix label.' fi echo "assets-only=$assets_only" >> "$GITHUB_OUTPUT" - # One configuration keeps asset-dependent PHP tests visible on Core CSS/JS-only PRs. + # One configuration keeps asset-dependent PHP tests visible on Core asset-only PRs. + # Single site only. Asset tests must not also belong to groups excluded by phpunit.xml.dist. test-assets: name: Core assets uses: ./.github/workflows/reusable-phpunit-tests-v3.yml diff --git a/.github/workflows/reusable-phpunit-tests-v3.yml b/.github/workflows/reusable-phpunit-tests-v3.yml index 6348d2a5cfbbf..9cdb2ff37403f 100644 --- a/.github/workflows/reusable-phpunit-tests-v3.yml +++ b/.github/workflows/reusable-phpunit-tests-v3.yml @@ -323,7 +323,7 @@ jobs: php ./vendor/bin/phpunit \ --verbose \ -c "${PHPUNIT_CONFIG}" \ - ${{ inputs.phpunit-test-groups && '--group "${TEST_GROUPS}"' || '' }} \ + ${{ inputs.phpunit-test-groups && '--group "${TEST_GROUPS}" --fail-on-empty-test-suite' || '' }} \ ${{ inputs.coverage-report && '--coverage-clover "wp-code-coverage-${MULTISITE_FLAG}-${GITHUB_SHA}.xml"' || '' }} env: TEST_GROUPS: ${{ inputs.phpunit-test-groups }}