88# **Note**: When updating the beginning of the cache key, also update the cache key to match
99# the new cache key prefix. This allows us to take advantage of CircleCI's fallback caching.
1010# Read more here: https://circleci.com/docs/2.0/caching/#restoring-cache.
11- var_1 : &cache_key v1-{{ checksum ".bazelversion" }}-{{ checksum "WORKSPACE" }}-{{ checksum "yarn.lock" }}
12- # We want to invalidate the cache if the postinstall patches change. In order to apply new
13- # patches, a clean version of the node modules is needed. Additionally, we invalidate the cache
14- # if the Bazel version changes. We do this because otherwise the `bazelisk` cache folder will
15- # contain all previously used versions and ultimately cause the cache restoring to be slower.
11+ var_1 : &cache_key v1-{{ checksum ".bazelversion" }}-{{ checksum "WORKSPACE" }}
12+ # We invalidate the cache if the Bazel version changes. We do this because otherwise the `bazelisk`
13+ # cache folder will contain all previously used versions and ultimately cause the cache
14+ # restoring to be slower.
1615var_2 : &cache_fallback_key v1-{{ checksum ".bazelversion" }}-
1716
1817var_3 : &gcp_decrypt_token "angular"
@@ -27,7 +26,6 @@ var_5: &save_cache
2726 save_cache :
2827 key : *cache_key
2928 paths :
30- - " node_modules"
3129 - " ~/.cache/bazelisk"
3230 - " ~/bazel_repository_cache"
3331
@@ -114,6 +112,27 @@ jobs:
114112 - prepare_and_store_test_results
115113 - *save_cache
116114
115+ # Job that runs for PRs changing the Yarn cache directory for zero installs
116+ # https://yarnpkg.com/features/zero-installs#does-it-have-security-implications.
117+ check-yarn-cache :
118+ executor : default-executor
119+ steps :
120+ - checkout_and_rebase
121+ - run :
122+ name : Check Yarn dependency cache if modified
123+ environment :
124+ CIRCLE_GIT_BASE_REVISION : << pipeline.git.base_revision >>
125+ command : |
126+ latestShaForCacheDir=$(git log -1 --format=format:%H .yarn/cache/)
127+
128+ # If the cache directory SHA is already part of the base, we know that the
129+ # cache has not been modified, and can skip this rather slow security check.
130+ if git merge-base --is-ancestor $latestShaForCacheDir $CIRCLE_GIT_BASE_REVISION; then
131+ echo "Cache has not been touched. Skipping check."
132+ else
133+ yarn install --check-cache --immutable
134+ fi
135+
117136 lint :
118137 executor : default-executor
119138 steps :
@@ -165,6 +184,7 @@ workflows:
165184 jobs :
166185 - test
167186 - lint
187+ - check-yarn-cache
168188 - publish_snapshot_build :
169189 filters :
170190 branches :
0 commit comments