Skip to content

Try running phpunit on the GHA machine rather than a docker env. - #12760

Draft
peterwilsoncc wants to merge 16 commits into
WordPress:trunkfrom
peterwilsoncc:try/phpunit-no-docker
Draft

Try running phpunit on the GHA machine rather than a docker env.#12760
peterwilsoncc wants to merge 16 commits into
WordPress:trunkfrom
peterwilsoncc:try/phpunit-no-docker

Conversation

@peterwilsoncc

Copy link
Copy Markdown
Contributor

Trac ticket:

Use of AI Tools


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Copilot AI review requested due to automatic review settings July 30, 2026 00:20
Comment thread .github/workflows/reusable-phpunit-tests-v3.yml Fixed
--health-retries=10
--health-start-period=60s
memcached:
image: ${{ inputs.memcached && 'memcached' || 'alpine' }}
--health-retries=10
--health-start-period=60s
memcached:
image: ${{ inputs.memcached && 'memcached' || 'alpine' }}

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the reusable PHPUnit GitHub Actions workflow to run PHPUnit directly on the GitHub-hosted runner (using setup-php) instead of running tests inside the project’s Docker environment.

Changes:

  • Adds GitHub Actions service containers for MySQL/MariaDB (and memcached) to support runner-based test execution.
  • Switches PHPUnit invocations from the Docker wrapper script to direct ./vendor/bin/phpunit execution on the runner.
  • Reworks code coverage setup to install/configure PCOV directly on the runner.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +224 to +233
- name: Set up test configuration
run: |
npm run env:start

- name: Log running Docker containers
run: docker ps -a

- name: WordPress Docker container debug information
run: |
docker compose run --rm mysql "${LOCAL_DB_CMD}" --version
docker compose run --rm php php --version
docker compose run --rm php php -m
docker compose run --rm php php -i
docker compose run --rm php locale -a
env:
LOCAL_DB_CMD: ${{ env.LOCAL_DB_TYPE == 'mariadb' && contains( fromJSON('["5.5", "10.0", "10.1", "10.2", "10.3"]'), env.LOCAL_DB_VERSION ) && 'mysql' || env.LOCAL_DB_TYPE }}

- name: Install WordPress
run: npm run env:install
sed \
-e 's/youremptytestdbnamehere/wordpress_develop_tests/' \
-e 's/yourusernamehere/root/' \
-e 's/yourpasswordhere/password/' \
-e 's/localhost/127.0.0.1/' \
-e "s/'WP_TESTS_DOMAIN', 'example.org'/'WP_TESTS_DOMAIN', '${LOCAL_WP_TESTS_DOMAIN}'/" \
wp-tests-config-sample.php > wp-tests-config.php
echo "define( 'FS_METHOD', 'direct' );" >> wp-tests-config.php
Comment on lines +151 to +154
memcached:
image: ${{ inputs.memcached && 'memcached' || 'alpine' }}
ports:
- 11211:11211
Copilot AI review requested due to automatic review settings July 30, 2026 00:30

services:
mysql:
image: ${{ inputs.db-type }}:${{ inputs.db-version }}

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (2)

.github/workflows/reusable-phpunit-tests-v3.yml:160

  • The memcached service falls back to the alpine image when inputs.memcached is false. The default alpine container exits immediately (no long-running command), which can cause the job to fail because a declared service container is not running. Prefer always using the memcached image (the PHP extension can remain conditional) so the service container stays up.
      memcached:
        image: ${{ inputs.memcached && 'memcached' || 'alpine' }}
        ports:
          - 11211:11211

.github/workflows/reusable-phpunit-tests-v3.yml:203

  • setup-php enables Xdebug for every job via the extensions list. Xdebug’s default mode can significantly slow down the entire PHPUnit run and can affect runtime behavior in non-Xdebug jobs. Install/enable Xdebug only for the job variants that actually run the Xdebug test group, and keep it disabled otherwise.
        uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # 2.37.2
        with:
          php-version: '${{ inputs.php }}'
          extensions: "gd, opcache, mysqli, zip, exif, intl, mbstring, xml, xsl, imagick, xdebug${{ inputs.memcached && ', memcached' || '' }}"
          coverage: none

Comment on lines +255 to +263
pecl install --force pcov-1.0.12
PHP_INI_SCAN_DIR=$(php -r 'echo PHP_CONFIG_FILE_SCAN_DIR;')
{
echo "extension=pcov"
echo "pcov.enabled=1"
echo "pcov.directory=${GITHUB_WORKSPACE}/src"
echo "pcov.initial.files=10000"
} > "$PHP_INI_SCAN_DIR/pcov.ini"
php -m | grep -i pcov
Copilot AI review requested due to automatic review settings July 30, 2026 00:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (3)

.github/workflows/reusable-phpunit-tests-v3.yml:246

  • When inputs.memcached is enabled, this workflow installs the PHP memcached extension and starts a memcached service, but it doesn’t install the object-cache.php drop-in. Without that drop-in, WordPress won’t actually use Memcached, so the “with memcached” matrix jobs likely won’t be exercising the intended cache backend. The Docker-based local environment handles this by copying tests/phpunit/includes/object-cache.php into src/wp-content/object-cache.php when memcached is enabled.
      - name: Set up test configuration
        run: |
          sed \
            -e "s/youremptytestdbnamehere/${WP_DB_DATABASE}/" \
            -e 's/yourusernamehere/root/' \
            -e "s/yourpasswordhere/${WP_DB_PASSWORD}/" \
            -e 's/localhost/127.0.0.1/' \
            -e "s/'WP_TESTS_DOMAIN', 'example.org'/'WP_TESTS_DOMAIN', '${LOCAL_WP_TESTS_DOMAIN}'/" \
            wp-tests-config-sample.php > wp-tests-config.php
          echo "define( 'FS_METHOD', 'direct' );" >> wp-tests-config.php

.github/workflows/reusable-phpunit-tests-v3.yml:269

  • PCOV config writes to "$PHP_INI_SCAN_DIR/pcov.ini" where PHP_INI_SCAN_DIR is sourced from PHP_CONFIG_FILE_SCAN_DIR. That constant can be empty or contain multiple paths (colon-separated), which would make this write fail or target an invalid path. It’s safer to derive the scanned ini directory from php --ini and fail fast if it can’t be determined.
          pecl install --force pcov-1.0.12
          PHP_INI_SCAN_DIR=$(php -r 'echo PHP_CONFIG_FILE_SCAN_DIR;')
          {
            echo "extension=pcov"
            echo "pcov.enabled=1"
            echo "pcov.directory=${GITHUB_WORKSPACE}/src"
            echo "pcov.initial.files=10000"
          } > "$PHP_INI_SCAN_DIR/pcov.ini"

.github/workflows/reusable-phpunit-tests-v3.yml:246

  • This workflow removes the earlier Docker-based PHPUnit execution, but the final reporting path still shells out to docker compose run ... php php test-runner/report.php (later in this file). With the Docker environment no longer being pulled/started, enabling inputs.report will either fail or silently reintroduce a Docker dependency for reporting. Consider updating the reporting step to run directly on the runner’s PHP (or reintroduce the required Docker setup under the same condition).
      - name: Set up test configuration
        run: |
          sed \
            -e "s/youremptytestdbnamehere/${WP_DB_DATABASE}/" \
            -e 's/yourusernamehere/root/' \
            -e "s/yourpasswordhere/${WP_DB_PASSWORD}/" \
            -e 's/localhost/127.0.0.1/' \
            -e "s/'WP_TESTS_DOMAIN', 'example.org'/'WP_TESTS_DOMAIN', '${LOCAL_WP_TESTS_DOMAIN}'/" \
            wp-tests-config-sample.php > wp-tests-config.php
          echo "define( 'FS_METHOD', 'direct' );" >> wp-tests-config.php

Comment on lines +157 to +160
memcached:
image: ${{ inputs.memcached && 'memcached' || 'alpine' }}
ports:
- 11211:11211
Copilot AI review requested due to automatic review settings July 30, 2026 01:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

.github/workflows/reusable-phpunit-tests-v3.yml:160

  • When inputs.memcached is false, this service uses the alpine image, which typically exits immediately (no long-running process). GitHub Actions expects service containers to remain running, so this can fail the entire job even when memcached is disabled. Consider always running a real memcached service (and just omit the PHP extension/tests when disabled), or restructure the workflow to only define this service when needed.
      memcached:
        image: ${{ inputs.memcached && 'memcached' || 'alpine' }}
        ports:
          - 11211:11211

Copilot AI review requested due to automatic review settings July 30, 2026 02:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (2)

.github/workflows/reusable-phpunit-tests-v3.yml:266

  • This sed replacement for WP_TESTS_DOMAIN doesn’t match the actual line in wp-tests-config-sample.php (which is define( 'WP_TESTS_DOMAIN', 'example.org' );). As a result the tests-domain input won’t be applied and the config will always use example.org.
            -e "s/'WP_TESTS_DOMAIN', 'example.org'/'WP_TESTS_DOMAIN', '${LOCAL_WP_TESTS_DOMAIN}'/" \

.github/workflows/reusable-phpunit-tests-v3.yml:259

  • The workflow-level step list comment for this job still describes running PHPUnit inside the Docker environment (pull/start containers, env:install, etc.), but those steps have been removed in this change. Updating that comment block will help keep the workflow self-documenting and avoid confusion when debugging CI.
      - name: Set up test configuration

--health-retries=10
--health-start-period=60s
memcached:
image: ${{ inputs.memcached && 'memcached' || 'alpine' }}
Copilot AI review requested due to automatic review settings July 30, 2026 02:27

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (4)

.github/workflows/reusable-phpunit-tests-v3.yml:263

  • This workflow removes the Docker-based test environment steps, but the reporting step later in the job still runs docker compose run ... php php test-runner/report.php (see the Submit test results... step). With no env:pull / env:start equivalent remaining, that reporting path is very likely to fail on trunk runs where inputs.report is true.
      - name: Set up test configuration
        run: |
          sed \
            -e "s/youremptytestdbnamehere/${WP_DB_DATABASE}/" \
            -e 's/yourusernamehere/root/' \

.github/workflows/reusable-phpunit-tests-v3.yml:156

  • The MySQL service maps a fixed host port (3306:3306) and the generated wp-tests-config.php hard-codes 127.0.0.1 with no port. This can conflict on self-hosted runners (or any runner already using 3306). A more robust pattern used elsewhere in this repo is to expose only the container port and read the assigned host port via job.services.<service>.ports['3306'] (e.g. .github/workflows/install-testing.yml:107-136).
        ports:
          - 3306:3306
        options: >-

.github/workflows/reusable-phpunit-tests-v3.yml:196

  • actions/setup-node is now skipped when inputs.wordpress-build-artifact is set, but later steps (e.g. General debug information) still run npm --version / node --version. On runners without Node preinstalled (possible when vars.PHPUNIT_RUNNER points to a custom runner), the job can fail even though Node isn’t otherwise required when using a pre-built artifact.

Either guard the later Node/NPM usage, or keep setup-node unconditional so Node is always present.

      - name: Set up Node.js
        if: inputs.wordpress-build-artifact == ''
        uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
        with:
          node-version-file: '.nvmrc'
          cache: npm

.github/workflows/reusable-prepare-gutenberg.yml:69

  • This workflow’s job timeout is still set to 10 minutes, but it now runs npm ci plus npm run build:dev, which can exceed that on slower runners or during cache misses. If this job times out, every downstream PHPUnit job that needs the artifact will be skipped/fail.

Consider increasing the job timeout-minutes to account for the added build work.

      - name: Install npm dependencies
        run: npm ci
        env:
          PUPPETEER_SKIP_DOWNLOAD: true

      - name: Build WordPress
        run: npm run build:dev

Comment on lines +74 to +79
run: |
{ git diff --name-only HEAD; git ls-files --others --exclude-standard; } \
> /tmp/build-manifest.txt
echo "Files included in build artifact:"
cat /tmp/build-manifest.txt
tar -czf /tmp/wordpress-build.tar.gz --files-from=/tmp/build-manifest.txt
Copilot AI review requested due to automatic review settings July 30, 2026 02:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (3)

.github/workflows/reusable-phpunit-tests-v3.yml:295

  • Writing pcov.ini via shell redirection to PHP_CONFIG_FILE_SCAN_DIR can fail due to permissions (this directory is typically under /etc/php/... and root-owned). That would break coverage-report jobs.
            echo "pcov.enabled=1"
            echo "pcov.directory=${GITHUB_WORKSPACE}/src"
            echo "pcov.initial.files=10000"
          } > "$PHP_INI_SCAN_DIR/pcov.ini"
          php -m | grep -i pcov

.github/workflows/reusable-phpunit-tests-v3.yml:195

  • actions/setup-node is now skipped when inputs.wordpress-build-artifact != '', but later steps still call node/npm (e.g. the "General debug information" step). On runners without preinstalled Node (notably when vars.PHPUNIT_RUNNER points to a custom runner), this will fail even though Node is only being skipped for performance.
      - name: Set up Node.js
        if: inputs.wordpress-build-artifact == ''
        uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
        with:
          node-version-file: '.nvmrc'

.github/workflows/reusable-phpunit-tests-v3.yml:230

  • apt-get install is run without an apt-get update. On GitHub-hosted images (and especially over time), stale package indexes can cause intermittent "Unable to locate package" failures for otherwise valid packages.
      - name: Install system dependencies
        run: |
          sudo apt-get install -y --no-install-recommends ghostscript libheif1 libheif-plugin-aomenc libheif-plugin-aomdec libavif16 locales
          # Generate the locales used by WordPress tests.
          sudo locale-gen ru_RU.UTF-8 fr_FR.UTF-8 de_DE.UTF-8 es_ES.UTF-8 ja_JP.UTF-8

Copilot AI review requested due to automatic review settings July 30, 2026 02:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings July 30, 2026 02:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants