mirror of
https://github.com/actions/setup-java.git
synced 2026-07-29 21:16:26 +00:00
Skip optional Maven and Gradle wrapper cache saves when their distribution paths do not exist, while allowing the main dependency cache to save. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: c0b19ff2-ef52-4ac1-a832-0f8f72c43219
This commit is contained in:
+54
-9
@@ -377,6 +377,10 @@ describe('dependency cache', () => {
|
||||
ReturnType<typeof cache.saveCache>,
|
||||
Parameters<typeof cache.saveCache>
|
||||
>;
|
||||
let spyGlobCreate: jest.SpyInstance<
|
||||
ReturnType<typeof glob.create>,
|
||||
Parameters<typeof glob.create>
|
||||
>;
|
||||
|
||||
beforeEach(() => {
|
||||
spyCacheSave = jest
|
||||
@@ -384,6 +388,9 @@ describe('dependency cache', () => {
|
||||
.mockImplementation((paths: string[], key: string) =>
|
||||
Promise.resolve(0)
|
||||
);
|
||||
spyGlobCreate = jest
|
||||
.spyOn(glob, 'create')
|
||||
.mockResolvedValue(createGlobber(['wrapper-path']));
|
||||
spyWarning.mockImplementation(() => null);
|
||||
});
|
||||
|
||||
@@ -469,17 +476,24 @@ describe('dependency cache', () => {
|
||||
});
|
||||
it('does not fail the post step when the wrapper distribution path is missing', async () => {
|
||||
createFile(join(workspace, 'pom.xml'));
|
||||
createDirectory(join(workspace, '.mvn'));
|
||||
createDirectory(join(workspace, '.mvn', 'wrapper'));
|
||||
createFile(
|
||||
join(workspace, '.mvn', 'wrapper', 'maven-wrapper.properties')
|
||||
);
|
||||
createStateForWrapperRestore('maven-wrapper', false);
|
||||
spyCacheSave.mockImplementation((paths: string[], key: string) => {
|
||||
if (paths.includes(join(os.homedir(), '.m2', 'wrapper', 'dists'))) {
|
||||
return Promise.reject(
|
||||
new cache.ValidationError('Path Validation Error')
|
||||
);
|
||||
}
|
||||
return Promise.resolve(0);
|
||||
});
|
||||
spyGlobCreate.mockResolvedValue(createGlobber([]));
|
||||
|
||||
await expect(save('maven')).resolves.not.toThrow();
|
||||
await expect(save('maven')).resolves.toBeUndefined();
|
||||
expect(spyCacheSave).not.toHaveBeenCalledWith(
|
||||
[join(os.homedir(), '.m2', 'wrapper', 'dists')],
|
||||
expect.any(String)
|
||||
);
|
||||
expect(spyCacheSave).toHaveBeenCalledWith(
|
||||
[join(os.homedir(), '.m2', 'repository')],
|
||||
'setup-java-cache-primary-key'
|
||||
);
|
||||
expect(spyWarning).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
describe('for gradle', () => {
|
||||
@@ -553,6 +567,23 @@ describe('dependency cache', () => {
|
||||
expect.any(String)
|
||||
);
|
||||
});
|
||||
it('does not fail the post step when the wrapper distribution path is missing', async () => {
|
||||
createFile(join(workspace, 'build.gradle'));
|
||||
createFile(join(workspace, 'gradle-wrapper.properties'));
|
||||
createStateForWrapperRestore('gradle-wrapper', false);
|
||||
spyGlobCreate.mockResolvedValue(createGlobber([]));
|
||||
|
||||
await expect(save('gradle')).resolves.toBeUndefined();
|
||||
expect(spyCacheSave).not.toHaveBeenCalledWith(
|
||||
[join(os.homedir(), '.gradle', 'wrapper')],
|
||||
expect.any(String)
|
||||
);
|
||||
expect(spyCacheSave).toHaveBeenCalledWith(
|
||||
[join(os.homedir(), '.gradle', 'caches')],
|
||||
'setup-java-cache-primary-key'
|
||||
);
|
||||
expect(spyWarning).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
describe('for sbt', () => {
|
||||
it('uploads cache even if no build.sbt found', async () => {
|
||||
@@ -663,6 +694,20 @@ function createDirectory(path: string) {
|
||||
fs.mkdirSync(path);
|
||||
}
|
||||
|
||||
function createGlobber(
|
||||
paths: string[]
|
||||
): Awaited<ReturnType<typeof glob.create>> {
|
||||
return {
|
||||
getSearchPaths: () => [],
|
||||
glob: () => Promise.resolve(paths),
|
||||
globGenerator: async function* () {
|
||||
for (const path of paths) {
|
||||
yield path;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function projectRoot(workspace: string): string {
|
||||
if (os.platform() === 'darwin') {
|
||||
return `/private${workspace}`;
|
||||
|
||||
Reference in New Issue
Block a user