豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit 2f41657

Browse files
committed
ci: add security check to ensure yarn cache is not corrupt
Adds a security check to ensure the Yarn cache is not corrupt
1 parent 18f2731 commit 2f41657

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

.circleci/config.yml

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ orbs:
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.
1615
var_2: &cache_fallback_key v1-{{ checksum ".bazelversion" }}-
1716

1817
var_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

Comments
 (0)