Skip to content

Commit 434ef99

Browse files
devversionjelbourn
authored andcommitted
build: add circleci fallback caching (#15625)
Enables fallback caching within CircleCI. This means that all PRs or jobs that caused a change in the cache key still run with the most recent and closest maching cache. Meaning that we in theory never need to pull Bazel repositories or `node_modules` from scratch (unless we explicitly want to purge the cache). Same has been applied to `angular/angular` as well.
1 parent 31f753a commit 434ef99

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

.circleci/config.yml

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,70 +8,77 @@
88
# http://yaml-online-parser.appspot.com/
99

1010
var_1: &docker_image angular/ngcontainer:0.10.0
11-
var_2: &cache_key v2-ng-mat-{{ checksum "WORKSPACE" }}-{{ checksum "yarn.lock" }}-0.7.0
11+
12+
# **Note**: When updating the beginning of the cache key, also update the cache key to match
13+
# the new cache key prefix. This allows us to take advantage of CircleCI's fallback caching.
14+
# Read more here: https://circleci.com/docs/2.0/caching/#restoring-cache.
15+
var_2: &cache_key v2-ng-mat-{{ checksum "WORKSPACE" }}-{{ checksum "yarn.lock" }}
16+
var_3: &cache_fallback_key v2-ng-mat-
1217

1318
# Settings common to each job
14-
var_3: &job_defaults
19+
var_4: &job_defaults
1520
working_directory: ~/ng
1621
docker:
1722
- image: *docker_image
1823

1924
# Job step for checking out the source code from GitHub. This also ensures that the source code
2025
# is rebased on top of master.
21-
var_4: &checkout_code
26+
var_5: &checkout_code
2227
checkout:
2328
# After checkout, rebase on top of master. By default, PRs are not rebased on top of master,
2429
# which we want. See https://discuss.circleci.com/t/1662
2530
post: git pull --ff-only origin "refs/pull/${CI_PULL_REQUEST//*pull\//}/merge"
2631

2732
# Restores the cache that could be available for the current Yarn lock file. The cache usually
2833
# includes the node modules and the Bazel repository cache.
29-
var_5: &restore_cache
34+
var_6: &restore_cache
3035
restore_cache:
31-
key: *cache_key
36+
keys:
37+
- *cache_key
38+
- *cache_fallback_key
3239

3340
# Saves the cache for the current Yarn lock file. We store the node modules and the Bazel
3441
# repository cache in order to make subsequent builds faster.
35-
var_6: &save_cache
42+
var_7: &save_cache
3643
save_cache:
3744
key: *cache_key
3845
paths:
3946
- "node_modules"
4047
- "~/bazel_repository_cache"
4148

4249
# Decryption token that is used to decode the GCP credentials file in ".circleci/gcp_token".
43-
var_7: &gcp_decrypt_token "angular"
50+
var_8: &gcp_decrypt_token "angular"
4451

4552
# Job step that ensures that the node module dependencies are installed and up-to-date. We use
4653
# Yarn with the frozen lockfile option in order to make sure that lock file and package.json are
4754
# in sync. Unlike in Travis, we don't need to manually purge the node modules if stale because
4855
# CircleCI automatically discards the cache if the checksum of the lock file has changed.
49-
var_8: &yarn_install
56+
var_9: &yarn_install
5057
run: yarn install --frozen-lockfile --non-interactive
5158

5259
# Copies the Bazel config which is specifically for CircleCI to a location where Bazel picks it
5360
# up and merges it with the project-wide bazel configuration (tools/bazel.rc)
54-
var_9: &copy_bazel_config
61+
var_10: &copy_bazel_config
5562
# Set up the CircleCI specific bazel configuration.
5663
run: sudo cp ./.circleci/bazel.rc /etc/bazel.bazelrc
5764

5865
# Sets up a different Docker image that includes a moe recent Firefox version which
5966
# is needed for headless testing.
60-
var_10: &docker-firefox-image
67+
var_11: &docker-firefox-image
6168
# TODO(devversion): Temporarily use a image that includes Firefox 62 because the
6269
# ngcontainer image does include an old Firefox version that does not support headless.
6370
- image: circleci/node:11.4.0-browsers
6471

6572
# Attaches the release output which has been stored in the workspace to the current job.
6673
# https://circleci.com/docs/2.0/workflows/#using-workspaces-to-share-data-among-jobs
67-
var_11: &attach_release_output
74+
var_12: &attach_release_output
6875
attach_workspace:
6976
at: dist/
7077

7178
# Branch filter that we can specify for jobs that should only run on publish branches. This filter
7279
# is used to ensure that not all upstream branches will be published as Github builds
7380
# (e.g. revert branches, feature branches)
74-
var_12: &publish_branches_filter
81+
var_13: &publish_branches_filter
7582
branches:
7683
only:
7784
- master
@@ -85,15 +92,15 @@ var_12: &publish_branches_filter
8592
# In order to reduce duplication we use a YAML anchor that just always excludes the "_presubmit"
8693
# branch. We don't want to run Circle for the temporary "_presubmit" branch which is reserved
8794
# for the caretaker.
88-
var_13: &ignore_presubmit_branch_filter
95+
var_14: &ignore_presubmit_branch_filter
8996
branches:
9097
ignore:
9198
- "_presubmit"
9299
- "ivy-2019"
93100

94101
# Runs a script that sets up the Bazel remote execution. This will be used by jobs that run
95102
# Bazel primarily and should benefit from remote caching and execution.
96-
var_14: &setup_bazel_remote_execution
103+
var_15: &setup_bazel_remote_execution
97104
run:
98105
name: "Setup bazel RBE remote execution"
99106
command: ./scripts/circleci/bazel/setup-remote-execution.sh

0 commit comments

Comments
 (0)