5
0
mirror of https://gitea.com/actions/setup-java.git synced 2026-08-05 02:31:18 +00:00

Add JDK caching

Cache resolved JDK tool-cache entries by exact platform and release identity, with a default-on cache-jdk input and explicit opt-out.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Bruno Borges
2026-08-04 19:02:19 -04:00
parent 60b1ab8234
commit ee3e6d82d3
21 changed files with 1695 additions and 804 deletions
+27
View File
@@ -8,6 +8,7 @@ import {
beforeAll,
afterAll
} from '@jest/globals';
import fs from 'fs';
// Mock @actions/cache before importing source modules
const real_cache_module = await import('@actions/cache');
@@ -163,6 +164,32 @@ describe('cleanup', () => {
expect(spyCacheSave).toHaveBeenCalled();
});
it('saves the JDK cache without dependency caching', async () => {
const key = 'setup-java-jdk-v1-Linux-x64-key';
(core.getInput as jest.Mock).mockReturnValue('');
(core.getState as jest.Mock<any>).mockImplementation((name: string) =>
name === 'jdk-caches'
? JSON.stringify([{key, path: '/toolcache/java'}])
: ''
);
jest.spyOn(fs, 'existsSync').mockReturnValue(true);
spyCacheSave.mockResolvedValue(1);
await cleanup();
expect(spyCacheSave).toHaveBeenCalledWith(['/toolcache/java'], key);
});
it('does not save a JDK cache when cache-jdk is disabled', async () => {
(core.getInput as jest.Mock<any>).mockImplementation((name: string) =>
name === 'cache-jdk' ? 'false' : ''
);
await cleanup();
expect(spyCacheSave).not.toHaveBeenCalled();
});
});
function resetState() {