From 7ec6c2e60f80dc53cd67bad41ba2a5582211241f Mon Sep 17 00:00:00 2001 From: meriadec Date: Thu, 21 Jun 2018 11:41:04 +0200 Subject: [PATCH] Optimize CI builds by caching dependencies Now it takes ~1 minute instead of more than 5 minutes :tada: --- .circleci/config.yml | 13 +++++++++++-- scripts/hash-utils.sh | 26 ++++++++++++++++++++++++++ scripts/install-ci-deps.sh | 13 +++++++++++++ scripts/postinstall.sh | 31 +++++-------------------------- 4 files changed, 55 insertions(+), 28 deletions(-) create mode 100644 scripts/hash-utils.sh create mode 100644 scripts/install-ci-deps.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index dc9c2e92..b3cde252 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -12,9 +12,18 @@ jobs: - gh-pages steps: - checkout + - restore_cache: + name: Restore Yarn Package Cache + keys: + - v1-yarn-packages-{{ .Branch }}-{{ checksum "yarn.lock" }} - run: - name: Dependencies - command: SKIP_REBUILD=1 yarn + name: Install Dependencies + command: bash scripts/install-ci-deps.sh + - save_cache: + name: Save Yarn Package Cache + key: v1-yarn-packages-{{ .Branch }}-{{ checksum "yarn.lock" }} + paths: + - node_modules/ - run: name: Lint command: yarn lint diff --git a/scripts/hash-utils.sh b/scripts/hash-utils.sh new file mode 100644 index 00000000..7210614a --- /dev/null +++ b/scripts/hash-utils.sh @@ -0,0 +1,26 @@ +#/bin/bash + +function GET_HASH_PATH { + HASH_NAME=$1 + echo "./node_modules/.cache/LEDGER_HASH_$HASH_NAME.hash" +} + +function GET_HASH { + HASH_NAME=$1 + HASH_PATH=`GET_HASH_PATH $HASH_NAME` + if [ ! -e "$HASH_PATH" ]; then + echo '' + else + HASH_CONTENT=`cat "$HASH_PATH"` + echo $HASH_CONTENT + fi +} + +function SET_HASH { + HASH_NAME=$1 + HASH_CONTENT=$2 + echo "setting hash $HASH_NAME to $HASH_CONTENT" + HASH_PATH=`GET_HASH_PATH $HASH_NAME` + mkdir -p ./node_modules/.cache + echo $HASH_CONTENT > $HASH_PATH +} diff --git a/scripts/install-ci-deps.sh b/scripts/install-ci-deps.sh new file mode 100644 index 00000000..c0ecbae2 --- /dev/null +++ b/scripts/install-ci-deps.sh @@ -0,0 +1,13 @@ +#/bin/bash + +source scripts/hash-utils.sh + +PACKAGE_JSON_HASH=`md5sum package.json | cut -d ' ' -f 1` +CACHED_PACKAGE_JSON_HASH=`GET_HASH 'package.json'` + +if [ "$CACHED_PACKAGE_JSON_HASH" == "$PACKAGE_JSON_HASH" ]; then + echo "> Skipping yarn install" +else + yarn install + SET_HASH 'package.json' $PACKAGE_JSON_HASH +fi diff --git a/scripts/postinstall.sh b/scripts/postinstall.sh index 2eaa9447..1609353f 100755 --- a/scripts/postinstall.sh +++ b/scripts/postinstall.sh @@ -1,33 +1,12 @@ #/bin/bash -function MAIN { - REBUILD_ELECTRON_NATIVE_DEPS - INSTALL_FLOW_TYPED -} - -function GET_HASH_PATH { - HASH_NAME=$1 - echo "./node_modules/.cache/LEDGER_HASH_$HASH_NAME.hash" -} +source scripts/hash-utils.sh -function GET_HASH { - HASH_NAME=$1 - HASH_PATH=`GET_HASH_PATH $HASH_NAME` - if [ ! -e "$HASH_PATH" ]; then - echo '' - else - HASH_CONTENT=`cat "$HASH_PATH"` - echo $HASH_CONTENT +function MAIN { + if ! $CI; then + REBUILD_ELECTRON_NATIVE_DEPS fi -} - -function SET_HASH { - HASH_NAME=$1 - HASH_CONTENT=$2 - echo "setting hash $HASH_NAME to $HASH_CONTENT" - HASH_PATH=`GET_HASH_PATH $HASH_NAME` - mkdir -p ./node_modules/.cache - echo $HASH_CONTENT > $HASH_PATH + INSTALL_FLOW_TYPED } function INSTALL_FLOW_TYPED {