Skip to content

Commit f6805de

Browse files
devversionIgorMinar
authored andcommitted
build: fix circleci not restoring cache for PRs (angular#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 angular#28480
1 parent 72c3695 commit f6805de

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

.circleci/config.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
# **NOTE 2**: If you change the version of the docker images, also change the `cache_key` suffix.
1818
var_1: &default_docker_image circleci/node:10.12
1919
var_2: &browsers_docker_image circleci/node:10.12-browsers
20-
var_3: &cache_key v2-angular-{{ .Branch }}-{{ checksum "yarn.lock" }}-node-10.12
20+
# We don't want to include the current branch name in the cache key because that would prevent
21+
# PRs from being able to restore the cache since the branch names are always different for PRs.
22+
# The cache key should only consist of dynamic values that change whenever something in the
23+
# cache changes. (e.g. Yarn lock file changes --> cached "node_modules" are different).
24+
var_3: &cache_key v2-angular-{{ checksum "yarn.lock" }}-node-10.12
2125

2226
# Define common ENV vars
2327
var_4: &define_env_vars

0 commit comments

Comments
 (0)