Skip to content

Commit cb4fd45

Browse files
committed
Cache the prepared WordPress folder on CI
Installing the npm packages and building WordPress takes about 100 seconds of each WordPress CI job, and the result only changes when the WordPress branch moves or our setup changes. The cache includes Composer packages too, so that PHPUnit jobs don't depend on GitHub and Packagist being available.
1 parent 4247e59 commit cb4fd45

5 files changed

Lines changed: 44 additions & 2 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Prepare WordPress
2+
description: Set up the WordPress repository.
3+
runs:
4+
using: composite
5+
steps:
6+
- name: Resolve WordPress cache key
7+
id: wordpress
8+
shell: bash
9+
env:
10+
# The setup script builds the "wordpress" folder and copies "db.copy" into it.
11+
SETUP_HASH: ${{ hashFiles( 'wp-setup.sh', 'packages/plugin-sqlite-database-integration/db.copy' ) }}
12+
run: |
13+
version="$( sed -n 's/^WP_VERSION="\(.*\)"$/\1/p' wp-setup.sh )"
14+
commit="$( git ls-remote --exit-code https://github.com/WordPress/wordpress-develop.git "refs/heads/$version" | cut -f1 )"
15+
echo "cache-key=wordpress-$( node --version )-$commit-$SETUP_HASH" >> "$GITHUB_OUTPUT"
16+
17+
- name: Restore WordPress from the cache
18+
id: cache
19+
uses: actions/cache/restore@v6
20+
with:
21+
path: wordpress
22+
key: ${{ steps.wordpress.outputs.cache-key }}
23+
24+
- name: Set up WordPress
25+
if: steps.cache.outputs.cache-hit != 'true'
26+
shell: bash
27+
run: composer run wp-test-ensure-php-env
28+
29+
# Save now rather than using "actions/cache", which saves at the end of the job.
30+
# Saving after the tests would also cache files they create, like the SQLite database.
31+
- name: Save WordPress to the cache
32+
if: steps.cache.outputs.cache-hit != 'true'
33+
uses: actions/cache/save@v6
34+
with:
35+
path: wordpress
36+
key: ${{ steps.wordpress.outputs.cache-key }}

‎.github/workflows/end-to-end-tests.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
echo "PHP_FPM_GID=$(id -g)" >> $GITHUB_ENV
2929
3030
- name: Prepare WordPress
31-
run: composer run wp-setup
31+
uses: ./.github/actions/wordpress
3232

3333
- name: Run end-to-end tests
3434
uses: ./.github/actions/playwright

‎.github/workflows/sqlite-plugin-phpunit-tests.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ jobs:
3131
echo "PHP_FPM_UID=$(id -u)" >> $GITHUB_ENV
3232
echo "PHP_FPM_GID=$(id -g)" >> $GITHUB_ENV
3333
34+
- name: Prepare WordPress
35+
uses: ./.github/actions/wordpress
36+
3437
- name: Run SQLite plugin single-site PHPUnit tests
3538
run: composer run wp-test-sqlite-plugin-php
3639

‎.github/workflows/wp-tests-end-to-end.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
echo "PHP_FPM_GID=$(id -g)" >> $GITHUB_ENV
2929
3030
- name: Prepare WordPress
31-
run: composer run wp-setup
31+
uses: ./.github/actions/wordpress
3232

3333
- name: Run WordPress end-to-end tests
3434
uses: ./.github/actions/playwright

‎.github/workflows/wp-tests-phpunit.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,8 @@ jobs:
2727
echo "PHP_FPM_UID=$(id -u)" >> $GITHUB_ENV
2828
echo "PHP_FPM_GID=$(id -g)" >> $GITHUB_ENV
2929
30+
- name: Prepare WordPress
31+
uses: ./.github/actions/wordpress
32+
3033
- name: Run WordPress PHPUnit tests
3134
run: node .github/workflows/wp-tests-phpunit-run.js

0 commit comments

Comments
 (0)