Skip to content

Commit

Permalink
feat!: Separate wrap and deps cache
Browse files Browse the repository at this point in the history
Feat!: Split Wrapper and Deps Caches
  • Loading branch information
Jaryt authored Apr 25, 2022
2 parents 614c0e5 + c93e219 commit cdc98fe
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 13 deletions.
1 change: 1 addition & 0 deletions .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ workflows:
- gradle/test:
app_src_directory: sample_app
reports_path: sample_app/build/reports/
cache_key: 'v2'
test_results_path: sample_app/build/test-results/
filters: *filters
- orb-tools/pack:
Expand Down
28 changes: 22 additions & 6 deletions src/commands/with_cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,37 @@ parameters:
description: Add a custom suffix to your cache key in the event you need to work with multiple maven caches.
type: string
default: "v1"
cache_checksum_file:
description: File to use to generate the cache checksum, defaults to build.gradle. For example if using Gradle Kotlin DSL then set to build.gradle.kts instead.
deps_checksum_file:
description: File to use to generate the cache checksum for dependencies. Defaults to build.gradle. For example if using Gradle Kotlin DSL then set to build.gradle.kts instead.
type: string
default: "build.gradle"
wrapper_checksum_file:
description: File to use to generate the cache checksum for the gradle wrapper. Defaults to gradlew. For example, if testing on Windows, gradlew.bat should be used instead.
type: string
default: "gradlew"
steps:
- run:
name: Generate Cache Checksum
name: Generate Dependencies Checksum
command: << include(scripts/checksum_files.sh) >>
environment:
PARAM_CHECKSUM_FILES: << parameters.deps_checksum_file>>
CHECKSUM_SEED_LOCATION: "/tmp/gradle_dep_cache_seed"
- run:
name: Generate Wrapper Checksum
command: << include(scripts/checksum_files.sh) >>
environment:
PARAM_CHECKSUM_FILES: << parameters.cache_checksum_file>>
PARAM_CHECKSUM_FILES: << parameters.wrapper_checksum_file>>
CHECKSUM_SEED_LOCATION: "/tmp/gradle_wrapper_cache_seed"
- restore_cache:
key: gradle-<< parameters.cache_key>>-{{ checksum "/tmp/gradle_cache_seed" }}-{{ checksum ".circleci/config.yml" }}
key: gradle-<< parameters.cache_key>>-{{ checksum "/tmp/gradle_dep_cache_seed" }}
- restore_cache:
key: gradle-<< parameters.cache_key>>-{{ checksum "/tmp/gradle_wrapper_cache_seed" }}
- steps: << parameters.steps >>
- save_cache:
paths:
- ~/.gradle/caches
key: gradle-<< parameters.cache_key>>-{{ checksum "/tmp/gradle_dep_cache_seed" }}
- save_cache:
paths:
- ~/.gradle/wrapper
key: gradle-<< parameters.cache_key>>-{{ checksum "/tmp/gradle_cache_seed" }}-{{ checksum ".circleci/config.yml" }}
key: gradle-<< parameters.cache_key>>-{{ checksum "/tmp/gradle_wrapper_cache_seed" }}
11 changes: 8 additions & 3 deletions src/jobs/run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,20 @@ parameters:
description: Add a custom suffix to your cache key in the event you need to work with multiple maven caches.
type: string
default: 'v1'
cache_checksum_file:
description: File to use to generate the cache checksum, defaults to build.gradle. For example if using Gradle Kotlin DSL then set to build.gradle.kts instead.
deps_checksum_file:
description: File to use to generate the cache checksum for dependencies. Defaults to build.gradle. For example if using Gradle Kotlin DSL then set to build.gradle.kts instead.
type: string
default: 'build.gradle'
wrapper_checksum_file:
description: File to use to generate the cache checksum for the gradle wrapper. Defaults to gradlew. For example, if testing on Windows, gradlew.bat should be used instead.
type: string
default: 'gradlew'
steps:
- checkout
- with_cache:
cache_key: << parameters.cache_key >>
cache_checksum_file: << parameters.cache_checksum_file >>
deps_checksum_file: << parameters.deps_checksum_file >>
wrapper_checksum_file: << parameters.wrapper_checksum_file >>
steps:
- run:
working_directory: << parameters.app_src_directory >>
Expand Down
11 changes: 8 additions & 3 deletions src/jobs/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,20 @@ parameters:
description: Add a custom suffix to your cache key in the event you need to work with multiple maven caches.
type: string
default: 'v1'
cache_checksum_file:
description: File to use to generate the cache checksum, defaults to build.gradle. For example if using Gradle Kotlin DSL then set to build.gradle.kts instead.
deps_checksum_file:
description: File to use to generate the cache checksum for dependencies. Defaults to build.gradle. For example if using Gradle Kotlin DSL then set to build.gradle.kts instead.
type: string
default: 'build.gradle'
wrapper_checksum_file:
description: File to use to generate the cache checksum for the gradle wrapper. Defaults to gradlew. For example, if testing on Windows, gradlew.bat should be used instead.
type: string
default: 'gradlew'
steps:
- checkout
- with_cache:
cache_key: << parameters.cache_key >>
cache_checksum_file: << parameters.cache_checksum_file >>
deps_checksum_file: << parameters.deps_checksum_file >>
wrapper_checksum_file: << parameters.wrapper_checksum_file >>
steps:
- run:
name: Run Tests
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/checksum_files.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
find . -name "${PARAM_CHECKSUM_FILES}" | sort | xargs cat | shasum | awk '{print $1}' > /tmp/gradle_cache_seed
find . -name "${PARAM_CHECKSUM_FILES}" | sort | xargs cat | shasum | awk '{print $1}' > "${CHECKSUM_SEED_LOCATION}"

0 comments on commit cdc98fe

Please sign in to comment.