Skip to content

Commit

Permalink
feat: Add parameters to disable caching
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-oakes committed Mar 24, 2021
1 parent be0f588 commit ad81e99
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 94 deletions.
97 changes: 55 additions & 42 deletions src/commands/android_build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
description: Builds the Android app at the given path with the given build types. This should be run only after installing dependencies.
description: Builds the Android app at the given path with the given build types. This should be run only after installing dependencies.

parameters:
project_path:
Expand All @@ -9,27 +9,34 @@ parameters:
description: The build type to build. This is normally either "debug" or "release" but you may have custom build types configured for your app.
type: string
default: "debug"
cache:
description: Save and restore the caches? Defaults to true
type: boolean
default: true

steps:
- run:
name: Create cache checksum files
command: |
mkdir -p ~/.tmp/checksumfiles
find . -type f -name 'build.gradle' -not -path "*node_modules*" -exec cat {} + >> ~/.tmp/checksumfiles/build.gradle
find . -type f -name 'settings.gradle' -not -path "*node_modules*" -exec cat {} + >> ~/.tmp/checksumfiles/settings.gradle
- when:
condition: <<parameters.cache>>
steps:
- run:
name: Create cache checksum files
command: |
mkdir -p ~/.tmp/checksumfiles
find . -type f -name 'build.gradle' -not -path "*node_modules*" -exec cat {} + >> ~/.tmp/checksumfiles/build.gradle
find . -type f -name 'settings.gradle' -not -path "*node_modules*" -exec cat {} + >> ~/.tmp/checksumfiles/settings.gradle
- restore_cache:
keys:
- gradle-wrapper-{{ arch }}-{{ checksum "<<parameters.project_path>>/gradle/wrapper/gradle-wrapper.properties" }}-{{ .Environment.CACHE_VERSION }}
- restore_cache:
keys:
- gradle-wrapper-{{ arch }}-{{ checksum "<<parameters.project_path>>/gradle/wrapper/gradle-wrapper.properties" }}-{{ .Environment.CACHE_VERSION }}

- restore_cache:
keys:
- gradle-home-cache-{{ arch }}-{{ checksum "~/.tmp/checksumfiles/build.gradle" }}-{{ checksum "~/.tmp/checksumfiles/settings.gradle" }}-{{ .Environment.CACHE_VERSION }}
- restore_cache:
keys:
- gradle-home-cache-{{ arch }}-{{ checksum "~/.tmp/checksumfiles/build.gradle" }}-{{ checksum "~/.tmp/checksumfiles/settings.gradle" }}-{{ .Environment.CACHE_VERSION }}

- restore_cache:
name: Restoring Gradle Build caches
keys:
- gradle-build-cache-{{ .Revision }}
- restore_cache:
name: Restoring Gradle Build caches
keys:
- gradle-build-cache-{{ .Revision }}

- run:
name: Dispersing Gradle Build caches for restoring
Expand All @@ -45,35 +52,41 @@ steps:
name: Downloading Gradle Dependencies
command: "cd <<parameters.project_path>> && chmod +x gradlew && ./gradlew --max-workers 2 downloadDependencies"

- save_cache:
name: Saving Gradle wrapper cache
paths:
- ~/.gradle/wrapper/
key: gradle-wrapper-{{ arch }}-{{ checksum "<<parameters.project_path>>/gradle/wrapper/gradle-wrapper.properties" }}-{{ .Environment.CACHE_VERSION }}
- when:
condition: <<parameters.cache>>
steps:
- save_cache:
name: Saving Gradle wrapper cache
paths:
- ~/.gradle/wrapper/
key: gradle-wrapper-{{ arch }}-{{ checksum "<<parameters.project_path>>/gradle/wrapper/gradle-wrapper.properties" }}-{{ .Environment.CACHE_VERSION }}

- save_cache:
name: Saving Gradle home cache
paths:
- ~/.gradle/caches/
key: gradle-home-cache-{{ arch }}-{{ checksum "~/.tmp/checksumfiles/build.gradle" }}-{{ checksum "~/.tmp/checksumfiles/settings.gradle" }}-{{ .Environment.CACHE_VERSION }}
- save_cache:
name: Saving Gradle home cache
paths:
- ~/.gradle/caches/
key: gradle-home-cache-{{ arch }}-{{ checksum "~/.tmp/checksumfiles/build.gradle" }}-{{ checksum "~/.tmp/checksumfiles/settings.gradle" }}-{{ .Environment.CACHE_VERSION }}

- run:
name: Build Android APK
command: "cd <<parameters.project_path>> && chmod +x gradlew && ./gradlew --build-cache --max-workers 2 --continue assemble<<parameters.build_type>> assembleAndroidTest -DtestBuildType=<<parameters.build_type>> --stacktrace"

- run:
name: Collecting Gradle Build caches for saving
command: |
mkdir -p ~/gradle-build-caches
[ -d ~/.gradle/caches ] &&
[ -n "$(ls -Ad ~/.gradle/caches/build-cache-* 2>/dev/null)" ] &&
rm -rf ~/gradle-build-caches/* &&
mv ~/.gradle/caches/build-cache-* ~/gradle-build-caches || true
when: always
- when:
condition: <<parameters.cache>>
steps:
- run:
name: Collecting Gradle Build caches for saving
command: |
mkdir -p ~/gradle-build-caches
[ -d ~/.gradle/caches ] &&
[ -n "$(ls -Ad ~/.gradle/caches/build-cache-* 2>/dev/null)" ] &&
rm -rf ~/gradle-build-caches/* &&
mv ~/.gradle/caches/build-cache-* ~/gradle-build-caches || true
when: always

- save_cache:
name: Saving Gradle Build caches
paths:
- ~/gradle-build-caches
key: gradle-debug-build-cache-{{ .Revision }}
when: always
- save_cache:
name: Saving Gradle Build caches
paths:
- ~/gradle-build-caches
key: gradle-debug-build-cache-{{ .Revision }}
when: always
30 changes: 20 additions & 10 deletions src/commands/ios_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,30 @@ parameters:
scheme:
description: The scheme to use.
type: string
cache:
description: Save and restore the build cache? Defaults to true
type: boolean
default: true

steps:
- restore_cache:
name: Restoring iOS Build caches
keys:
- ios-build-cache-{{ arch }}-{{ checksum "~/.tmp/checksumfiles/package.json" }}-{{ .Environment.CACHE_VERSION }}
- when:
condition: <<parameters.cache>>
steps:
- restore_cache:
name: Restoring iOS Build caches
keys:
- ios-build-cache-{{ arch }}-{{ checksum "~/.tmp/checksumfiles/package.json" }}-{{ .Environment.CACHE_VERSION }}

- run:
name: Build iOS App
command: "export RCT_NO_LAUNCH_PACKAGER=true && xcodebuild -<<parameters.project_type>> <<parameters.project_path>> -destination 'platform=iOS Simulator,name=<<parameters.device>>' -scheme <<parameters.scheme>> -parallelizeTargets -configuration <<parameters.build_configuration>> -derivedDataPath <<parameters.derived_data_path>> -UseModernBuildSystem=YES | xcpretty -k"

- save_cache:
name: Saving iOS Build Cache
paths:
- <<parameters.derived_data_path>>/Build
key: ios-build-cache-{{ arch }}-{{ checksum "~/.tmp/checksumfiles/package.json" }}-{{ .Environment.CACHE_VERSION }}
when: always
- when:
condition: <<parameters.cache>>
steps:
- save_cache:
name: Saving iOS Build Cache
paths:
- <<parameters.derived_data_path>>/Build
key: ios-build-cache-{{ arch }}-{{ checksum "~/.tmp/checksumfiles/package.json" }}-{{ .Environment.CACHE_VERSION }}
when: always
27 changes: 19 additions & 8 deletions src/commands/pod_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,27 @@ parameters:
type: string
default: "ios"
description: The location of the "ios" directory
cache:
description: Save and restore the cache? Defaults to true
type: boolean
default: true

steps:
- restore_cache:
keys:
- cache-pods-{{ checksum "<<parameters.pod_install_directory>>/Podfile.lock" }}-{{ .Environment.CACHE_VERSION }}
- cache-pods-
- when:
condition: <<parameters.cache>>
steps:
- restore_cache:
keys:
- cache-pods-{{ checksum "<<parameters.pod_install_directory>>/Podfile.lock" }}-{{ .Environment.CACHE_VERSION }}
- cache-pods-
- run:
name: Install CocoaPods
command: |
cd <<parameters.pod_install_directory>> && pod install && cd -
- save_cache:
paths:
- <<parameters.pod_install_directory>>/Pods
key: cache-pods-{{ checksum "<<parameters.pod_install_directory>>/Podfile.lock" }}-{{ .Environment.CACHE_VERSION }}
- when:
condition: <<parameters.cache>>
steps:
- save_cache:
paths:
- <<parameters.pod_install_directory>>/Pods
key: cache-pods-{{ checksum "<<parameters.pod_install_directory>>/Podfile.lock" }}-{{ .Environment.CACHE_VERSION }}
28 changes: 19 additions & 9 deletions src/commands/setup_macos_executor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ parameters:
description: The version of Node to use. This can be either a major version ("8"), a major and minor ("8.4"), or a fully qualified version ("8.4.1").
type: string
default: "12"
homebrew_cache:
description: Should we cache after brew install? Defaults to true
type: boolean
default: true

steps:
- run:
Expand All @@ -18,9 +22,12 @@ steps:
echo 'export JAVA_HOME=$(/usr/libexec/java_home)' >> $BASH_ENV
source $BASH_ENV
- restore_cache:
key: |
brew-cache-{{ arch }}-{{ .Environment.CACHE_VERSION }}
- when:
condition: <<parameters.homebrew_cache>>
steps:
- restore_cache:
key: |
brew-cache-{{ arch }}-{{ .Environment.CACHE_VERSION }}
- run:
name: Install node@<<parameters.node_version>>
Expand Down Expand Up @@ -48,9 +55,12 @@ steps:
touch .watchmanconfig
node -v
- save_cache:
paths:
- /usr/local/Homebrew
- ~/Library/Caches/Homebrew
key: |
brew-cache-{{ arch }}-{{ .Environment.CACHE_VERSION }}
- when:
condition: <<parameters.homebrew_cache>>
steps:
- save_cache:
paths:
- /usr/local/Homebrew
- ~/Library/Caches/Homebrew
key: |
brew-cache-{{ arch }}-{{ .Environment.CACHE_VERSION }}
40 changes: 26 additions & 14 deletions src/commands/yarn_install.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
description: Install Javascript dependencies using Yarn. This command correctly configures the cache for any number of package.json and yarn.lock files.

parameters:
cache:
description: Save and restore the build cache? Defaults to true
type: boolean
default: true

steps:
- run:
name: Create cache checksum file
command: |
mkdir -p ~/.tmp/checksumfiles
find . -type f -name 'package.json' -not -path "*node_modules*" -exec cat {} + >> ~/.tmp/checksumfiles/package.json
find . -type f -name 'yarn.lock' -not -path "*node_modules*" -exec cat {} + >> ~/.tmp/checksumfiles/yarn.lock
- restore_cache:
keys:
- yarn-cache-{{ arch }}-{{ checksum "~/.tmp/checksumfiles/package.json" }}-{{ checksum "~/.tmp/checksumfiles/yarn.lock" }}-{{ .Environment.CACHE_VERSION }}
- when:
condition: <<parameters.cache>>
steps:
- run:
name: Create cache checksum file
command: |
mkdir -p ~/.tmp/checksumfiles
find . -type f -name 'package.json' -not -path "*node_modules*" -exec cat {} + >> ~/.tmp/checksumfiles/package.json
find . -type f -name 'yarn.lock' -not -path "*node_modules*" -exec cat {} + >> ~/.tmp/checksumfiles/yarn.lock
- restore_cache:
keys:
- yarn-cache-{{ arch }}-{{ checksum "~/.tmp/checksumfiles/package.json" }}-{{ checksum "~/.tmp/checksumfiles/yarn.lock" }}-{{ .Environment.CACHE_VERSION }}
- run:
name: Yarn Install
command: yarn install --frozen-lockfile --non-interactive --cache-folder /tmp/yarn
- save_cache:
paths:
- /tmp/yarn
key: |
yarn-cache-{{ arch }}-{{ checksum "~/.tmp/checksumfiles/package.json" }}-{{ checksum "~/.tmp/checksumfiles/yarn.lock" }}-{{ .Environment.CACHE_VERSION }}
- when:
condition: <<parameters.cache>>
steps:
- save_cache:
paths:
- /tmp/yarn
key: |
yarn-cache-{{ arch }}-{{ checksum "~/.tmp/checksumfiles/package.json" }}-{{ checksum "~/.tmp/checksumfiles/yarn.lock" }}-{{ .Environment.CACHE_VERSION }}
12 changes: 11 additions & 1 deletion src/jobs/android_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ parameters:
description: Store this job store files as job artifacts? Defaults to true
type: boolean
default: true
yarn_cache:
description: Should we cache after yarn install? Defaults to true
type: boolean
default: true
# For the build command
project_path:
description: The path to the root of the Android project you want to build, relative to the root of the repository.
Expand All @@ -37,6 +41,10 @@ parameters:
description: A custom command to run right after yarn install.
type: string
default: ""
build_cache:
description: Should we cache after Gradle build? Defaults to true
type: boolean
default: true

steps:
- when:
Expand All @@ -48,7 +56,8 @@ steps:
steps:
- attach_workspace:
at: <<parameters.workspace_root>>
- yarn_install
- yarn_install:
cache: <<parameters.yarn_cache>>
- when:
condition: <<parameters.on_after_initialize>>
steps:
Expand All @@ -58,6 +67,7 @@ steps:
- android_build:
project_path: <<parameters.project_path>>
build_type: <<parameters.build_type>>
cache: <<parameters.build_cache>>
- when:
condition: <<parameters.persist_to_workspace>>
steps:
Expand Down
13 changes: 9 additions & 4 deletions src/jobs/android_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ parameters:
description: If we should start the Metro packager in the background for this job.
type: boolean
default: false
yarn_cache:
description: Should we cache after yarn install? Defaults to true
type: boolean
default: true
# For the start emulator command
device_name:
description: The name of the AVD. You use this name to tell which device to run tests on. Defaults to 'TestingAVD'.
Expand Down Expand Up @@ -40,7 +44,7 @@ parameters:
enum: ["fatal", "error", "warn", "info", "verbose", "trace"]
default: warn
store_artifact_path:
description: Stores detox artifacts at CircleCI
description: Stores detox artifacts at CircleCI
type: string
default: ""
should_on_after_initialize:
Expand All @@ -55,14 +59,15 @@ parameters:
node_version:
description: The version of Node to use. This can be either a major version ("8"), a major and minor ("8.4"), or a fully qualified version ("8.4.1").
type: string
default: '12'
default: "12"

steps:
- attach_workspace:
at: <<parameters.workspace_root>>
- setup_macos_executor:
node_version: <<parameters.node_version>>
- yarn_install
node_version: <<parameters.node_version>>
- yarn_install:
cache: <<parameters.yarn_cache>>
- when:
condition: <<parameters.should_on_after_initialize>>
steps:
Expand Down
Loading

0 comments on commit ad81e99

Please sign in to comment.