🏗 Cache node_modules/ in between CircleCI jobs #39812
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've noticed that a lot of times jobs fail because of the
Install NPM packages
step due to random network hiccups. We run this step on each CircleCI job (so a total of ~30 times per PR!) - this isn't really necessary because we can just runnpm ci
once during the init job, cache the resultingnode_modules/
directory, and restore that cache at the start of every subsequent job. For PRs that don't change package-lock.json (which is most of the human-written PRs), we can skip the installation step entirely and just restore the cache.This means that any PR that changes package-lock.json will take about 50 seconds longer to go through the initializing step, but then all PRs (whether they change package-lock.json or not) shortens every other job by about 40 seconds! That shortens the the total wall time of a CircleCI workflow in either case - woohoo!
And of course, instead of having a chance to fail in a later job during the
Install NPM packages
, this can only happen once at the beginning (faster to notice and restart the job) and then only for PRs that change package-lock.json to begin with.