Repository navigation
Speed up setup of WordPress CI jobs #620
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| name: Prepare WordPress | ||
| description: Set up the WordPress repository. | ||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Resolve WordPress cache key | ||
| id: wordpress | ||
| shell: bash | ||
| env: | ||
| # The setup script builds the "wordpress" folder and copies "db.copy" into it. | ||
| SETUP_HASH: ${{ hashFiles( 'wp-setup.sh', 'packages/plugin-sqlite-database-integration/db.copy' ) }} | ||
| run: | | ||
| version="$( sed -n 's/^WP_VERSION="\(.*\)"$/\1/p' wp-setup.sh )" | ||
| commit="$( git ls-remote --exit-code https://github.com/WordPress/wordpress-develop.git "refs/heads/$version" | cut -f1 )" | ||
| echo "cache-key=wordpress-$( node --version )-$commit-$SETUP_HASH" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Restore WordPress from the cache | ||
| id: cache | ||
| uses: actions/cache/restore@v6 | ||
| with: | ||
| path: wordpress | ||
| key: ${{ steps.wordpress.outputs.cache-key }} | ||
|
|
||
| - name: Set up WordPress | ||
| if: steps.cache.outputs.cache-hit != 'true' | ||
| shell: bash | ||
| run: composer run wp-test-ensure-php-env | ||
|
|
||
| # Save now rather than using "actions/cache", which saves at the end of the job. | ||
| # Saving after the tests would also cache files they create, like the SQLite database. | ||
| - name: Save WordPress to the cache | ||
| if: steps.cache.outputs.cache-hit != 'true' | ||
| uses: actions/cache/save@v6 | ||
| with: | ||
| path: wordpress | ||
| key: ${{ steps.wordpress.outputs.cache-key }} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,13 +59,17 @@ | |
| "npm --prefix wordpress run env:cli -- plugin install gutenberg --version=22.3.0", | ||
| "npm --prefix wordpress run env:cli -- plugin install query-monitor" | ||
| ], | ||
| "wp-test-ensure-env": [ | ||
| "if [ ! -f wordpress/src/wp-load.php ]; then composer run wp-setup; fi", | ||
| "wp-test-ensure-php-env": [ | ||
| "if [ ! -f wordpress/wp-tests-config.php ]; then composer run wp-setup; fi", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| "@putenv COMPOSE_IGNORE_ORPHANS=true", | ||
| "if [ ! -f wordpress/vendor/autoload.php ]; then npm --prefix wordpress run env:composer -- update -W; fi" | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| ], | ||
| "wp-test-ensure-env": [ | ||
| "@wp-test-ensure-php-env", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| "cd wordpress && if [ -z \"$(DOTENV_CONFIG_QUIET=true node tools/local-env/scripts/docker.js ps -q)\" ]; then cd ..; composer run wp-test-start; fi" | ||
| ], | ||
| "wp-test-php": [ | ||
| "@wp-test-ensure-env @no_additional_args", | ||
| "@wp-test-ensure-php-env @no_additional_args", | ||
| "@wp-test-remove-database @no_additional_args", | ||
| "cd wordpress && node tools/local-env/scripts/docker.js run --rm php php -d zend.enable_gc=0 -d opcache.enable_cli=1 -d opcache.memory_consumption=256 -d opcache.jit=tracing -d opcache.jit_buffer_size=64M ./vendor/bin/phpunit @additional_args" | ||
| ], | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: WordPress/sqlite-database-integration
Length of output: 2074
Script executed:
Repository: WordPress/sqlite-database-integration
Length of output: 19326
Web query:
GitHub actions/cache v6 restore save cache exact key concurrent jobs cache immutable save primary keyResult:
Script executed:
Repository: WordPress/sqlite-database-integration
Length of output: 12455
Verify the cloned revision before saving the cache.
If the WordPress branch advances between key resolution and cloning, setup can save the newer revision under the earlier commit’s key. A concurrent job that retained that key can then restore and test the wrong revision. Do not save the tree unless its commit matches the key.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not changing this. The window between
git ls-remoteand the clone is about 2 seconds. Jobs that start later read the new SHA and miss this cache entry. Only jobs started in that same window could restore it, and they would get the current branch head anyway.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JanJakes Understood. The race can still produce a cache entry whose contents do not match its key, but the short window limits its practical impact. I respect your decision to leave it unchanged.
You are interacting with an AI system.