build: fix circleci not restoring cache for PRs (#28480)
Currently whenever someone creates a pull request, the NPM dependencies are downloaded and installed. This is problematic because we have a lot NPM dependencies with potentially large files that would need to be downloaded (e.g. the Bazel binaries). The caches are currently not being restored because we added the `{Branch}` variable to the CircleCI cache key. Since every PR has a different branch name (e.g. `devversion/refs/heads/my-banch`), the cache keys would never match an existing cache key, and the PR would start fresh by downloading everything. We can safely remove the `{Branch}` variable from the cache key because it does not provide any value since the cached files are based on the state of the `yarn.lock` file and not based on the current branch name. This reduces our dependency on the slow and sometimes **flaky** Yarn registry. We should try to depend as few as possible on external services (e.g. see how Saucelabs flakiness can cause trouble for the caretaker; same applies to flaky Yarn installs) PR Close #28480
This commit is contained in:
parent
72c36956de
commit
f6805de8eb
|
@ -17,7 +17,11 @@
|
||||||
# **NOTE 2**: If you change the version of the docker images, also change the `cache_key` suffix.
|
# **NOTE 2**: If you change the version of the docker images, also change the `cache_key` suffix.
|
||||||
var_1: &default_docker_image circleci/node:10.12
|
var_1: &default_docker_image circleci/node:10.12
|
||||||
var_2: &browsers_docker_image circleci/node:10.12-browsers
|
var_2: &browsers_docker_image circleci/node:10.12-browsers
|
||||||
var_3: &cache_key v2-angular-{{ .Branch }}-{{ checksum "yarn.lock" }}-node-10.12
|
# We don't want to include the current branch name in the cache key because that would prevent
|
||||||
|
# PRs from being able to restore the cache since the branch names are always different for PRs.
|
||||||
|
# The cache key should only consist of dynamic values that change whenever something in the
|
||||||
|
# cache changes. (e.g. Yarn lock file changes --> cached "node_modules" are different).
|
||||||
|
var_3: &cache_key v2-angular-{{ checksum "yarn.lock" }}-node-10.12
|
||||||
|
|
||||||
# Define common ENV vars
|
# Define common ENV vars
|
||||||
var_4: &define_env_vars
|
var_4: &define_env_vars
|
||||||
|
|
Loading…
Reference in New Issue