mirror of
https://github.com/actions/setup-java.git
synced 2026-08-05 17:02:57 +00:00
955f34f16f
* 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> * Apply batched suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Fix JDK cache CI validation Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Update brace-expansion security fix Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Refresh brace-expansion license metadata Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Refine JDK cache semantics Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Refine JDK cache documentation Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Simplify JDK cache identity Use one normalized runner OS dimension, reset the internal cache key schema for the unreleased feature, and align documentation, tests, and bundles. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Align JDK cache OS identity Use the established RUNNER_OS value directly and retain process.platform only as a non-Actions fallback. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Harden JDK cache saves and document tool-cache reuse Bind each JDK cache key to the installation identity it was computed for, keep post-job saves best-effort per entry, and state the real reuse and verification guarantee in the documentation. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * docs: restructure README caching section Rename '## Caching dependencies' to '## Caching' and add a what-gets-cached overview table covering the dependency, wrapper, and JDK caches. Lead with the common 'cache: maven' example and the dependency-cache material, and demote JDK caching into its own subsection. Also corrects the IMPORTANT callout, which implied JDK caching required an explicit opt-in; it is enabled implicitly whenever 'cache' is set. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * docs: fix caching documentation defects - Remove pull-request framing that compared behavior to `main`; state the tool-cache and `jdkfile` behavior directly and unconditionally. - Clarify that the JDK cache is a separate cache *entry* from the dependency and wrapper caches, while its *enablement* is coupled to `cache`, so the opening paragraph agrees with the enablement matrix. - Cite the actions/setup-java-benchmarks repository instead of an open PR and a self-referential PR comment, keeping the measured figures and caveats. - Keep the `cache`/`cache-jdk` matrix only in docs/advanced-usage.md and summarize the rules in prose in README.md to avoid divergence. - Describe the guarantee that a cache key is only saved with the installation it was computed for, instead of documenting inode/size/timestamp internals. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * docs: add V6 what's new entry for JDK caching Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e2755464-4e83-47b6-ba71-731bb481b418 --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Copilot-Session: e2755464-4e83-47b6-ba71-731bb481b418
121 lines
3.5 KiB
TypeScript
121 lines
3.5 KiB
TypeScript
import {jest, describe, it, expect, beforeEach} from '@jest/globals';
|
|
|
|
jest.unstable_mockModule('@actions/core', () => ({
|
|
info: jest.fn(),
|
|
warning: jest.fn(),
|
|
debug: jest.fn(),
|
|
error: jest.fn(),
|
|
notice: jest.fn(),
|
|
setFailed: jest.fn(),
|
|
setOutput: jest.fn(),
|
|
getInput: jest.fn(),
|
|
getBooleanInput: jest.fn(),
|
|
getMultilineInput: jest.fn(),
|
|
addPath: jest.fn(),
|
|
exportVariable: jest.fn(),
|
|
saveState: jest.fn(),
|
|
getState: jest.fn(),
|
|
setSecret: jest.fn(),
|
|
isDebug: jest.fn(() => false),
|
|
startGroup: jest.fn(),
|
|
endGroup: jest.fn(),
|
|
group: jest.fn((_name: string, fn: () => Promise<unknown>) => fn()),
|
|
toPlatformPath: jest.fn((value: string) => value),
|
|
toWin32Path: jest.fn((value: string) => value),
|
|
toPosixPath: jest.fn((value: string) => value)
|
|
}));
|
|
|
|
jest.unstable_mockModule('fs', () => ({
|
|
default: {
|
|
readFileSync: jest.fn()
|
|
}
|
|
}));
|
|
|
|
jest.unstable_mockModule('../src/util.js', () => ({
|
|
getBooleanInput: jest.fn(),
|
|
getVersionFromFileContent: jest.fn(),
|
|
isJdkCacheEnabled: jest.fn()
|
|
}));
|
|
|
|
jest.unstable_mockModule('../src/toolchains.js', () => ({
|
|
validateToolchainIds: jest.fn(),
|
|
configureToolchains: jest.fn()
|
|
}));
|
|
|
|
jest.unstable_mockModule(
|
|
'../src/distributions/distribution-factory.js',
|
|
() => ({
|
|
getJavaDistribution: jest.fn()
|
|
})
|
|
);
|
|
|
|
jest.unstable_mockModule('../src/auth.js', () => ({
|
|
configureAuthentication: jest.fn()
|
|
}));
|
|
|
|
jest.unstable_mockModule('../src/maven-args.js', () => ({
|
|
configureMavenArgs: jest.fn()
|
|
}));
|
|
|
|
jest.unstable_mockModule('../src/problem-matcher.js', () => ({
|
|
configureProblemMatcher: jest.fn()
|
|
}));
|
|
|
|
// These modules should never be imported when `cache` input is empty.
|
|
jest.unstable_mockModule('../src/cache-feature.js', () => {
|
|
throw new Error('cache-feature module should not be loaded');
|
|
});
|
|
jest.unstable_mockModule('../src/cache.js', () => {
|
|
throw new Error('cache module should not be loaded');
|
|
});
|
|
|
|
const core = await import('@actions/core');
|
|
const util = await import('../src/util.js');
|
|
const toolchains = await import('../src/toolchains.js');
|
|
const factory = await import('../src/distributions/distribution-factory.js');
|
|
const {run} = await import('../src/setup-java.js');
|
|
|
|
describe('setup-java conditional module loading', () => {
|
|
const inputs = new Map<string, string>();
|
|
const multilineInputs = new Map<string, string[]>();
|
|
const booleanInputs = new Map<string, boolean>();
|
|
|
|
beforeEach(() => {
|
|
jest.resetAllMocks();
|
|
inputs.clear();
|
|
multilineInputs.clear();
|
|
booleanInputs.clear();
|
|
|
|
(core.getInput as jest.Mock).mockImplementation((name: unknown) => {
|
|
return inputs.get(name as string) ?? '';
|
|
});
|
|
(core.getMultilineInput as jest.Mock).mockImplementation(
|
|
(name: unknown) => {
|
|
return multilineInputs.get(name as string) ?? [];
|
|
}
|
|
);
|
|
(util.getBooleanInput as jest.Mock).mockImplementation(
|
|
(name: unknown, defaultValue: unknown) => {
|
|
return booleanInputs.get(name as string) ?? defaultValue;
|
|
}
|
|
);
|
|
(util.isJdkCacheEnabled as jest.Mock).mockReturnValue(false);
|
|
(toolchains.configureToolchains as jest.Mock).mockResolvedValue(undefined);
|
|
});
|
|
|
|
it('does not import cache modules when cache input is not provided', async () => {
|
|
inputs.set('distribution', 'temurin');
|
|
multilineInputs.set('java-version', ['21']);
|
|
(factory.getJavaDistribution as jest.Mock).mockResolvedValue({
|
|
setupJava: jest.fn(async () => ({
|
|
version: '21.0.4+7',
|
|
path: '/opt/java/21'
|
|
}))
|
|
});
|
|
|
|
await run();
|
|
|
|
expect(core.setFailed).not.toHaveBeenCalled();
|
|
});
|
|
});
|