Skip to content

Add caching for the /gutenberg directory#10971

Open
desrosj wants to merge 11 commits intoWordPress:trunkfrom
desrosj:add/caching-for-gutenberg
Open

Add caching for the /gutenberg directory#10971
desrosj wants to merge 11 commits intoWordPress:trunkfrom
desrosj:add/caching-for-gutenberg

Conversation

@desrosj
Copy link
Member

@desrosj desrosj commented Feb 18, 2026

This adds caching for the /gutenberg directory in GitHub Actions workflows in an attempt to avoid every single job from performing a full checkout, install, and build of the Gutenberg plugin at the pinned SHA reference.

Trac ticket: Core-64393.

Use of AI Tools

Used Claude code for the jq one liner.


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.

@desrosj desrosj self-assigned this Feb 18, 2026
@github-actions
Copy link

github-actions bot commented Feb 18, 2026

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props desrosj, westonruter, jorbin.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Refs are meant to be human readable. The value being pinned for the repository is a commit hash value (SHA). This uses the correct terminology.
@github-actions
Copy link

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@desrosj
Copy link
Member Author

desrosj commented Feb 18, 2026

Props to @westonruter for the idea to include the tools/gutenberg directory in the cache key.

with:
path: |
gutenberg
!gutenberg/node_modules/
Copy link
Member

Choose a reason for hiding this comment

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

Why is gutenberg/node_modules excluded?

Copy link
Member

Choose a reason for hiding this comment

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

I mean, wouldn't we want to cache node_modules?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm experimenting to see what the effect of caching this has on the overall time it takes to run the workflow. The setup-node action already caches npm dependencies in an optimized way, so I'm not certain that it's required to cache the node_modules directory. Just testing an assumption before committing to storing an 800MB cache key (the entire repository is limited to 10GB at any given time).

Copy link
Member

Choose a reason for hiding this comment

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

I assumed setup-node only caches the root node_modules directory, not the gutenberg/node_modules directory. But apparently it doesn't even cache the root one, per the docs:

Note: The action does not cache node_modules

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe it caches the global npm download cache which has compressed tarballs. This is mainly because the resulting node_modules folder varies for different platforms/operating systems.

My assumption is that the global cache should contain any packages installed on the runner from any package.json file. But to confirm this, we'd have to find a specific dependency found only in the Gutenberg repository and confirm it ends up in the generated cache key (deleting the key manually and then rerunning a workflow that generates a new one with debug mode will output every file included).

If that is the case, then the changes here will actually have no effect at all since the cache already includes the necessary details.

Copy link
Member Author

Choose a reason for hiding this comment

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

It looks like jest-jasmine2 is a dependency in gutenberg and is found nowhere in the dependency tree for wordpress-develop. Testing this now.

Copy link
Member Author

Choose a reason for hiding this comment

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

With some assistance from Claude, it seems you have to take the sha512 integrity value in the lock file for the package, convert it from base64 to hexadecimal. Then the first 4 digits represent the directory path, and the rest is the name. So for jest-jasmine2 it should be .npm/_cacache/content-v2/sha512/83/c2/05d0c1e40d87834adf69b1e631dc7c7c9e3cba98f9e3d1bbd7e5fd7d4172e09cbe39ba9ccb2eefc45e34bb9b89047afe7b95f9e2791427b1f1ee1e0b7f44ddde0c3c9b5e7c2fc76

I don't see that in the log output, though. So seems it's not the case.

It looks like the reusable Gutenberg build process testing workflow specifies multiple lock files for setup-node. This is probably the best option, but the problem is that the file does not exist until npm install runs. So passing gutenberg/package-lock.json will result in an error.

Any other ideas @westonruter?

Copy link
Member

Choose a reason for hiding this comment

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

Could the package-lock.json file be pulled down beforehand and written into the gutenberg directory before running npm install at the root? The raw URL for the file should be easy to construct since we have the Gutenberg hash available.

@aaronjorbin
Copy link
Member

Would it make sense to have a new reusable workflow so that the same code doesn't need to be maintained in 9 different places?

Apparently exclusions do not work for actions/cache and this is a known issue. See actions/cache#1356.

Instead, this manually removes the `node_modules` directory to see what effect that has on the cache.
Excluding this from the cache did not speed things up.
@desrosj
Copy link
Member Author

desrosj commented Feb 28, 2026

This did not really warrant the results I was hoping for. @westonruter did have one more idea, but I much prefer the solution I'm working on in #11019. The improvement there is significantly greater than what caching the gutenberg directory or the dependencies there would provide.

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