Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat!: Split Wrapper and Deps Caches #15

Merged
merged 4 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}"