Optimize Temurin tool-cache fast path with lazy loading (#1179)

* 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
This commit is contained in:
Bruno Borges
2026-07-29 17:53:33 -04:00
committed by GitHub
co-authored by Copilot App
parent 6937f5eb31
commit 3cc3643700
39 changed files with 135324 additions and 133265 deletions
+62 -38
View File
@@ -1,14 +1,9 @@
import fs from 'fs';
import * as core from '@actions/core';
import * as auth from './auth.js';
import {
getBooleanInput,
isCacheFeatureAvailable,
getVersionFromFileContent
} from './util.js';
import {getBooleanInput, getVersionFromFileContent} from './util.js';
import * as toolchains from './toolchains.js';
import * as constants from './constants.js';
import {restore} from './cache.js';
import * as path from 'path';
import {fileURLToPath} from 'url';
import {getJavaDistribution} from './distributions/distribution-factory.js';
@@ -17,34 +12,32 @@ import {configureMavenArgs} from './maven-args.js';
import {configureProblemMatcher} from './problem-matcher.js';
export async function run() {
try {
const versions = core.getMultilineInput(constants.INPUT_JAVA_VERSION);
let distributionName = core.getInput(constants.INPUT_DISTRIBUTION);
const versionFile = core.getInput(constants.INPUT_JAVA_VERSION_FILE);
const architecture = core.getInput(constants.INPUT_ARCHITECTURE);
const packageType = core.getInput(constants.INPUT_JAVA_PACKAGE);
const jdkFile = getJdkFileInput();
const cache = core.getInput(constants.INPUT_CACHE);
const cacheDependencyPath = core.getInput(
constants.INPUT_CACHE_DEPENDENCY_PATH
);
const cachePath = core.getMultilineInput(constants.INPUT_CACHE_PATH);
const checkLatest = getBooleanInput(constants.INPUT_CHECK_LATEST, false);
const forceDownload = getBooleanInput(
constants.INPUT_FORCE_DOWNLOAD,
false
);
const setDefault = getBooleanInput(constants.INPUT_SET_DEFAULT, true);
const verifySignature = getBooleanInput(
constants.INPUT_VERIFY_SIGNATURE,
false
);
const verifySignaturePublicKey =
core.getInput(constants.INPUT_VERIFY_SIGNATURE_PUBLIC_KEY) || undefined;
const toolchainIds = core.getMultilineInput(
constants.INPUT_MVN_TOOLCHAIN_ID
);
const versions = core.getMultilineInput(constants.INPUT_JAVA_VERSION);
let distributionName = core.getInput(constants.INPUT_DISTRIBUTION);
const versionFile = core.getInput(constants.INPUT_JAVA_VERSION_FILE);
const architecture = core.getInput(constants.INPUT_ARCHITECTURE);
const packageType = core.getInput(constants.INPUT_JAVA_PACKAGE);
const jdkFile = getJdkFileInput();
const cache = core.getInput(constants.INPUT_CACHE);
const cacheDependencyPath = core.getInput(
constants.INPUT_CACHE_DEPENDENCY_PATH
);
const cachePath = core.getMultilineInput(constants.INPUT_CACHE_PATH);
const checkLatest = getBooleanInput(constants.INPUT_CHECK_LATEST, false);
const forceDownload = getBooleanInput(constants.INPUT_FORCE_DOWNLOAD, false);
const setDefault = getBooleanInput(constants.INPUT_SET_DEFAULT, true);
const verifySignature = getBooleanInput(
constants.INPUT_VERIFY_SIGNATURE,
false
);
const verifySignaturePublicKey =
core.getInput(constants.INPUT_VERIFY_SIGNATURE_PUBLIC_KEY) || undefined;
const toolchainIds = core.getMultilineInput(constants.INPUT_MVN_TOOLCHAIN_ID);
let actionError: Error | undefined;
let cacheRestore: Promise<void> | undefined;
try {
core.startGroup('Installed distributions');
if (!versions.length && !versionFile) {
@@ -97,6 +90,9 @@ export async function run() {
toolchainIds
};
cacheRestore = cache
? startCacheRestore(cache, cacheDependencyPath, cachePath)
: undefined;
await installVersion(versionInfo.version, installerInputsOptions);
} else {
// When using java-version input, distribution is still required
@@ -117,6 +113,9 @@ export async function run() {
toolchainIds
};
cacheRestore = cache
? startCacheRestore(cache, cacheDependencyPath, cachePath)
: undefined;
for (const [index, version] of versions.entries()) {
await installVersion(version, installerInputsOptions, index);
}
@@ -132,11 +131,22 @@ export async function run() {
await auth.configureAuthentication();
configureMavenArgs();
if (cache && isCacheFeatureAvailable()) {
await restore(cache, cacheDependencyPath, cachePath);
}
} catch (error) {
core.setFailed((error as Error).message);
actionError = error as Error;
}
if (cacheRestore) {
try {
await cacheRestore;
} catch (error) {
if (!actionError) {
actionError = error as Error;
}
}
}
if (actionError) {
core.setFailed(actionError.message);
}
}
@@ -189,7 +199,7 @@ async function installVersion(
version
};
const distribution = getJavaDistribution(
const distribution = await getJavaDistribution(
distributionName,
installerOptions,
jdkFile
@@ -234,3 +244,17 @@ interface installerInputsOptions {
jdkFile: string;
toolchainIds: Array<string>;
}
async function startCacheRestore(
cache: string,
cacheDependencyPath: string,
cachePath: string[]
): Promise<void> {
const {isCacheFeatureAvailable} = await import('./cache-feature.js');
if (!isCacheFeatureAvailable()) {
return;
}
const {restore} = await import('./cache.js');
await restore(cache, cacheDependencyPath, cachePath);
}