From 39157070107495245b228a8c97ecb87f27517e68 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Fri, 24 Apr 2026 02:47:18 +0100 Subject: [PATCH 1/3] ci: cache tool artefacts and slim workflow steps Speeds up CI runs by caching the expensive downloads and scan results that were previously repeated on every run: Playwright browsers keyed on the installed version, wp-env WordPress/tarball downloads, the PHPCS results file, and the ESLint/Jest caches. Also collapses the separate build and test jobs in the E2E workflow into a single job (the artifact hand-off added runner provisioning without enabling parallelism), and swaps the global wp-env install in integration for an npx invocation backed by setup-node's npm cache. --- .github/workflows/e2e-tests.yml | 63 +++++++++++++------------------ .github/workflows/integration.yml | 21 +++++++++-- .github/workflows/js-tests.yml | 13 ++++++- .github/workflows/php-lint.yml | 11 +++++- .gitignore | 4 ++ 5 files changed, 71 insertions(+), 41 deletions(-) diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index 26617776..4c6d3ead 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -40,9 +40,11 @@ concurrency: cancel-in-progress: true jobs: - build: - name: Build - runs-on: ubuntu-latest + test: + name: Build and E2E Tests + # Pin to ubuntu-22.04 for Playwright compatibility + # ubuntu-latest (24.04) has library version mismatches with Playwright's WebKit dependencies + runs-on: ubuntu-22.04 permissions: contents: read @@ -85,45 +87,34 @@ jobs: echo "| custom-status-block.js | $(du -h build/custom-status-block.js | cut -f1) |" >> $GITHUB_STEP_SUMMARY echo "| calendar-react.js | $(du -h build/calendar-react.js | cut -f1) |" >> $GITHUB_STEP_SUMMARY - - name: Upload build artifacts - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 - with: - name: build-artifacts - path: build/ - retention-days: 1 - - test: - name: E2E Tests - # Pin to ubuntu-22.04 for Playwright compatibility - # ubuntu-latest (24.04) has library version mismatches with Playwright's WebKit dependencies - runs-on: ubuntu-22.04 - needs: build - permissions: - contents: read + - name: Resolve Playwright version + id: playwright-version + run: | + version=$(node -p "require('@playwright/test/package.json').version") + echo "version=${version}" >> "$GITHUB_OUTPUT" - steps: - - name: Checkout code - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + - name: Cache Playwright browsers + id: playwright-cache + uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 with: - persist-credentials: false + path: ~/.cache/ms-playwright + key: playwright-${{ runner.os }}-${{ steps.playwright-version.outputs.version }} - - name: Set up NodeJS 20 - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 - with: - node-version: '20' - cache: npm + - name: Install Playwright browsers and system dependencies + if: steps.playwright-cache.outputs.cache-hit != 'true' + run: npx playwright install --with-deps chromium - - name: Install dependencies - run: npm ci + - name: Install Playwright system dependencies + if: steps.playwright-cache.outputs.cache-hit == 'true' + run: npx playwright install-deps chromium - - name: Download build artifacts - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + - name: Cache wp-env downloads + uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 with: - name: build-artifacts - path: build/ - - - name: Install Playwright browsers and system dependencies - run: npx playwright install --with-deps chromium + path: ~/wp-env + key: wp-env-${{ runner.os }}-${{ hashFiles('.wp-env.json') }} + restore-keys: | + wp-env-${{ runner.os }}- - name: Install WordPress with wp-env run: npm run wp-env start diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 75ba6e07..8bda0adf 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -52,8 +52,14 @@ jobs: with: persist-credentials: false - - name: Install wordpress environment - run: npm -g install @wordpress/env + - name: Set up NodeJS 20 + uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 + with: + node-version: '20' + cache: npm + + - name: Install npm dependencies + run: npm ci - name: Setup PHP ${{ matrix.php }} uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0 @@ -66,8 +72,17 @@ jobs: with: composer-options: --prefer-dist --no-progress + - name: Cache wp-env downloads + uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 + with: + path: ~/wp-env + key: wp-env-${{ runner.os }}-${{ matrix.wp }}-${{ matrix.php }}-${{ hashFiles('.wp-env.json') }} + restore-keys: | + wp-env-${{ runner.os }}-${{ matrix.wp }}-${{ matrix.php }}- + wp-env-${{ runner.os }}-${{ matrix.wp }}- + - name: Setup wp-env - run: wp-env start + run: npx wp-env start env: WP_ENV_CORE: WordPress/WordPress#${{ matrix.wp }} diff --git a/.github/workflows/js-tests.yml b/.github/workflows/js-tests.yml index 62616ca5..343dabb2 100644 --- a/.github/workflows/js-tests.yml +++ b/.github/workflows/js-tests.yml @@ -53,8 +53,19 @@ jobs: - name: Install dependencies run: npm ci + - name: Cache ESLint and Jest results + uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 + with: + path: | + .eslintcache + node_modules/.cache/jest + key: js-cache-${{ runner.os }}-${{ hashFiles('package-lock.json', 'jest.config.js', '.eslintrc*', 'eslint.config.*') }}-${{ github.sha }} + restore-keys: | + js-cache-${{ runner.os }}-${{ hashFiles('package-lock.json', 'jest.config.js', '.eslintrc*', 'eslint.config.*') }}- + js-cache-${{ runner.os }}- + - name: Run Lint JS - run: npm run lint-js + run: npm run lint-js -- --cache - name: Run Jest tests run: npm run test-jest diff --git a/.github/workflows/php-lint.yml b/.github/workflows/php-lint.yml index 6261f551..01ac88e4 100644 --- a/.github/workflows/php-lint.yml +++ b/.github/workflows/php-lint.yml @@ -49,8 +49,17 @@ jobs: with: composer-options: --prefer-dist --no-progress + - name: Cache PHPCS results + uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 + with: + path: .phpcs-cache + key: phpcs-${{ runner.os }}-${{ hashFiles('.phpcs.xml.dist', 'composer.json') }}-${{ github.sha }} + restore-keys: | + phpcs-${{ runner.os }}-${{ hashFiles('.phpcs.xml.dist', 'composer.json') }}- + phpcs-${{ runner.os }}- + - name: PHP syntax lint run: composer lint-ci | cs2pr - name: PHP coding standards - run: composer cs -- --report=checkstyle | cs2pr + run: composer cs -- --cache=.phpcs-cache --report=checkstyle | cs2pr diff --git a/.gitignore b/.gitignore index 250094d5..e29be333 100644 --- a/.gitignore +++ b/.gitignore @@ -11,5 +11,9 @@ dist/ .phpunit.cache/ artifacts/ +# Tool caches +.phpcs-cache +.eslintcache + # Local wp-env overrides .wp-env.override.json From f3f9154edfe9a3fad58ec2835f33cc5d4b185955 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Fri, 24 Apr 2026 02:51:51 +0100 Subject: [PATCH 2/3] ci: expose node_modules/.bin on PATH for composer scripts The composer test:integration scripts invoke wp-env directly, relying on it being on PATH. The previous global npm install satisfied that; switching to npx wp-env did not, since bare wp-env was still unresolved when composer ran its script. Adding node_modules/.bin to GITHUB_PATH keeps the composer scripts working without a global install or changes to composer.json. --- .github/workflows/integration.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 8bda0adf..de37285f 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -61,6 +61,9 @@ jobs: - name: Install npm dependencies run: npm ci + - name: Put local node binaries on PATH + run: echo "$GITHUB_WORKSPACE/node_modules/.bin" >> "$GITHUB_PATH" + - name: Setup PHP ${{ matrix.php }} uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0 with: From bb016fca3f173d86b94c6a0a53c97c58a09769d7 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Fri, 24 Apr 2026 03:02:48 +0100 Subject: [PATCH 3/3] ci: drop wp-env cache and npm/npx swap Two parts of the earlier speedup didn't pay off and are backed out here. The wp-env download cache broke E2E: the afterStart lifecycle script (wp plugin install query-monitor --activate) consistently failed with "The site you have requested is not installed" on fresh runs, suggesting the cache step interacts badly with wp-env's state directory on first use. Integration tests were unaffected but the cache was always the lowest-value item in the plan, so it goes from both workflows. The global-install to npx swap in integration pushed a full npm ci into the job that previously only fetched wp-env, adding around 25 seconds and pushing total runtime from ~2m20s to ~4m. Reverting to npm -g install @wordpress/env restores the original speed; the companion PATH tweak for composer scripts is no longer needed. The Playwright cache, PHPCS cache, ESLint/Jest cache, and the merged E2E build+test job remain in place. --- .github/workflows/e2e-tests.yml | 8 -------- .github/workflows/integration.yml | 24 +++--------------------- 2 files changed, 3 insertions(+), 29 deletions(-) diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index 4c6d3ead..760febd2 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -108,14 +108,6 @@ jobs: if: steps.playwright-cache.outputs.cache-hit == 'true' run: npx playwright install-deps chromium - - name: Cache wp-env downloads - uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 - with: - path: ~/wp-env - key: wp-env-${{ runner.os }}-${{ hashFiles('.wp-env.json') }} - restore-keys: | - wp-env-${{ runner.os }}- - - name: Install WordPress with wp-env run: npm run wp-env start diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index de37285f..75ba6e07 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -52,17 +52,8 @@ jobs: with: persist-credentials: false - - name: Set up NodeJS 20 - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 - with: - node-version: '20' - cache: npm - - - name: Install npm dependencies - run: npm ci - - - name: Put local node binaries on PATH - run: echo "$GITHUB_WORKSPACE/node_modules/.bin" >> "$GITHUB_PATH" + - name: Install wordpress environment + run: npm -g install @wordpress/env - name: Setup PHP ${{ matrix.php }} uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0 @@ -75,17 +66,8 @@ jobs: with: composer-options: --prefer-dist --no-progress - - name: Cache wp-env downloads - uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 - with: - path: ~/wp-env - key: wp-env-${{ runner.os }}-${{ matrix.wp }}-${{ matrix.php }}-${{ hashFiles('.wp-env.json') }} - restore-keys: | - wp-env-${{ runner.os }}-${{ matrix.wp }}-${{ matrix.php }}- - wp-env-${{ runner.os }}-${{ matrix.wp }}- - - name: Setup wp-env - run: npx wp-env start + run: wp-env start env: WP_ENV_CORE: WordPress/WordPress#${{ matrix.wp }}