From 249cbde4651af34d819ad81f620b23687c52501a Mon Sep 17 00:00:00 2001 From: Jaryt Bustard Date: Fri, 22 Apr 2022 18:43:49 -0400 Subject: [PATCH 1/4] feat!: Split deps and wrapper cache --- src/commands/with_cache.yml | 24 ++++++++++++++++++++---- src/scripts/checksum_files.sh | 2 +- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/commands/with_cache.yml b/src/commands/with_cache.yml index 7745033..68006c3 100755 --- a/src/commands/with_cache.yml +++ b/src/commands/with_cache.yml @@ -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: + deps_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. type: string default: "build.gradle" + wrapper_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. + 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.cache_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>> + CHECKSUM_SEED_LOCATION: "/tmp/gradle_wrapper_cache_seed" + - restore_cache: + key: gradle-<< parameters.cache_key>>-{{ checksum "/tmp/gradle_dep_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_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" }} diff --git a/src/scripts/checksum_files.sh b/src/scripts/checksum_files.sh index 4ecbfa0..36a0d8c 100644 --- a/src/scripts/checksum_files.sh +++ b/src/scripts/checksum_files.sh @@ -1 +1 @@ -find . -name "${PARAM_CHECKSUM_FILES}" | sort | xargs cat | shasum | awk '{print $1}' > /tmp/gradle_cache_seed \ No newline at end of file +find . -name "${PARAM_CHECKSUM_FILES}" | sort | xargs cat | shasum | awk '{print $1}' > "${CHECKSUM_SEED_LOCATION}" From 2c7c2b47dba7df135f29ddabca6faffdebf93872 Mon Sep 17 00:00:00 2001 From: Jaryt Bustard Date: Fri, 22 Apr 2022 18:52:11 -0400 Subject: [PATCH 2/4] feat: update job with_cache usage --- src/commands/with_cache.yml | 4 ++-- src/jobs/run.yml | 11 ++++++++--- src/jobs/test.yml | 11 ++++++++--- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/commands/with_cache.yml b/src/commands/with_cache.yml index 68006c3..9502f4e 100755 --- a/src/commands/with_cache.yml +++ b/src/commands/with_cache.yml @@ -15,11 +15,11 @@ parameters: type: string default: "v1" deps_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. + 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, defaults to build.gradle. For example if using Gradle Kotlin DSL then set to build.gradle.kts instead. + 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: diff --git a/src/jobs/run.yml b/src/jobs/run.yml index 74268db..d31623b 100755 --- a/src/jobs/run.yml +++ b/src/jobs/run.yml @@ -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 >> diff --git a/src/jobs/test.yml b/src/jobs/test.yml index c8c4d56..9299ddb 100755 --- a/src/jobs/test.yml +++ b/src/jobs/test.yml @@ -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 From 5ad68de9806f82a56f1f50c15c973af5413967d3 Mon Sep 17 00:00:00 2001 From: Jaryt Bustard Date: Fri, 22 Apr 2022 18:53:36 -0400 Subject: [PATCH 3/4] fix: update parameters --- src/commands/with_cache.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/commands/with_cache.yml b/src/commands/with_cache.yml index 9502f4e..488a510 100755 --- a/src/commands/with_cache.yml +++ b/src/commands/with_cache.yml @@ -27,13 +27,13 @@ steps: name: Generate Dependencies Checksum command: << include(scripts/checksum_files.sh) >> environment: - PARAM_CHECKSUM_FILES: << parameters.cache_checksum_file>> + 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_dep_cache_seed" }} From c93e219bfc3064b7238ba4593f5d497bdd00f89c Mon Sep 17 00:00:00 2001 From: Jaryt Bustard Date: Fri, 22 Apr 2022 18:56:27 -0400 Subject: [PATCH 4/4] ci: update cache key --- .circleci/test-deploy.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/test-deploy.yml b/.circleci/test-deploy.yml index c61a933..7515846 100644 --- a/.circleci/test-deploy.yml +++ b/.circleci/test-deploy.yml @@ -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: