Skip to content

Commit ad81e99

Browse files
committed
feat: Add parameters to disable caching
1 parent be0f588 commit ad81e99

File tree

9 files changed

+195
-94
lines changed

9 files changed

+195
-94
lines changed

src/commands/android_build.yml

Lines changed: 55 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
description: Builds the Android app at the given path with the given build types. This should be run only after installing dependencies.
1+
description: Builds the Android app at the given path with the given build types. This should be run only after installing dependencies.
22

33
parameters:
44
project_path:
@@ -9,27 +9,34 @@ parameters:
99
description: The build type to build. This is normally either "debug" or "release" but you may have custom build types configured for your app.
1010
type: string
1111
default: "debug"
12+
cache:
13+
description: Save and restore the caches? Defaults to true
14+
type: boolean
15+
default: true
1216

1317
steps:
14-
- run:
15-
name: Create cache checksum files
16-
command: |
17-
mkdir -p ~/.tmp/checksumfiles
18-
find . -type f -name 'build.gradle' -not -path "*node_modules*" -exec cat {} + >> ~/.tmp/checksumfiles/build.gradle
19-
find . -type f -name 'settings.gradle' -not -path "*node_modules*" -exec cat {} + >> ~/.tmp/checksumfiles/settings.gradle
18+
- when:
19+
condition: <<parameters.cache>>
20+
steps:
21+
- run:
22+
name: Create cache checksum files
23+
command: |
24+
mkdir -p ~/.tmp/checksumfiles
25+
find . -type f -name 'build.gradle' -not -path "*node_modules*" -exec cat {} + >> ~/.tmp/checksumfiles/build.gradle
26+
find . -type f -name 'settings.gradle' -not -path "*node_modules*" -exec cat {} + >> ~/.tmp/checksumfiles/settings.gradle
2027
21-
- restore_cache:
22-
keys:
23-
- gradle-wrapper-{{ arch }}-{{ checksum "<<parameters.project_path>>/gradle/wrapper/gradle-wrapper.properties" }}-{{ .Environment.CACHE_VERSION }}
28+
- restore_cache:
29+
keys:
30+
- gradle-wrapper-{{ arch }}-{{ checksum "<<parameters.project_path>>/gradle/wrapper/gradle-wrapper.properties" }}-{{ .Environment.CACHE_VERSION }}
2431

25-
- restore_cache:
26-
keys:
27-
- gradle-home-cache-{{ arch }}-{{ checksum "~/.tmp/checksumfiles/build.gradle" }}-{{ checksum "~/.tmp/checksumfiles/settings.gradle" }}-{{ .Environment.CACHE_VERSION }}
32+
- restore_cache:
33+
keys:
34+
- gradle-home-cache-{{ arch }}-{{ checksum "~/.tmp/checksumfiles/build.gradle" }}-{{ checksum "~/.tmp/checksumfiles/settings.gradle" }}-{{ .Environment.CACHE_VERSION }}
2835

29-
- restore_cache:
30-
name: Restoring Gradle Build caches
31-
keys:
32-
- gradle-build-cache-{{ .Revision }}
36+
- restore_cache:
37+
name: Restoring Gradle Build caches
38+
keys:
39+
- gradle-build-cache-{{ .Revision }}
3340

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

48-
- save_cache:
49-
name: Saving Gradle wrapper cache
50-
paths:
51-
- ~/.gradle/wrapper/
52-
key: gradle-wrapper-{{ arch }}-{{ checksum "<<parameters.project_path>>/gradle/wrapper/gradle-wrapper.properties" }}-{{ .Environment.CACHE_VERSION }}
55+
- when:
56+
condition: <<parameters.cache>>
57+
steps:
58+
- save_cache:
59+
name: Saving Gradle wrapper cache
60+
paths:
61+
- ~/.gradle/wrapper/
62+
key: gradle-wrapper-{{ arch }}-{{ checksum "<<parameters.project_path>>/gradle/wrapper/gradle-wrapper.properties" }}-{{ .Environment.CACHE_VERSION }}
5363

54-
- save_cache:
55-
name: Saving Gradle home cache
56-
paths:
57-
- ~/.gradle/caches/
58-
key: gradle-home-cache-{{ arch }}-{{ checksum "~/.tmp/checksumfiles/build.gradle" }}-{{ checksum "~/.tmp/checksumfiles/settings.gradle" }}-{{ .Environment.CACHE_VERSION }}
64+
- save_cache:
65+
name: Saving Gradle home cache
66+
paths:
67+
- ~/.gradle/caches/
68+
key: gradle-home-cache-{{ arch }}-{{ checksum "~/.tmp/checksumfiles/build.gradle" }}-{{ checksum "~/.tmp/checksumfiles/settings.gradle" }}-{{ .Environment.CACHE_VERSION }}
5969

6070
- run:
6171
name: Build Android APK
6272
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"
6373

64-
- run:
65-
name: Collecting Gradle Build caches for saving
66-
command: |
67-
mkdir -p ~/gradle-build-caches
68-
[ -d ~/.gradle/caches ] &&
69-
[ -n "$(ls -Ad ~/.gradle/caches/build-cache-* 2>/dev/null)" ] &&
70-
rm -rf ~/gradle-build-caches/* &&
71-
mv ~/.gradle/caches/build-cache-* ~/gradle-build-caches || true
72-
when: always
74+
- when:
75+
condition: <<parameters.cache>>
76+
steps:
77+
- run:
78+
name: Collecting Gradle Build caches for saving
79+
command: |
80+
mkdir -p ~/gradle-build-caches
81+
[ -d ~/.gradle/caches ] &&
82+
[ -n "$(ls -Ad ~/.gradle/caches/build-cache-* 2>/dev/null)" ] &&
83+
rm -rf ~/gradle-build-caches/* &&
84+
mv ~/.gradle/caches/build-cache-* ~/gradle-build-caches || true
85+
when: always
7386

74-
- save_cache:
75-
name: Saving Gradle Build caches
76-
paths:
77-
- ~/gradle-build-caches
78-
key: gradle-debug-build-cache-{{ .Revision }}
79-
when: always
87+
- save_cache:
88+
name: Saving Gradle Build caches
89+
paths:
90+
- ~/gradle-build-caches
91+
key: gradle-debug-build-cache-{{ .Revision }}
92+
when: always

src/commands/ios_build.yml

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,30 @@ parameters:
2424
scheme:
2525
description: The scheme to use.
2626
type: string
27+
cache:
28+
description: Save and restore the build cache? Defaults to true
29+
type: boolean
30+
default: true
2731

2832
steps:
29-
- restore_cache:
30-
name: Restoring iOS Build caches
31-
keys:
32-
- ios-build-cache-{{ arch }}-{{ checksum "~/.tmp/checksumfiles/package.json" }}-{{ .Environment.CACHE_VERSION }}
33+
- when:
34+
condition: <<parameters.cache>>
35+
steps:
36+
- restore_cache:
37+
name: Restoring iOS Build caches
38+
keys:
39+
- ios-build-cache-{{ arch }}-{{ checksum "~/.tmp/checksumfiles/package.json" }}-{{ .Environment.CACHE_VERSION }}
3340

3441
- run:
3542
name: Build iOS App
3643
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"
3744

38-
- save_cache:
39-
name: Saving iOS Build Cache
40-
paths:
41-
- <<parameters.derived_data_path>>/Build
42-
key: ios-build-cache-{{ arch }}-{{ checksum "~/.tmp/checksumfiles/package.json" }}-{{ .Environment.CACHE_VERSION }}
43-
when: always
45+
- when:
46+
condition: <<parameters.cache>>
47+
steps:
48+
- save_cache:
49+
name: Saving iOS Build Cache
50+
paths:
51+
- <<parameters.derived_data_path>>/Build
52+
key: ios-build-cache-{{ arch }}-{{ checksum "~/.tmp/checksumfiles/package.json" }}-{{ .Environment.CACHE_VERSION }}
53+
when: always

src/commands/pod_install.yml

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,27 @@ parameters:
99
type: string
1010
default: "ios"
1111
description: The location of the "ios" directory
12+
cache:
13+
description: Save and restore the cache? Defaults to true
14+
type: boolean
15+
default: true
16+
1217
steps:
13-
- restore_cache:
14-
keys:
15-
- cache-pods-{{ checksum "<<parameters.pod_install_directory>>/Podfile.lock" }}-{{ .Environment.CACHE_VERSION }}
16-
- cache-pods-
18+
- when:
19+
condition: <<parameters.cache>>
20+
steps:
21+
- restore_cache:
22+
keys:
23+
- cache-pods-{{ checksum "<<parameters.pod_install_directory>>/Podfile.lock" }}-{{ .Environment.CACHE_VERSION }}
24+
- cache-pods-
1725
- run:
1826
name: Install CocoaPods
1927
command: |
2028
cd <<parameters.pod_install_directory>> && pod install && cd -
21-
- save_cache:
22-
paths:
23-
- <<parameters.pod_install_directory>>/Pods
24-
key: cache-pods-{{ checksum "<<parameters.pod_install_directory>>/Podfile.lock" }}-{{ .Environment.CACHE_VERSION }}
29+
- when:
30+
condition: <<parameters.cache>>
31+
steps:
32+
- save_cache:
33+
paths:
34+
- <<parameters.pod_install_directory>>/Pods
35+
key: cache-pods-{{ checksum "<<parameters.pod_install_directory>>/Podfile.lock" }}-{{ .Environment.CACHE_VERSION }}

src/commands/setup_macos_executor.yml

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ parameters:
55
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").
66
type: string
77
default: "12"
8+
homebrew_cache:
9+
description: Should we cache after brew install? Defaults to true
10+
type: boolean
11+
default: true
812

913
steps:
1014
- run:
@@ -18,9 +22,12 @@ steps:
1822
echo 'export JAVA_HOME=$(/usr/libexec/java_home)' >> $BASH_ENV
1923
source $BASH_ENV
2024
21-
- restore_cache:
22-
key: |
23-
brew-cache-{{ arch }}-{{ .Environment.CACHE_VERSION }}
25+
- when:
26+
condition: <<parameters.homebrew_cache>>
27+
steps:
28+
- restore_cache:
29+
key: |
30+
brew-cache-{{ arch }}-{{ .Environment.CACHE_VERSION }}
2431
2532
- run:
2633
name: Install node@<<parameters.node_version>>
@@ -48,9 +55,12 @@ steps:
4855
touch .watchmanconfig
4956
node -v
5057
51-
- save_cache:
52-
paths:
53-
- /usr/local/Homebrew
54-
- ~/Library/Caches/Homebrew
55-
key: |
56-
brew-cache-{{ arch }}-{{ .Environment.CACHE_VERSION }}
58+
- when:
59+
condition: <<parameters.homebrew_cache>>
60+
steps:
61+
- save_cache:
62+
paths:
63+
- /usr/local/Homebrew
64+
- ~/Library/Caches/Homebrew
65+
key: |
66+
brew-cache-{{ arch }}-{{ .Environment.CACHE_VERSION }}

src/commands/yarn_install.yml

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,32 @@
11
description: Install Javascript dependencies using Yarn. This command correctly configures the cache for any number of package.json and yarn.lock files.
22

3+
parameters:
4+
cache:
5+
description: Save and restore the build cache? Defaults to true
6+
type: boolean
7+
default: true
8+
39
steps:
4-
- run:
5-
name: Create cache checksum file
6-
command: |
7-
mkdir -p ~/.tmp/checksumfiles
8-
find . -type f -name 'package.json' -not -path "*node_modules*" -exec cat {} + >> ~/.tmp/checksumfiles/package.json
9-
find . -type f -name 'yarn.lock' -not -path "*node_modules*" -exec cat {} + >> ~/.tmp/checksumfiles/yarn.lock
10-
- restore_cache:
11-
keys:
12-
- yarn-cache-{{ arch }}-{{ checksum "~/.tmp/checksumfiles/package.json" }}-{{ checksum "~/.tmp/checksumfiles/yarn.lock" }}-{{ .Environment.CACHE_VERSION }}
10+
- when:
11+
condition: <<parameters.cache>>
12+
steps:
13+
- run:
14+
name: Create cache checksum file
15+
command: |
16+
mkdir -p ~/.tmp/checksumfiles
17+
find . -type f -name 'package.json' -not -path "*node_modules*" -exec cat {} + >> ~/.tmp/checksumfiles/package.json
18+
find . -type f -name 'yarn.lock' -not -path "*node_modules*" -exec cat {} + >> ~/.tmp/checksumfiles/yarn.lock
19+
- restore_cache:
20+
keys:
21+
- yarn-cache-{{ arch }}-{{ checksum "~/.tmp/checksumfiles/package.json" }}-{{ checksum "~/.tmp/checksumfiles/yarn.lock" }}-{{ .Environment.CACHE_VERSION }}
1322
- run:
1423
name: Yarn Install
1524
command: yarn install --frozen-lockfile --non-interactive --cache-folder /tmp/yarn
16-
- save_cache:
17-
paths:
18-
- /tmp/yarn
19-
key: |
20-
yarn-cache-{{ arch }}-{{ checksum "~/.tmp/checksumfiles/package.json" }}-{{ checksum "~/.tmp/checksumfiles/yarn.lock" }}-{{ .Environment.CACHE_VERSION }}
25+
- when:
26+
condition: <<parameters.cache>>
27+
steps:
28+
- save_cache:
29+
paths:
30+
- /tmp/yarn
31+
key: |
32+
yarn-cache-{{ arch }}-{{ checksum "~/.tmp/checksumfiles/package.json" }}-{{ checksum "~/.tmp/checksumfiles/yarn.lock" }}-{{ .Environment.CACHE_VERSION }}

src/jobs/android_build.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ parameters:
2424
description: Store this job store files as job artifacts? Defaults to true
2525
type: boolean
2626
default: true
27+
yarn_cache:
28+
description: Should we cache after yarn install? Defaults to true
29+
type: boolean
30+
default: true
2731
# For the build command
2832
project_path:
2933
description: The path to the root of the Android project you want to build, relative to the root of the repository.
@@ -37,6 +41,10 @@ parameters:
3741
description: A custom command to run right after yarn install.
3842
type: string
3943
default: ""
44+
build_cache:
45+
description: Should we cache after Gradle build? Defaults to true
46+
type: boolean
47+
default: true
4048

4149
steps:
4250
- when:
@@ -48,7 +56,8 @@ steps:
4856
steps:
4957
- attach_workspace:
5058
at: <<parameters.workspace_root>>
51-
- yarn_install
59+
- yarn_install:
60+
cache: <<parameters.yarn_cache>>
5261
- when:
5362
condition: <<parameters.on_after_initialize>>
5463
steps:
@@ -58,6 +67,7 @@ steps:
5867
- android_build:
5968
project_path: <<parameters.project_path>>
6069
build_type: <<parameters.build_type>>
70+
cache: <<parameters.build_cache>>
6171
- when:
6272
condition: <<parameters.persist_to_workspace>>
6373
steps:

src/jobs/android_test.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ parameters:
1212
description: If we should start the Metro packager in the background for this job.
1313
type: boolean
1414
default: false
15+
yarn_cache:
16+
description: Should we cache after yarn install? Defaults to true
17+
type: boolean
18+
default: true
1519
# For the start emulator command
1620
device_name:
1721
description: The name of the AVD. You use this name to tell which device to run tests on. Defaults to 'TestingAVD'.
@@ -40,7 +44,7 @@ parameters:
4044
enum: ["fatal", "error", "warn", "info", "verbose", "trace"]
4145
default: warn
4246
store_artifact_path:
43-
description: Stores detox artifacts at CircleCI
47+
description: Stores detox artifacts at CircleCI
4448
type: string
4549
default: ""
4650
should_on_after_initialize:
@@ -55,14 +59,15 @@ parameters:
5559
node_version:
5660
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").
5761
type: string
58-
default: '12'
62+
default: "12"
5963

6064
steps:
6165
- attach_workspace:
6266
at: <<parameters.workspace_root>>
6367
- setup_macos_executor:
64-
node_version: <<parameters.node_version>>
65-
- yarn_install
68+
node_version: <<parameters.node_version>>
69+
- yarn_install:
70+
cache: <<parameters.yarn_cache>>
6671
- when:
6772
condition: <<parameters.should_on_after_initialize>>
6873
steps:

0 commit comments

Comments
 (0)