Skip to content

Speed up yarn installs in circle builds #19566

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

Merged
merged 1 commit into from
Aug 11, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 52 additions & 71 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,11 @@ aliases:
- &environment
TZ: /usr/share/zoneinfo/America/Los_Angeles

- &restore_yarn_cache
Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed to clarify what this is actually restoring, which is the node_modules directory now.

- &restore_node_modules
restore_cache:
name: Restore node_modules cache
keys:
- v2-node-{{ arch }}-{{ .Branch }}-{{ checksum "yarn.lock" }}
- v2-node-{{ arch }}-{{ .Branch }}-
- v2-node-{{ arch }}-
- &run_yarn
Copy link
Member Author

Choose a reason for hiding this comment

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

Removing this alias because a yarn install should only be necessary in the setup job.

run:
name: Install Packages
command: yarn --frozen-lockfile
- v2-node-{{ arch }}-{{ .Branch }}-{{ checksum "yarn.lock" }}-node-modules

- &TEST_PARALLELISM 20

Expand All @@ -30,8 +24,7 @@ aliases:
steps:
- checkout
- attach_workspace: *attach_workspace
- *restore_yarn_cache
- *run_yarn
- *restore_node_modules
- run: node ./scripts/rollup/consolidateBundleSizes.js
- run: ./scripts/circleci/pack_and_store_artifact.sh
- store_artifacts:
Expand Down Expand Up @@ -59,22 +52,37 @@ jobs:
- run:
name: Nodejs Version
command: node --version
- *restore_yarn_cache
- *run_yarn
- restore_cache:
name: Restore yarn cache
key: v2-node-{{ arch }}-{{ checksum "yarn.lock" }}-yarn
- run:
name: Install Packages
command: yarn --frozen-lockfile --cache-folder ~/.cache/yarn
- save_cache:
name: Save node_modules cache
key: v2-node-{{ arch }}-{{ .Branch }}-{{ checksum "yarn.lock" }}
# Store the yarn cache globally for all lock files with this same
# checksum. This will speed up the setup job for all PRs where the
# lockfile is the same.
name: Save yarn cache for future installs
key: v2-node-{{ arch }}-{{ checksum "yarn.lock" }}-yarn
paths:
- ~/.cache/yarn
- save_cache:
# Store node_modules for all jobs in this workflow so that they don't
# need to each run a yarn install for each job. This will speed up
# all jobs run on this branch with the same lockfile.
name: Save node_modules cache
# This cache key is per branch, a yarn install in setup is required.
key: v2-node-{{ arch }}-{{ .Branch }}-{{ checksum "yarn.lock" }}-node-modules
paths:
- 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.

We're now saving two different caches:

  • yarn: This is the global yarn node_module cache to be used only by the setup job to speed up yarn install across all jobs and PRs with the same yarn.lock. It's only restored in the setup job.
  • node_modules: Once the setup job installs a node_modules directory, we cache node_modules to use in every child job. This means that we only need to run yarn install once in the setup and never for the child jobs.

The node_modules cache key is per branch just so that it's scoped per PR. Caches in circle are global and immutable so this just prevents unexpected collisions and should not change performance.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this needs to be modified to also save nested node_modules paths, to avoid causing differences on CI when there are dependency differences between modules (e.g. like the failing tests on #21641).


yarn_lint:
docker: *docker
environment: *environment

steps:
- checkout
- *restore_yarn_cache
- *run_yarn
- *restore_node_modules
- run: node ./scripts/prettier/index
- run: node ./scripts/tasks/eslint
- run: ./scripts/circleci/check_license.sh
Expand All @@ -87,8 +95,7 @@ jobs:

steps:
- checkout
- *restore_yarn_cache
- *run_yarn
- *restore_node_modules
- run: node ./scripts/tasks/flow-ci

RELEASE_CHANNEL_stable_yarn_test:
Expand All @@ -98,8 +105,7 @@ jobs:

steps:
- checkout
- *restore_yarn_cache
- *run_yarn
- *restore_node_modules
- run: yarn test --release-channel=stable --ci

yarn_test:
Expand All @@ -108,8 +114,7 @@ jobs:
parallelism: *TEST_PARALLELISM
steps:
- checkout
- *restore_yarn_cache
- *run_yarn
- *restore_node_modules
- run: yarn test --ci

RELEASE_CHANNEL_stable_yarn_test_www:
Expand All @@ -118,8 +123,7 @@ jobs:
parallelism: *TEST_PARALLELISM
steps:
- checkout
- *restore_yarn_cache
- *run_yarn
- *restore_node_modules
- run: yarn test --release-channel=www-classic --ci

RELEASE_CHANNEL_stable_yarn_test_www_variant:
Expand All @@ -128,8 +132,7 @@ jobs:
parallelism: *TEST_PARALLELISM
steps:
- checkout
- *restore_yarn_cache
- *run_yarn
- *restore_node_modules
- run: yarn test --release-channel=www-classic --variant --ci

RELEASE_CHANNEL_stable_yarn_test_prod_www:
Expand All @@ -138,8 +141,7 @@ jobs:
parallelism: *TEST_PARALLELISM
steps:
- checkout
- *restore_yarn_cache
- *run_yarn
- *restore_node_modules
- run: yarn test --release-channel=www-classic --prod --ci

RELEASE_CHANNEL_stable_yarn_test_prod_www_variant:
Expand All @@ -148,8 +150,7 @@ jobs:
parallelism: *TEST_PARALLELISM
steps:
- checkout
- *restore_yarn_cache
- *run_yarn
- *restore_node_modules
- run: yarn test --release-channel=www-classic --prod --variant --ci

yarn_test_www:
Expand All @@ -158,8 +159,7 @@ jobs:
parallelism: *TEST_PARALLELISM
steps:
- checkout
- *restore_yarn_cache
- *run_yarn
- *restore_node_modules
- run: yarn test --release-channel=www-modern --ci

yarn_test_www_variant:
Expand All @@ -168,8 +168,7 @@ jobs:
parallelism: *TEST_PARALLELISM
steps:
- checkout
- *restore_yarn_cache
- *run_yarn
- *restore_node_modules
- run: yarn test --release-channel=www-modern --variant --ci

yarn_test_prod_www:
Expand All @@ -178,8 +177,7 @@ jobs:
parallelism: *TEST_PARALLELISM
steps:
- checkout
- *restore_yarn_cache
- *run_yarn
- *restore_node_modules
- run: yarn test --release-channel=www-modern --prod --ci

yarn_test_prod_www_variant:
Expand All @@ -188,8 +186,7 @@ jobs:
parallelism: *TEST_PARALLELISM
steps:
- checkout
- *restore_yarn_cache
- *run_yarn
- *restore_node_modules
- run: yarn test --release-channel=www-modern --prod --variant --ci

RELEASE_CHANNEL_stable_yarn_test_persistent:
Expand All @@ -199,8 +196,7 @@ jobs:

steps:
- checkout
- *restore_yarn_cache
- *run_yarn
- *restore_node_modules
- run: yarn test --release-channel=stable --persistent --ci

RELEASE_CHANNEL_stable_yarn_test_prod:
Expand All @@ -210,8 +206,7 @@ jobs:

steps:
- checkout
- *restore_yarn_cache
- *run_yarn
- *restore_node_modules
- run: yarn test --release-channel=stable --prod --ci

yarn_test_prod:
Expand All @@ -220,8 +215,7 @@ jobs:
parallelism: *TEST_PARALLELISM
steps:
- checkout
- *restore_yarn_cache
- *run_yarn
- *restore_node_modules
- run: yarn test --release-channel=experimental --prod --ci

RELEASE_CHANNEL_stable_yarn_build:
Expand All @@ -230,8 +224,7 @@ jobs:
parallelism: *TEST_PARALLELISM
steps:
- checkout
- *restore_yarn_cache
- *run_yarn
- *restore_node_modules
- run:
environment:
RELEASE_CHANNEL: stable
Expand All @@ -257,8 +250,7 @@ jobs:
parallelism: 20
steps:
- checkout
- *restore_yarn_cache
- *run_yarn
- *restore_node_modules
- run:
environment:
RELEASE_CHANNEL: experimental
Expand All @@ -285,8 +277,7 @@ jobs:
steps:
- checkout
- attach_workspace: *attach_workspace
- *restore_yarn_cache
- *run_yarn
- *restore_node_modules
- run:
environment:
RELEASE_CHANNEL: experimental
Expand All @@ -305,8 +296,7 @@ jobs:
steps:
- checkout
- attach_workspace: *attach_workspace
- *restore_yarn_cache
- *run_yarn
- *restore_node_modules
# This runs in the process_artifacts job, too, but it's faster to run
# this step in both jobs instead of running the jobs sequentially
- run: node ./scripts/rollup/consolidateBundleSizes.js
Expand All @@ -321,8 +311,7 @@ jobs:
steps:
- checkout
- attach_workspace: *attach_workspace
- *restore_yarn_cache
- *run_yarn
- *restore_node_modules
# This runs in the process_artifacts job, too, but it's faster to run
# this step in both jobs instead of running the jobs sequentially
- run: node ./scripts/rollup/consolidateBundleSizes.js
Expand All @@ -337,8 +326,7 @@ jobs:
steps:
- checkout
- attach_workspace: *attach_workspace
- *restore_yarn_cache
- *run_yarn
- *restore_node_modules
- run: yarn lint-build
- run: scripts/circleci/check_minified_errors.sh

Expand All @@ -348,8 +336,7 @@ jobs:
steps:
- checkout
- attach_workspace: *attach_workspace
- *restore_yarn_cache
- *run_yarn
- *restore_node_modules
- run:
environment:
RELEASE_CHANNEL: stable
Expand All @@ -363,8 +350,7 @@ jobs:
steps:
- checkout
- attach_workspace: *attach_workspace
- *restore_yarn_cache
- *run_yarn
- *restore_node_modules
- run: yarn test --release-channel=stable --build --ci

yarn_test_build:
Expand All @@ -374,8 +360,7 @@ jobs:
steps:
- checkout
- attach_workspace: *attach_workspace
- *restore_yarn_cache
- *run_yarn
- *restore_node_modules
- run: yarn test --release-channel=experimental --build --ci

yarn_test_build_devtools:
Expand All @@ -384,8 +369,7 @@ jobs:
steps:
- checkout
- attach_workspace: *attach_workspace
- *restore_yarn_cache
- *run_yarn
- *restore_node_modules
- run: yarn test --project=devtools --build --ci

RELEASE_CHANNEL_stable_yarn_test_dom_fixtures:
Expand All @@ -394,7 +378,7 @@ jobs:
steps:
- checkout
- attach_workspace: *attach_workspace
- *restore_yarn_cache
- *restore_node_modules
- run:
name: Run DOM fixture tests
environment:
Expand All @@ -410,8 +394,7 @@ jobs:
environment: *environment
steps:
- checkout
- *restore_yarn_cache
- *run_yarn
- *restore_node_modules
- run:
name: Run fuzz tests
command: |
Expand All @@ -425,8 +408,7 @@ jobs:
steps:
- checkout
- attach_workspace: *attach_workspace
- *restore_yarn_cache
- *run_yarn
- *restore_node_modules
- run: yarn test --release-channel=stable --build --prod --ci

yarn_test_build_prod:
Expand All @@ -436,8 +418,7 @@ jobs:
steps:
- checkout
- attach_workspace: *attach_workspace
- *restore_yarn_cache
- *run_yarn
- *restore_node_modules
- run: yarn test --release-channel=experimental --build --prod --ci

workflows:
Expand Down