From 404e5db3a1a0925ad4d751e6acd2a5b18f52db3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Do=C4=9Fa=C3=A7=20Eldenk?= Date: Mon, 10 Apr 2023 10:56:26 +0300 Subject: [PATCH] fix sbt/scala cache key (#478) --- README.md | 2 +- __tests__/cache.test.ts | 24 +++++++++++++++++++++++- dist/cleanup/index.js | 3 ++- dist/setup/index.js | 3 ++- src/cache.ts | 3 ++- 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c174abe..ced5928 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ Currently, the following distributions are supported: 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` - maven: `**/pom.xml` -- sbt: all sbt build definition files `**/*.sbt`, `**/project/build.properties`, `**/project/**.{scala,sbt}` +- sbt: all sbt build definition files `**/*.sbt`, `**/project/build.properties`, `**/project/**.scala`, `**/project/**.sbt` The workflow output `cache-hit` is set to indicate if an exact match was found for the key [as actions/cache does](https://github.com/actions/cache/tree/main#outputs). diff --git a/__tests__/cache.test.ts b/__tests__/cache.test.ts index 8bcb635..ae56844 100644 --- a/__tests__/cache.test.ts +++ b/__tests__/cache.test.ts @@ -145,7 +145,7 @@ describe('dependency cache', () => { await expect(restore('sbt')).rejects.toThrow( `No file in ${projectRoot( workspace - )} matched to [**/*.sbt,**/project/build.properties,**/project/**.{scala,sbt}], make sure you have checked out the target repository` + )} matched to [**/*.sbt,**/project/build.properties,**/project/**.scala,**/project/**.sbt], make sure you have checked out the target repository` ); }); it('downloads cache', async () => { @@ -156,6 +156,28 @@ describe('dependency cache', () => { expect(spyWarning).not.toHaveBeenCalled(); expect(spyInfo).toHaveBeenCalledWith('sbt cache is not found'); }); + it('detects scala and sbt changes under **/project/ folder', async () => { + createFile(join(workspace, 'build.sbt')); + createDirectory(join(workspace, 'project')); + createFile(join(workspace, 'project/DependenciesV1.scala')); + + await restore('sbt'); + const firstCall = spySaveState.mock.calls.toString(); + + spySaveState.mockClear(); + await restore('sbt'); + const secondCall = spySaveState.mock.calls.toString(); + + // Make sure multiple restores produce the same cache + expect(firstCall).toBe(secondCall); + + spySaveState.mockClear(); + createFile(join(workspace, 'project/DependenciesV2.scala')); + await restore('sbt'); + const thirdCall = spySaveState.mock.calls.toString(); + + expect(firstCall).not.toBe(thirdCall); + }); }); }); describe('save', () => { diff --git a/dist/cleanup/index.js b/dist/cleanup/index.js index 4481094..62202e5 100644 --- a/dist/cleanup/index.js +++ b/dist/cleanup/index.js @@ -68416,7 +68416,8 @@ const supportedPackageManager = [ pattern: [ '**/*.sbt', '**/project/build.properties', - '**/project/**.{scala,sbt}' + '**/project/**.scala', + '**/project/**.sbt' ] } ]; diff --git a/dist/setup/index.js b/dist/setup/index.js index b930883..3f6eccc 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -103621,7 +103621,8 @@ const supportedPackageManager = [ pattern: [ '**/*.sbt', '**/project/build.properties', - '**/project/**.{scala,sbt}' + '**/project/**.scala', + '**/project/**.sbt' ] } ]; diff --git a/src/cache.ts b/src/cache.ts index 81d0b27..4d37664 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -56,7 +56,8 @@ const supportedPackageManager: PackageManager[] = [ pattern: [ '**/*.sbt', '**/project/build.properties', - '**/project/**.{scala,sbt}' + '**/project/**.scala', + '**/project/**.sbt' ] } ];