Skip to content

Commit ca584e7

Browse files
authored
Merge pull request #1 from schuenadel/include-buildSrc-in-cache-key
Include *.kt files in buildSrc in cache key
2 parents a12e082 + 69e9330 commit ca584e7

File tree

5 files changed

+29
-5
lines changed

5 files changed

+29
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Currently, the following distributions are supported:
6767

6868
### Caching packages dependencies
6969
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:
70-
- gradle: `**/*.gradle*`, `**/gradle-wrapper.properties`
70+
- gradle: `**/*.gradle*`, `**/gradle-wrapper.properties`, `buildSrc/**/*.kt`
7171
- maven: `**/pom.xml`
7272

7373
The cache input is optional, and caching is turned off by default.

__tests__/cache.test.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ describe('dependency cache', () => {
9898
await expect(restore('gradle')).rejects.toThrowError(
9999
`No file in ${projectRoot(
100100
workspace
101-
)} matched to [**/*.gradle*,**/gradle-wrapper.properties], make sure you have checked out the target repository`
101+
)} matched to [**/*.gradle*,**/gradle-wrapper.properties,buildSrc/**/*.kt], make sure you have checked out the target repository`
102102
);
103103
});
104104
it('downloads cache based on build.gradle', async () => {
@@ -118,6 +118,15 @@ describe('dependency cache', () => {
118118
expect(spyInfo).toBeCalledWith('gradle cache is not found');
119119
});
120120
});
121+
it('downloads cache based on buildSrc/Versions.kt', async () => {
122+
createDirectory(join(workspace, 'buildSrc'));
123+
createFile(join(workspace, 'buildSrc', 'Versions.kt'));
124+
125+
await restore('gradle');
126+
expect(spyCacheRestore).toBeCalled();
127+
expect(spyWarning).not.toBeCalled();
128+
expect(spyInfo).toBeCalledWith('gradle cache is not found');
129+
});
121130
});
122131
describe('save', () => {
123132
let spyCacheSave: jest.SpyInstance<
@@ -188,6 +197,16 @@ describe('dependency cache', () => {
188197
createFile(join(workspace, 'build.gradle.kts'));
189198
createStateForSuccessfulRestore();
190199

200+
await save('gradle');
201+
expect(spyCacheSave).toBeCalled();
202+
expect(spyWarning).not.toBeCalled();
203+
expect(spyInfo).toBeCalledWith(expect.stringMatching(/^Cache saved with the key:.*/));
204+
});
205+
it('uploads cache based on buildSrc/Versions.kt', async () => {
206+
createDirectory(join(workspace, 'buildSrc'));
207+
createFile(join(workspace, 'buildSrc', 'Versions.kt'));
208+
createStateForSuccessfulRestore();
209+
191210
await save('gradle');
192211
expect(spyCacheSave).toBeCalled();
193212
expect(spyWarning).not.toBeCalled();
@@ -236,6 +255,11 @@ function createFile(path: string) {
236255
fs.writeFileSync(path, '');
237256
}
238257

258+
function createDirectory(path: string) {
259+
core.info(`created a directory at ${path}`);
260+
fs.mkdirSync(path);
261+
}
262+
239263
function projectRoot(workspace: string): string {
240264
if (os.platform() === 'darwin') {
241265
return `/private${workspace}`;

dist/cleanup/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61833,7 +61833,7 @@ const supportedPackageManager = [
6183361833
id: 'gradle',
6183461834
path: [path_1.join(os_1.default.homedir(), '.gradle', 'caches'), path_1.join(os_1.default.homedir(), '.gradle', 'wrapper')],
6183561835
// https://github.com/actions/cache/blob/0638051e9af2c23d10bb70fa9beffcad6cff9ce3/examples.md#java---gradle
61836-
pattern: ['**/*.gradle*', '**/gradle-wrapper.properties']
61836+
pattern: ['**/*.gradle*', '**/gradle-wrapper.properties', 'buildSrc/**/*.kt']
6183761837
}
6183861838
];
6183961839
function findPackageManager(id) {

dist/setup/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18624,7 +18624,7 @@ const supportedPackageManager = [
1862418624
id: 'gradle',
1862518625
path: [path_1.join(os_1.default.homedir(), '.gradle', 'caches'), path_1.join(os_1.default.homedir(), '.gradle', 'wrapper')],
1862618626
// https://github.com/actions/cache/blob/0638051e9af2c23d10bb70fa9beffcad6cff9ce3/examples.md#java---gradle
18627-
pattern: ['**/*.gradle*', '**/gradle-wrapper.properties']
18627+
pattern: ['**/*.gradle*', '**/gradle-wrapper.properties', 'buildSrc/**/*.kt']
1862818628
}
1862918629
];
1863018630
function findPackageManager(id) {

src/cache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const supportedPackageManager: PackageManager[] = [
3131
id: 'gradle',
3232
path: [join(os.homedir(), '.gradle', 'caches'), join(os.homedir(), '.gradle', 'wrapper')],
3333
// https://github.com/actions/cache/blob/0638051e9af2c23d10bb70fa9beffcad6cff9ce3/examples.md#java---gradle
34-
pattern: ['**/*.gradle*', '**/gradle-wrapper.properties']
34+
pattern: ['**/*.gradle*', '**/gradle-wrapper.properties', 'buildSrc/**/*.kt']
3535
}
3636
];
3737

0 commit comments

Comments
 (0)