Skip to content
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

Tests: Share JavaScript build assets across PHP workflows #60428

Merged
merged 6 commits into from
Apr 3, 2024

Conversation

sirreal
Copy link
Member

@sirreal sirreal commented Apr 3, 2024

What?

Share the npm run build result across PHP unit test workflows.

Why?

I noticed that the PHP unit tests tend to be one of the slowest parts of the unit tests and that one of the slowest steps tends to be building JavaScript assets. These assets are the same across all the PHP tests so if we can build them once and reuse them it may give us a significant speed up!

How?

Instead of running npm run build on every PHP unit test run, we run it 1 time and use upload/download actions to store and retrieve the assets. The PHP unit tests depend on the build, so we shift this part of the work earlier and the use the stored result in all of the runs.

Compare the same job on this branch with the job on trunk.

The build step takes 3m 34s on trunk while the download step that replaces it on this branch takes 11s. The extra build job on this branch takes ~4:20, so we save around 3:20 x 19 PHP jobs - the additional 4:20 dedicated build job. Unless my math is off, this save 1:03:20 in total - 4:20 for the additional job. That's almost an hour of overall workflow time saved. If we compare the total time, that seems accurate. Usage on this branch reports 1:04:45 while a recent trunk build reports 2:11:50.

As a follow-up, we may be able to simplify the npm installation from the PHP jobs as well. After this change I think it's only used to run wp-env.

@sirreal sirreal marked this pull request as ready for review April 3, 2024 14:55
@sirreal sirreal requested a review from desrosj as a code owner April 3, 2024 14:55
@sirreal sirreal added [Type] Code Quality Issues or PRs that relate to code quality Developer Experience Ideas about improving block and theme developer experience labels Apr 3, 2024
Copy link

github-actions bot commented Apr 3, 2024

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.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: sirreal <[email protected]>
Co-authored-by: desrosj <[email protected]>

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

@sirreal sirreal requested a review from gziolo April 3, 2024 14:55
@sirreal sirreal changed the title Tests: Share build assets across PHP workflows Tests: Share JavaScript build assets across PHP workflows Apr 3, 2024
@sirreal
Copy link
Member Author

sirreal commented Apr 3, 2024

As a follow-up, we may be able to simplify the npm installation from the PHP jobs as well. After this change I think it's only used to run wp-env.

I explored this in #60430. It may be something we could cache beter, but just installing wp-env ends up being slower that the npm ci install with its cache.

Comment on lines 181 to 182
- name: Docker debug information
run: |
Copy link
Member Author

Choose a reason for hiding this comment

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

Why do we have docker debug separate from general debug? Shall we combine this step and the next one?

Copy link
Contributor

Choose a reason for hiding this comment

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

This logs the version of Docker installed within the runner image. The other debug steps below this one log the running containers, and then some debug detail about what's running within the containers.

I think it makes sense to keep them separate becuase they have different contexts, but don't feel strongly here.

Copy link
Member Author

Choose a reason for hiding this comment

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

My question was about the following "General debug information" immediately following, not about the other docker logging like the running containers. It seems like the docker version could be printed there and we could save a step, it's mostly printing versions and it doesn't seem like there's any reason to isolate the docker version.

It's not too important and can be done in another PR if we'd like.

Copy link
Contributor

@desrosj desrosj left a comment

Choose a reason for hiding this comment

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

I wanted to note that we did initially use this strategy in the first iteration of testing workflows for Core. But the savings noted here are much more substantial than in that approach. I've compared the latest run of this workflow for trunk and this PR, and below is the reported time usage.

Screenshot 2024-04-03 at 2 33 06 PM

It seems your math does indeed add up. I think this is worth a shot.

.github/workflows/unit-test.yml Outdated Show resolved Hide resolved
.github/workflows/unit-test.yml Outdated Show resolved Hide resolved
.github/workflows/unit-test.yml Outdated Show resolved Hide resolved
.github/workflows/unit-test.yml Show resolved Hide resolved
Co-authored-by: Jonathan Desrosiers <[email protected]>
@sirreal sirreal enabled auto-merge (squash) April 3, 2024 19:48
@sirreal sirreal merged commit 37fa917 into trunk Apr 3, 2024
57 checks passed
@sirreal sirreal deleted the try/faster-php-workflows branch April 3, 2024 20:11
@github-actions github-actions bot added this to the Gutenberg 18.2 milestone Apr 3, 2024
cbravobernal pushed a commit to garridinsi/gutenberg that referenced this pull request Apr 9, 2024
…60428)

Share the npm run build result across PHP unit test workflows.

The PHP unit tests are one of the slowest parts of the unit tests and are run 19 times for every workflow run. The longest step in the runs is building the same JavaScript assets. By building once and reusing these assets we can save a significant amount of time. Around 1 hour of total CI runner time is saved for every run of the unit-test workflow.

Co-authored-by: sirreal <[email protected]>
Co-authored-by: desrosj <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Developer Experience Ideas about improving block and theme developer experience [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants