From a76faebd93f5a2c38bb42400ddfe82b6e13ee61d Mon Sep 17 00:00:00 2001 From: Alexandr Evstigneev Date: Sat, 4 Mar 2023 08:35:25 +0400 Subject: [PATCH] Added gradle.properties file to the cache key Part of project configuration may be in the `gradle.properties` file and changing it should invalidate cache See: https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties --- README.md | 2 +- __tests__/cache.test.ts | 10 +++++++++- dist/cleanup/index.js | 3 ++- dist/setup/index.js | 3 ++- src/cache.ts | 3 ++- 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index bd9a411..94a9209 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ Currently, the following distributions are supported: ### Caching packages dependencies The action has a built-in functionality for caching and restoring dependencies. It uses [actions/cache](https://github.com/actions/cache) under hood for caching dependencies but requires less configuration settings. Supported package managers are gradle, maven and sbt. The format of the used cache key is `setup-java-${{ platform }}-${{ packageManager }}-${{ fileHash }}`, where the hash is based on the following files: -- gradle: `**/*.gradle*`, `**/gradle-wrapper.properties`, `buildSrc/**/Versions.kt`, `buildSrc/**/Dependencies.kt`, and `gradle/*.versions.toml` +- gradle: `**/*.gradle*`, `**/gradle-wrapper.properties`, `buildSrc/**/Versions.kt`, `buildSrc/**/Dependencies.kt`, `gradle.properties` and `gradle/*.versions.toml` - maven: `**/pom.xml` - sbt: all sbt build definition files `**/*.sbt`, `**/project/build.properties`, `**/project/**.{scala,sbt}` diff --git a/__tests__/cache.test.ts b/__tests__/cache.test.ts index 987da4a..49a262e 100644 --- a/__tests__/cache.test.ts +++ b/__tests__/cache.test.ts @@ -98,7 +98,7 @@ describe('dependency cache', () => { await expect(restore('gradle')).rejects.toThrowError( `No file in ${projectRoot( workspace - )} matched to [**/*.gradle*,**/gradle-wrapper.properties,buildSrc/**/Versions.kt,buildSrc/**/Dependencies.kt,gradle/*.versions.toml], make sure you have checked out the target repository` + )} matched to [**/*.gradle*,**/gradle-wrapper.properties,buildSrc/**/Versions.kt,buildSrc/**/Dependencies.kt,gradle/*.versions.toml,gradle.properties], make sure you have checked out the target repository` ); }); it('downloads cache based on build.gradle', async () => { @@ -121,6 +121,14 @@ describe('dependency cache', () => { createDirectory(join(workspace, 'gradle')); createFile(join(workspace, 'gradle', 'libs.versions.toml')); + await restore('gradle'); + expect(spyCacheRestore).toBeCalled(); + expect(spyWarning).not.toBeCalled(); + expect(spyInfo).toBeCalledWith('gradle cache is not found'); + }); + it('downloads cache based on gradle.properties', async () => { + createFile(join(workspace, 'gradle.properties')); + await restore('gradle'); expect(spyCacheRestore).toBeCalled(); expect(spyWarning).not.toBeCalled(); diff --git a/dist/cleanup/index.js b/dist/cleanup/index.js index 7a4f37b..d9f74f4 100644 --- a/dist/cleanup/index.js +++ b/dist/cleanup/index.js @@ -68249,7 +68249,8 @@ const supportedPackageManager = [ '**/gradle-wrapper.properties', 'buildSrc/**/Versions.kt', 'buildSrc/**/Dependencies.kt', - 'gradle/*.versions.toml' + 'gradle/*.versions.toml', + 'gradle.properties' ] }, { diff --git a/dist/setup/index.js b/dist/setup/index.js index 20ec26a..db6135c 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -103452,7 +103452,8 @@ const supportedPackageManager = [ '**/gradle-wrapper.properties', 'buildSrc/**/Versions.kt', 'buildSrc/**/Dependencies.kt', - 'gradle/*.versions.toml' + 'gradle/*.versions.toml', + 'gradle.properties' ] }, { diff --git a/src/cache.ts b/src/cache.ts index 20b553e..f4f594b 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -36,7 +36,8 @@ const supportedPackageManager: PackageManager[] = [ '**/gradle-wrapper.properties', 'buildSrc/**/Versions.kt', 'buildSrc/**/Dependencies.kt', - 'gradle/*.versions.toml' + 'gradle/*.versions.toml', + 'gradle.properties' ] }, {