From 5e01602a011b524ba612ae1eef68b6bcd864e6f6 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Mon, 14 Dec 2020 11:46:42 -0330 Subject: [PATCH] Cache dependencies (#10065) Dependencies are now cached between builds, using a checksum of the `yarn.lock` file as the cache key. The `node_modules` directory and the `.har` file from the install are cached and restored, so that we ensure the record of the install is always preserved alongside the dependencies. The consolidation of the `collect-har-artifact` script was to make it easier to cache the `.har` file along with the dependencies. --- .circleci/config.yml | 11 +++++++---- .circleci/scripts/collect-har-artifact.sh | 5 ----- .circleci/scripts/deps-install.sh | 8 ++++++++ 3 files changed, 15 insertions(+), 9 deletions(-) delete mode 100755 .circleci/scripts/collect-har-artifact.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index e54378e98..e0407f18b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -125,14 +125,17 @@ jobs: executor: node-browsers steps: - checkout + - restore_cache: + key: dependency-cache-{{ checksum "yarn.lock" }} - run: name: Install deps command: | .circleci/scripts/deps-install.sh - - run: - name: Collect yarn install HAR logs - command: | - .circleci/scripts/collect-har-artifact.sh + - save_cache: + key: dependency-cache-{{ checksum "yarn.lock" }} + paths: + - node_modules/ + - build-artifacts/yarn-install-har/ - persist_to_workspace: root: . paths: diff --git a/.circleci/scripts/collect-har-artifact.sh b/.circleci/scripts/collect-har-artifact.sh deleted file mode 100755 index 7f6f1aa41..000000000 --- a/.circleci/scripts/collect-har-artifact.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash -set -x - -mkdir -p build-artifacts/yarn-install-har -mv ./*.har build-artifacts/yarn-install-har/ diff --git a/.circleci/scripts/deps-install.sh b/.circleci/scripts/deps-install.sh index c8b15e29b..828d6e63a 100755 --- a/.circleci/scripts/deps-install.sh +++ b/.circleci/scripts/deps-install.sh @@ -7,6 +7,14 @@ set -e yarn --frozen-lockfile --ignore-scripts --har +# Move HAR file into directory with consistent name so that we can cache it +mkdir -p build-artifacts/yarn-install-har +har_files=(./*.har) +if [[ -f "${har_files[0]}" ]] +then + mv ./*.har build-artifacts/yarn-install-har/ +fi + # run each in subshell so directory change does not persist # scripts can be any of: # preinstall