mirror of
https://github.com/actions/setup-java.git
synced 2026-07-30 09:10:01 +08:00
3cc3643700
* Optimize Temurin tool-cache fast path - Lazy-load distribution installers so only the selected distro module is initialized - Defer cache feature/cache module loading until cache input is provided - Start cache restore early and await it safely alongside Java setup flow - Update orchestration and lazy-loading tests; regenerate dist artifacts Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: cc2c0256-c55e-4a35-a584-5bed7e8b11ad * Address PR review comments - Lazy-load cache save in cleanup path so no-cache runs avoid cache module init in post action - Stage dist/setup/package.json in release script for chunked setup bundle completeness Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: cc2c0256-c55e-4a35-a584-5bed7e8b11ad * Fix CodeQL comment tag filter finding Patch is-unsafe's XML comment-close detector during builds so generated bundles recognize both HTML comment end forms and satisfy CodeQL until the dependency publishes a fix. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 277302b1-aa95-4012-817b-9752cdaee14e * Rebuild generated dist bundles Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: cc2c0256-c55e-4a35-a584-5bed7e8b11ad --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: cc2c0256-c55e-4a35-a584-5bed7e8b11ad Copilot-Session: 277302b1-aa95-4012-817b-9752cdaee14e
119 lines
3.4 KiB
TypeScript
119 lines
3.4 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()
|
|
}));
|
|
|
|
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;
|
|
}
|
|
);
|
|
(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();
|
|
});
|
|
});
|