mirror of
https://github.com/actions/setup-java.git
synced 2025-03-13 17:47:03 +00:00
Add versions properties to cache
This commit is contained in:
parent
a12e082d83
commit
8a9565d983
5 changed files with 67 additions and 51 deletions
|
@ -67,7 +67,7 @@ Currently, the following distributions are supported:
|
||||||
|
|
||||||
### Caching packages dependencies
|
### 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:
|
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`, `**/versions.properties`
|
||||||
- maven: `**/pom.xml`
|
- maven: `**/pom.xml`
|
||||||
|
|
||||||
The cache input is optional, and caching is turned off by default.
|
The cache input is optional, and caching is turned off by default.
|
||||||
|
|
|
@ -98,7 +98,7 @@ describe('dependency cache', () => {
|
||||||
await expect(restore('gradle')).rejects.toThrowError(
|
await expect(restore('gradle')).rejects.toThrowError(
|
||||||
`No file in ${projectRoot(
|
`No file in ${projectRoot(
|
||||||
workspace
|
workspace
|
||||||
)} matched to [**/*.gradle*,**/gradle-wrapper.properties], make sure you have checked out the target repository`
|
)} matched to [**/*.gradle*,**/gradle-wrapper.properties, versions.properties], make sure you have checked out the target repository`
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
it('downloads cache based on build.gradle', async () => {
|
it('downloads cache based on build.gradle', async () => {
|
||||||
|
@ -118,6 +118,14 @@ describe('dependency cache', () => {
|
||||||
expect(spyInfo).toBeCalledWith('gradle cache is not found');
|
expect(spyInfo).toBeCalledWith('gradle cache is not found');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
it('downloads cache based on versions.properties', async () => {
|
||||||
|
createFile(join(workspace, 'versions.properties'));
|
||||||
|
|
||||||
|
await restore('gradle');
|
||||||
|
expect(spyCacheRestore).toBeCalled();
|
||||||
|
expect(spyWarning).not.toBeCalled();
|
||||||
|
expect(spyInfo).toBeCalledWith('gradle cache is not found');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
describe('save', () => {
|
describe('save', () => {
|
||||||
let spyCacheSave: jest.SpyInstance<
|
let spyCacheSave: jest.SpyInstance<
|
||||||
|
@ -193,18 +201,26 @@ describe('dependency cache', () => {
|
||||||
expect(spyWarning).not.toBeCalled();
|
expect(spyWarning).not.toBeCalled();
|
||||||
expect(spyInfo).toBeCalledWith(expect.stringMatching(/^Cache saved with the key:.*/));
|
expect(spyInfo).toBeCalledWith(expect.stringMatching(/^Cache saved with the key:.*/));
|
||||||
});
|
});
|
||||||
});
|
it('uploads cache based on versions.properties', async () => {
|
||||||
});
|
createFile(join(workspace, 'versions.properties'));
|
||||||
});
|
createStateForSuccessfulRestore();
|
||||||
|
|
||||||
function resetState() {
|
await save('gradle');
|
||||||
|
expect(spyCacheSave).toBeCalled();
|
||||||
|
expect(spyWarning).not.toBeCalled();
|
||||||
|
expect(spyInfo).toBeCalledWith(expect.stringMatching(/^Cache saved with the key:.*/));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function resetState() {
|
||||||
jest.spyOn(core, 'getState').mockReset();
|
jest.spyOn(core, 'getState').mockReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create states to emulate a restore process without build file.
|
* Create states to emulate a restore process without build file.
|
||||||
*/
|
*/
|
||||||
function createStateForMissingBuildFile() {
|
function createStateForMissingBuildFile() {
|
||||||
jest.spyOn(core, 'getState').mockImplementation(name => {
|
jest.spyOn(core, 'getState').mockImplementation(name => {
|
||||||
switch (name) {
|
switch (name) {
|
||||||
case 'cache-primary-key':
|
case 'cache-primary-key':
|
||||||
|
@ -213,12 +229,12 @@ function createStateForMissingBuildFile() {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create states to emulate a successful restore process.
|
* Create states to emulate a successful restore process.
|
||||||
*/
|
*/
|
||||||
function createStateForSuccessfulRestore() {
|
function createStateForSuccessfulRestore() {
|
||||||
jest.spyOn(core, 'getState').mockImplementation(name => {
|
jest.spyOn(core, 'getState').mockImplementation(name => {
|
||||||
switch (name) {
|
switch (name) {
|
||||||
case 'cache-primary-key':
|
case 'cache-primary-key':
|
||||||
|
@ -229,17 +245,17 @@ function createStateForSuccessfulRestore() {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function createFile(path: string) {
|
function createFile(path: string) {
|
||||||
core.info(`created a file at ${path}`);
|
core.info(`created a file at ${path}`);
|
||||||
fs.writeFileSync(path, '');
|
fs.writeFileSync(path, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
function projectRoot(workspace: string): string {
|
function projectRoot(workspace: string): string {
|
||||||
if (os.platform() === 'darwin') {
|
if (os.platform() === 'darwin') {
|
||||||
return `/private${workspace}`;
|
return `/private${workspace}`;
|
||||||
} else {
|
} else {
|
||||||
return workspace;
|
return workspace;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2
dist/cleanup/index.js
vendored
2
dist/cleanup/index.js
vendored
|
@ -61833,7 +61833,7 @@ const supportedPackageManager = [
|
||||||
id: 'gradle',
|
id: 'gradle',
|
||||||
path: [path_1.join(os_1.default.homedir(), '.gradle', 'caches'), path_1.join(os_1.default.homedir(), '.gradle', 'wrapper')],
|
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
|
// https://github.com/actions/cache/blob/0638051e9af2c23d10bb70fa9beffcad6cff9ce3/examples.md#java---gradle
|
||||||
pattern: ['**/*.gradle*', '**/gradle-wrapper.properties']
|
pattern: ['**/*.gradle*', '**/gradle-wrapper.properties', '**/versions.properties']
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
function findPackageManager(id) {
|
function findPackageManager(id) {
|
||||||
|
|
2
dist/setup/index.js
vendored
2
dist/setup/index.js
vendored
|
@ -18624,7 +18624,7 @@ const supportedPackageManager = [
|
||||||
id: 'gradle',
|
id: 'gradle',
|
||||||
path: [path_1.join(os_1.default.homedir(), '.gradle', 'caches'), path_1.join(os_1.default.homedir(), '.gradle', 'wrapper')],
|
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
|
// https://github.com/actions/cache/blob/0638051e9af2c23d10bb70fa9beffcad6cff9ce3/examples.md#java---gradle
|
||||||
pattern: ['**/*.gradle*', '**/gradle-wrapper.properties']
|
pattern: ['**/*.gradle*', '**/gradle-wrapper.properties', '**/versions.properties']
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
function findPackageManager(id) {
|
function findPackageManager(id) {
|
||||||
|
|
|
@ -31,7 +31,7 @@ const supportedPackageManager: PackageManager[] = [
|
||||||
id: 'gradle',
|
id: 'gradle',
|
||||||
path: [join(os.homedir(), '.gradle', 'caches'), join(os.homedir(), '.gradle', 'wrapper')],
|
path: [join(os.homedir(), '.gradle', 'caches'), join(os.homedir(), '.gradle', 'wrapper')],
|
||||||
// https://github.com/actions/cache/blob/0638051e9af2c23d10bb70fa9beffcad6cff9ce3/examples.md#java---gradle
|
// https://github.com/actions/cache/blob/0638051e9af2c23d10bb70fa9beffcad6cff9ce3/examples.md#java---gradle
|
||||||
pattern: ['**/*.gradle*', '**/gradle-wrapper.properties']
|
pattern: ['**/*.gradle*', '**/gradle-wrapper.properties', '**/versions.properties']
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue