From d03f0ba4950834dd8bb7f2ac4b0bc047ccda59ac Mon Sep 17 00:00:00 2001 From: Hector Ramos Date: Tue, 27 Mar 2018 13:07:28 -0700 Subject: [PATCH] Cache gradle downloads and reuse existing caches in forks --- .circleci/config.yml | 69 ++++++++++++++---------- scripts/circleci/gradle_download_deps.sh | 5 ++ 2 files changed, 45 insertions(+), 29 deletions(-) create mode 100755 scripts/circleci/gradle_download_deps.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index 675aeb4e0b07f5..dcf58064c371aa 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,47 +1,37 @@ aliases: # Cache Management - - &restore-yarn-cache + - &restore-cache-yarn keys: - - v1-yarn-{{ arch }}-{{ .Branch }}-{{ checksum "package.json" }} - # Fallback in case checksum fails - - v1-yarn-{{ arch }}-{{ .Branch }}- - # Fallback in case this is a first-time run on a fork - - v1-yarn-{{ arch }}-master- - - &save-yarn-cache + - v1-yarn-{{ arch }}-{{ checksum "package.json" }} + - v1-yarn-{{ arch }}- + - &save-cache-yarn paths: - node_modules - ~/.cache/yarn - key: v1-yarn-{{ arch }}-{{ .Branch }}-{{ checksum "package.json" }} + key: v1-yarn-{{ arch }}-{{ checksum "package.json" }} - &restore-cache-analysis keys: - - v1-analysis-dependencies-{{ arch }}-{{ .Branch }}-{{ checksum "package.json" }}{{ checksum "bots/package.json" }} - # Fallback in case checksum fails - - v1-analysis-dependencies-{{ arch }}-{{ .Branch }}- - # Fallback in case this is a first-time run on a fork - - v1-analysis-dependencies-{{ arch }}-master- + - v1-analysis-dependencies-{{ arch }}-{{ checksum "package.json" }}{{ checksum "bots/package.json" }} + - v1-analysis-dependencies-{{ arch }}- - &save-cache-analysis paths: - bots/node_modules - node_modules - key: v1-analysis-dependencies-{{ arch }}-{{ .Branch }}-{{ checksum "package.json" }}{{ checksum "bots/package.json" }} + key: v1-analysis-dependencies-{{ arch }}-{{ checksum "package.json" }}{{ checksum "bots/package.json" }} - &restore-cache-android-packages keys: - - v1-android-sdkmanager-packages-{{ arch }}-{{ .Branch }}-api-26-alpha-{{ checksum "scripts/circle-ci-android-setup.sh" }} - # Fallback in case checksum fails - - v1-android-sdkmanager-packages-{{ arch }}-{{ .Branch }}-api-26-alpha- - # Fallback in case this is a first-time run on a fork - - v1-android-sdkmanager-packages-{{ arch }}-master-api-26-alpha- + - v1-android-sdkmanager-packages-{{ arch }}-api-26-alpha-{{ checksum "scripts/circle-ci-android-setup.sh" }} + - v1-android-sdkmanager-packages-{{ arch }}-api-26-alpha- - &save-cache-android-packages paths: - /opt/android/sdk - key: v1-android-sdkmanager-packages-{{ arch }}-{{ .Branch }}-api-26-alpha-{{ checksum "scripts/circle-ci-android-setup.sh" }} + key: v1-android-sdkmanager-packages-{{ arch }}-api-26-alpha-{{ checksum "scripts/circle-ci-android-setup.sh" }} - &restore-cache-ndk keys: - v2-android-ndk-{{ arch }}-r10e-32-64-{{ checksum "scripts/circle-ci-android-setup.sh" }} - # Fallback in case checksum fails - v2-android-ndk-{{ arch }}-r10e-32-64- - &save-cache-ndk paths: @@ -64,6 +54,17 @@ aliases: - ~/watchman key: v1-watchman-{{ arch }}-v4.9.0 + - &restore-cache-gradle-downloads + keys: + - v1-gradle-{{ arch }}-{{ checksum "ReactAndroid/build.gradle" }}-{{ checksum "scripts/circleci/gradle_download_deps.sh" }} + - v1-gradle-{{ arch }}- + - &save-cache-gradle-downloads + paths: + - ~/.gradle + - ReactAndroid/build/downloads + - ReactAndroid/build/third-party-ndk + key: v1-gradle-{{ arch }}-{{ checksum "ReactAndroid/build.gradle" }}-{{ checksum "scripts/circleci/gradle_download_deps.sh" }} + # Branch Filtering - &filter-only-master-stable branches: @@ -175,6 +176,10 @@ aliases: ./scripts/circleci/check_license.sh ./scripts/circleci/check_cache.sh when: always + + - &gradle-download-deps + name: Download C++ Dependencies + command: ./scripts/circleci/gradle_download_deps.sh - &build-android-app name: Build Android App @@ -283,9 +288,9 @@ jobs: - checkout - run: *setup-artifacts - - restore-cache: *restore-yarn-cache + - restore-cache: *restore-cache-yarn - run: *yarn - - save-cache: *save-yarn-cache + - save-cache: *save-cache-yarn # Basic checks against the checkout, cache... - run: *run-sanity-checks @@ -331,9 +336,9 @@ jobs: - checkout - run: *setup-artifacts - - restore-cache: *restore-yarn-cache + - restore-cache: *restore-cache-yarn - run: *yarn - - save-cache: *save-yarn-cache + - save-cache: *save-cache-yarn - run: *run-js-tests @@ -420,13 +425,16 @@ jobs: - run: buck fetch ReactAndroid/src/main/java/com/facebook/react/shell - run: buck fetch ReactAndroid/src/test/... - run: buck fetch ReactAndroid/src/androidTest/... - - run: ./gradlew :ReactAndroid:downloadBoost :ReactAndroid:downloadDoubleConversion :ReactAndroid:downloadFolly :ReactAndroid:downloadGlog :ReactAndroid:downloadJSCHeaders + + - restore-cache: *restore-cache-gradle-downloads + - run: *gradle-download-deps + - save-cache: *save-cache-gradle-downloads - run: *install-node - run: *install-yarn - - restore-cache: *restore-yarn-cache + - restore-cache: *restore-cache-yarn - run: *yarn - - save-cache: *save-yarn-cache + - save-cache: *save-cache-yarn - run: name: Publish React Native Package @@ -481,7 +489,10 @@ jobs: - run: buck fetch ReactAndroid/src/main/java/com/facebook/react/shell - run: buck fetch ReactAndroid/src/test/... - run: buck fetch ReactAndroid/src/androidTest/... - - run: ./gradlew :ReactAndroid:downloadBoost :ReactAndroid:downloadDoubleConversion :ReactAndroid:downloadFolly :ReactAndroid:downloadGlog :ReactAndroid:downloadJSCHeaders + + - restore-cache: *restore-cache-gradle-downloads + - run: *gradle-download-deps + - save-cache: *save-cache-gradle-downloads # Build and compile - run: *build-android-app diff --git a/scripts/circleci/gradle_download_deps.sh b/scripts/circleci/gradle_download_deps.sh new file mode 100755 index 00000000000000..1e093de55a0b7f --- /dev/null +++ b/scripts/circleci/gradle_download_deps.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +set -e + +./gradlew :ReactAndroid:downloadBoost :ReactAndroid:downloadDoubleConversion :ReactAndroid:downloadFolly :ReactAndroid:downloadGlog :ReactAndroid:downloadJSCHeaders \ No newline at end of file