From cc7a29482dd781f95dd0e8698a79248f02ee1658 Mon Sep 17 00:00:00 2001 From: Vladimir Sitnikov Date: Fri, 7 Aug 2020 16:04:20 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20add=20gradle-dependencies-cache-key?= =?UTF-8?q?=20property=20for=20configuring=20extra=20dependencies=20(e.g.?= =?UTF-8?q?=20versions=20declared=20in=20buildSrc/Versions.kt)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 +++++ action.yml | 12 ++++++++++++ .../com/github/burrunan/gradle/GradleCacheAction.kt | 2 +- src/main/kotlin/com/github/burrunan/gradle/Main.kt | 1 + .../kotlin/com/github/burrunan/gradle/Parameters.kt | 1 + .../burrunan/gradle/cache/dependenciesCache.kt | 7 +++++-- 6 files changed, 25 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1f29614..04cd8c4 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,11 @@ The default configuration should suit for most of the cases, however, there are # Disable caching of ~/.gradle/caches/modules-* save-gradle-dependencies-cache: false + # Extra files to take into account for ~/.gradle/caches dependencies + gradle-dependencies-cache-key: | + gradle/dependencies.kt + buildSrc/**/Version.kt + # Disable caching of ~/.m2/repository/ save-maven-dependencies-cache: false diff --git a/action.yml b/action.yml index 045dbf1..cf2ae04 100644 --- a/action.yml +++ b/action.yml @@ -11,6 +11,18 @@ inputs: gradle-version: description: (wrapper | or explicit version) Caches often depend on the Gradle version, so this parameter sets the ID to use for cache keys. It does not affect the Gradle version used for build required: false + save-generated-gradle-jars: + description: Enables caching of $HOME/.gradle/caches/*.*/generated-gradle-jars + required: false + save-gradle-dependencies-cache: + description: Enables caching of ~/.gradle/caches/modules-* + required: false + gradle-dependencies-cache-key: + description: Extra files to take into account for ~/.gradle/caches dependencies + required: false + save-maven-dependencies-cache: + description: Enables caching of ~/.m2/repository/ + required: false debug: description: Shows extra logging to debug the action required: false diff --git a/src/main/kotlin/com/github/burrunan/gradle/GradleCacheAction.kt b/src/main/kotlin/com/github/burrunan/gradle/GradleCacheAction.kt index acdb7f7..d6ceed7 100644 --- a/src/main/kotlin/com/github/burrunan/gradle/GradleCacheAction.kt +++ b/src/main/kotlin/com/github/burrunan/gradle/GradleCacheAction.kt @@ -46,7 +46,7 @@ class GradleCacheAction(val trigger: ActionsTrigger, val params: Parameters) { } if (params.gradleDependenciesCache) { - caches.add(gradleDependenciesCache(trigger, params.path)) + caches.add(gradleDependenciesCache(trigger, params.path, params.gradleDependenciesCacheKey)) } if (params.mavenDependenciesCache) { diff --git a/src/main/kotlin/com/github/burrunan/gradle/Main.kt b/src/main/kotlin/com/github/burrunan/gradle/Main.kt index 61f70a5..4097b26 100644 --- a/src/main/kotlin/com/github/burrunan/gradle/Main.kt +++ b/src/main/kotlin/com/github/burrunan/gradle/Main.kt @@ -31,6 +31,7 @@ suspend fun main() { generatedGradleJars = getInput("save-generated-gradle-jars").ifBlank { "true" }.toBoolean(), localBuildCache = getInput("save-local-build-cache").ifBlank { "true" }.toBoolean(), gradleDependenciesCache = getInput("save-gradle-dependencies-cache").ifBlank { "true" }.toBoolean(), + gradleDependenciesCacheKey = getInput("gradle-dependencies-cache-key"), mavenDependenciesCache = getInput("save-maven-dependencies-cache").ifBlank { "true" }.toBoolean(), concurrent = getInput("concurrent").ifBlank { "false" }.toBoolean(), ) diff --git a/src/main/kotlin/com/github/burrunan/gradle/Parameters.kt b/src/main/kotlin/com/github/burrunan/gradle/Parameters.kt index 1f4caa3..d3ec9a5 100644 --- a/src/main/kotlin/com/github/burrunan/gradle/Parameters.kt +++ b/src/main/kotlin/com/github/burrunan/gradle/Parameters.kt @@ -23,6 +23,7 @@ data class Parameters( val generatedGradleJars: Boolean, val localBuildCache: Boolean, val gradleDependenciesCache: Boolean, + val gradleDependenciesCacheKey: String, val mavenDependenciesCache: Boolean, val concurrent: Boolean, ) diff --git a/src/main/kotlin/com/github/burrunan/gradle/cache/dependenciesCache.kt b/src/main/kotlin/com/github/burrunan/gradle/cache/dependenciesCache.kt index 9f6dbf8..c2b37c8 100644 --- a/src/main/kotlin/com/github/burrunan/gradle/cache/dependenciesCache.kt +++ b/src/main/kotlin/com/github/burrunan/gradle/cache/dependenciesCache.kt @@ -38,7 +38,7 @@ suspend fun dependenciesCache( ) } -suspend fun gradleDependenciesCache(trigger: ActionsTrigger, path: String): Cache = +suspend fun gradleDependenciesCache(trigger: ActionsTrigger, path: String, gradleDependenciesCacheKey: String): Cache = dependenciesCache( "gradle", trigger, @@ -54,7 +54,10 @@ suspend fun gradleDependenciesCache(trigger: ActionsTrigger, path: String): Cach // We do not want .gradle folder, so we want to have at least one character before .gradle "$path/**/?*.gradle", "$path/**/*.properties", - ), + ) + gradleDependenciesCacheKey.split(Regex("[\r\n]+")).map { + (if (it.startsWith("!")) "!" else "") + + "$path/**/" + it.trim().trimStart('!') + }, ) suspend fun mavenDependenciesCache(trigger: ActionsTrigger, path: String): Cache =