From 69e93308b0146fab1513037e4b28c5bdb209243d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20Sch=C3=BCnadel?= Date: Wed, 12 Jan 2022 14:43:15 +0100 Subject: [PATCH] Include *.kt files in buildSrc in cache key --- README.md | 2 +- __tests__/cache.test.ts | 26 +++++++++++++++++++++++++- dist/cleanup/index.js | 2 +- dist/setup/index.js | 2 +- src/cache.ts | 2 +- 5 files changed, 29 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c02eb6c..0dbf3fa 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,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 and maven. 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` +- gradle: `**/*.gradle*`, `**/gradle-wrapper.properties`, `buildSrc/**/*.kt` - maven: `**/pom.xml` The cache input is optional, and caching is turned off by default. diff --git a/__tests__/cache.test.ts b/__tests__/cache.test.ts index b748e80..ab058de 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], make sure you have checked out the target repository` + )} matched to [**/*.gradle*,**/gradle-wrapper.properties,buildSrc/**/*.kt], make sure you have checked out the target repository` ); }); it('downloads cache based on build.gradle', async () => { @@ -118,6 +118,15 @@ describe('dependency cache', () => { expect(spyInfo).toBeCalledWith('gradle cache is not found'); }); }); + it('downloads cache based on buildSrc/Versions.kt', async () => { + createDirectory(join(workspace, 'buildSrc')); + createFile(join(workspace, 'buildSrc', 'Versions.kt')); + + await restore('gradle'); + expect(spyCacheRestore).toBeCalled(); + expect(spyWarning).not.toBeCalled(); + expect(spyInfo).toBeCalledWith('gradle cache is not found'); + }); }); describe('save', () => { let spyCacheSave: jest.SpyInstance< @@ -188,6 +197,16 @@ describe('dependency cache', () => { createFile(join(workspace, 'build.gradle.kts')); createStateForSuccessfulRestore(); + await save('gradle'); + expect(spyCacheSave).toBeCalled(); + expect(spyWarning).not.toBeCalled(); + expect(spyInfo).toBeCalledWith(expect.stringMatching(/^Cache saved with the key:.*/)); + }); + it('uploads cache based on buildSrc/Versions.kt', async () => { + createDirectory(join(workspace, 'buildSrc')); + createFile(join(workspace, 'buildSrc', 'Versions.kt')); + createStateForSuccessfulRestore(); + await save('gradle'); expect(spyCacheSave).toBeCalled(); expect(spyWarning).not.toBeCalled(); @@ -236,6 +255,11 @@ function createFile(path: string) { fs.writeFileSync(path, ''); } +function createDirectory(path: string) { + core.info(`created a directory at ${path}`); + fs.mkdirSync(path); +} + function projectRoot(workspace: string): string { if (os.platform() === 'darwin') { return `/private${workspace}`; diff --git a/dist/cleanup/index.js b/dist/cleanup/index.js index 0a20472..c51cb6f 100644 --- a/dist/cleanup/index.js +++ b/dist/cleanup/index.js @@ -61833,7 +61833,7 @@ const supportedPackageManager = [ id: 'gradle', path: [path_1.join(os_1.default.homedir(), '.gradle', 'caches'), path_1.join(os_1.default.homedir(), '.gradle', 'wrapper')], // https://github.com/actions/cache/blob/0638051e9af2c23d10bb70fa9beffcad6cff9ce3/examples.md#java---gradle - pattern: ['**/*.gradle*', '**/gradle-wrapper.properties'] + pattern: ['**/*.gradle*', '**/gradle-wrapper.properties', 'buildSrc/**/*.kt'] } ]; function findPackageManager(id) { diff --git a/dist/setup/index.js b/dist/setup/index.js index 34b866d..f8f1bd7 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -18624,7 +18624,7 @@ const supportedPackageManager = [ id: 'gradle', path: [path_1.join(os_1.default.homedir(), '.gradle', 'caches'), path_1.join(os_1.default.homedir(), '.gradle', 'wrapper')], // https://github.com/actions/cache/blob/0638051e9af2c23d10bb70fa9beffcad6cff9ce3/examples.md#java---gradle - pattern: ['**/*.gradle*', '**/gradle-wrapper.properties'] + pattern: ['**/*.gradle*', '**/gradle-wrapper.properties', 'buildSrc/**/*.kt'] } ]; function findPackageManager(id) { diff --git a/src/cache.ts b/src/cache.ts index fb97fb0..c9a728b 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -31,7 +31,7 @@ const supportedPackageManager: PackageManager[] = [ id: 'gradle', path: [join(os.homedir(), '.gradle', 'caches'), join(os.homedir(), '.gradle', 'wrapper')], // https://github.com/actions/cache/blob/0638051e9af2c23d10bb70fa9beffcad6cff9ce3/examples.md#java---gradle - pattern: ['**/*.gradle*', '**/gradle-wrapper.properties'] + pattern: ['**/*.gradle*', '**/gradle-wrapper.properties', 'buildSrc/**/*.kt'] } ];