Skip to content

Commit 06398b5

Browse files
alan-agius4vikerman
authored andcommitted
ci: improve circle ci setup (#1418)
With this change we introduce a couple of changes - Do `yarn install` and code checkout once in the setup phase - Save cache in `build-packages-dist` to ensure that we cache Bazel action outputs at the very end of our builds so that we will later get better cache hit rate - We use circle ci 2.1 features such as action executors and commands - Removed the `bazel-lint` task which was redundant - We save yarn cache to circli ci cache instead of node_modules directory - Use a cache key fallback, so to use the last cached version when a dependency is updated.
1 parent e8e8ead commit 06398b5

File tree

1 file changed

+105
-111
lines changed

1 file changed

+105
-111
lines changed

.circleci/config.yml

+105-111
Original file line numberDiff line numberDiff line change
@@ -15,98 +15,91 @@
1515
# (Using the tag in not necessary when pinning by ID, but include it anyway for documentation purposes.)
1616
# **NOTE 2**: If you change the version of the docker images, also change the `cache_key` suffix.
1717
var_1: &docker_image circleci/node:10.16-browsers@sha256:d2a96fe1cbef51257ee626b5f645e64dade3e886f00ba9cb7e8ea65b4efe8db1
18-
var_2: &cache_key v7-nguniversal-{{ checksum "yarn.lock" }}-{{ checksum "WORKSPACE" }}-node-10.16
18+
var_2: &cache_key v8-nguniversal-{{ checksum "yarn.lock" }}-{{ checksum "WORKSPACE" }}-node-10.16
19+
var_3: &cache_key_fallback v8-nguniversal-
1920

20-
# Settings common to each job
21-
var_3: &job_defaults
22-
working_directory: ~/ng
23-
docker:
24-
- image: *docker_image
25-
26-
# Job step for checking out the source code from GitHub. This also ensures that the source code
27-
# is rebased on top of master.
28-
var_4: &checkout_code
29-
checkout:
30-
# After checkout, rebase on top of master. By default, PRs are not rebased on top of master,
31-
# which we want. See https://discuss.circleci.com/t/1662
32-
post: git pull --ff-only origin "refs/pull/${CI_PULL_REQUEST//*pull\//}/merge"
33-
34-
# Restores the cache that could be available for the current Yarn lock file. The cache usually
35-
# includes the node modules and the Bazel repository cache.
36-
var_5: &restore_cache
37-
restore_cache:
38-
key: *cache_key
39-
40-
# Saves the cache for the current Yarn lock file. We store the node modules and the Bazel
41-
# repository cache in order to make subsequent builds faster.
42-
var_6: &save_cache
43-
save_cache:
44-
key: *cache_key
45-
paths:
46-
- "node_modules"
47-
- "~/bazel_repository_cache"
48-
- "~/bazel_disk_cache"
49-
50-
# Job step that ensures that the node module dependencies are installed and up-to-date. We use
51-
# Yarn with the frozen lockfile option in order to make sure that lock file and package.json are
52-
# in sync. Unlike in Travis, we don't need to manually purge the node modules if stale because
53-
# CircleCI automatically discards the cache if the checksum of the lock file has changed.
54-
var_7: &yarn_install
55-
run: yarn install --frozen-lockfile --non-interactive
56-
57-
# Copies the Bazel config which is specifically for CircleCI to a location where Bazel picks it
58-
# up and merges it with the project-wide bazel configuration (tools/bazel.rc)
59-
var_8: &copy_bazel_config
60-
# Set up the CircleCI specific bazel configuration.
61-
run: sudo cp ./.circleci/bazel.rc /etc/bazel.bazelrc
62-
63-
# Run a step to setup an environment variable.
64-
var_9: &setup_env_variables
65-
run:
66-
name: "Setup custom environment variables"
67-
command: |
68-
echo 'export CHROMEDRIVER_VERSION_ARG="--versions.chrome 75.0.3770.90"' >> $BASH_ENV # Redirect into $BASH_ENV
69-
70-
# Attaches the release output which has been stored in the workspace to the current job.
21+
# Workspace initially persisted by the `setup` job.
7122
# https://circleci.com/docs/2.0/workflows/#using-workspaces-to-share-data-among-jobs
72-
var_10: &attach_release_output
73-
attach_workspace:
74-
at: dist
23+
# https://circleci.com/blog/deep-diving-into-circleci-workspaces/
24+
var_5: &workspace_location ~/
25+
26+
version: 2.1
27+
28+
# Executor Definitions
29+
# https://circleci.com/docs/2.0/reusing-config/#authoring-reusable-executors
30+
executors:
31+
action-executor:
32+
docker:
33+
- image: *docker_image
34+
working_directory: ~/ng
35+
36+
# Command Definitions
37+
# https://circleci.com/docs/2.0/reusing-config/#authoring-reusable-commands
38+
commands:
39+
custom_attach_workspace:
40+
description: Attach workspace at a predefined location
41+
steps:
42+
- attach_workspace:
43+
at: *workspace_location
7544

76-
version: 2
45+
copy-bazel-config:
46+
description: Copy Bazel config
47+
steps:
48+
# Copies the Bazel config which is specifically for CircleCI to a location where Bazel picks it
49+
# up and merges it with the project-wide bazel configuration (tools/bazel.rc)
50+
# Set up the CircleCI specific bazel configuration.
51+
- run: sudo cp ./.circleci/bazel.rc /etc/bazel.bazelrc
7752

7853
jobs:
54+
setup:
55+
executor: action-executor
56+
steps:
57+
# After checkout, rebase on top of master. By default, PRs are not rebased on top of master,
58+
# which we want. See https://discuss.circleci.com/t/1662
59+
- checkout:
60+
post: git pull --ff-only origin "refs/pull/${CI_PULL_REQUEST//*pull\//}/merge"
61+
- restore_cache:
62+
keys:
63+
- *cache_key
64+
- *cache_key_fallback
65+
- run: yarn install --frozen-lockfile --non-interactive
66+
# Reduces ~25mb from being persisted to the workspace
67+
- run: rm -rf .git
68+
- persist_to_workspace:
69+
root: *workspace_location
70+
paths:
71+
- ng
72+
- .cache/yarn
73+
- bazel_repository_cache
74+
- bazel_disk_cache
75+
7976
build:
80-
<<: *job_defaults
77+
executor: action-executor
8178
resource_class: xlarge
8279
steps:
83-
- *checkout_code
84-
- *restore_cache
85-
- *copy_bazel_config
86-
- *yarn_install
87-
88-
- run: yarn bazel test //...
89-
90-
# Note: We want to save the cache in this job because the workspace cache also
91-
# includes the Bazel repository cache that will be updated in this job.
92-
- *save_cache
80+
- custom_attach_workspace
81+
- copy-bazel-config
82+
- run: yarn bazel test //...
83+
- persist_to_workspace:
84+
root: *workspace_location
85+
paths:
86+
- bazel_repository_cache
87+
- bazel_disk_cache
9388

9489
lint:
95-
<<: *job_defaults
90+
executor: action-executor
9691
steps:
97-
- *checkout_code
98-
- *restore_cache
99-
- *yarn_install
100-
101-
# Enforce that BUILD files are formatted. Note that this uses the version of buildifier
102-
# from the docker image above - take care that you use the same version when you run
103-
# buildifier locally on your change.
104-
- run: 'yarn bazel:format -mode=check ||
105-
(echo "BUILD files not formatted. Please run ''yarn bazel:format''" ; exit 1)'
106-
# Run the skylark linter to check our Bazel rules
107-
- run: 'yarn bazel:lint ||
108-
(echo -e "\n.bzl files have lint errors. Please run ''yarn bazel:lint-fix''"; exit 1)'
109-
- run: yarn lint
92+
- custom_attach_workspace
93+
- copy-bazel-config
94+
# Enforce that BUILD files are formatted. Note that this uses the version of buildifier
95+
# from the docker image above - take care that you use the same version when you run
96+
# buildifier locally on your change.
97+
- run: 'yarn bazel:format -mode=check ||
98+
(echo "BUILD files not formatted. Please run ''yarn bazel:format''" ; exit 1)'
99+
# Run the skylark linter to check our Bazel rules
100+
- run: 'yarn bazel:lint ||
101+
(echo -e "\n.bzl files have lint errors. Please run ''yarn bazel:lint-fix''"; exit 1)'
102+
- run: yarn lint
110103

111104
# This job exists only for backwards-compatibility with old scripts and tests
112105
# that rely on the pre-Bazel dist/modules-dist layout.
@@ -116,21 +109,22 @@ jobs:
116109
# starts.
117110
# No new jobs should depend on this one.
118111
build-packages-dist:
119-
<<: *job_defaults
112+
executor: action-executor
120113
resource_class: xlarge
121114
steps:
122-
- *checkout_code
123-
- *restore_cache
124-
- *copy_bazel_config
125-
126-
- run: scripts/build-modules-dist.sh
127-
128-
# Save the npm packages from //modules/... for other workflow jobs to read
129-
# https://circleci.com/docs/2.0/workflows/#using-workspaces-to-share-data-among-jobs
130-
- persist_to_workspace:
131-
root: dist
132-
paths:
133-
- modules-dist
115+
- custom_attach_workspace
116+
- copy-bazel-config
117+
- run: scripts/build-modules-dist.sh
118+
- save_cache:
119+
key: *cache_key
120+
paths:
121+
- ~/.cache/yarn
122+
- ~/bazel_repository_cache
123+
- ~/bazel_disk_cache
124+
- persist_to_workspace:
125+
root: *workspace_location
126+
paths:
127+
- ng/dist
134128

135129
# We run the integration tests outside of Bazel for now.
136130
# They are a separate workflow job so that they can be easily re-run.
@@ -139,33 +133,33 @@ jobs:
139133
# need to re-run manually should be alleviated.
140134
# See comments inside the integration/run_tests.sh script.
141135
integration_test:
142-
<<: *job_defaults
143-
steps:
144-
- *checkout_code
145-
- *restore_cache
146-
- *setup_env_variables
147-
- *attach_release_output
148-
- run: ./integration/run_tests.sh
149-
150-
# TODO(CaerusKaru): remove this step
151-
bazel-lint:
152-
<<: *job_defaults
136+
executor: action-executor
153137
steps:
154-
- run: exit 0
138+
- custom_attach_workspace
139+
# Run a step to setup an environment variable.
140+
- run:
141+
name: "Setup custom environment variables"
142+
command: |
143+
echo 'export CHROMEDRIVER_VERSION_ARG="--versions.chrome 75.0.3770.90"' >> $BASH_ENV # Redirect into $BASH_ENV
144+
- run: ./integration/run_tests.sh
155145

156146
workflows:
157147
version: 2
158148
default_workflow:
159149
jobs:
160-
- build
161-
- bazel-lint
162-
- lint
150+
- setup
151+
- build:
152+
requires:
153+
- setup
154+
- lint:
155+
requires:
156+
- setup
163157
- build-packages-dist:
164158
requires:
165-
- build
159+
- build
166160
- integration_test:
167161
requires:
168-
- build-packages-dist
162+
- build-packages-dist
169163

170164
general:
171165
branches:

0 commit comments

Comments
 (0)