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

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
parent 6937f5eb31
commit 3cc3643700
39 changed files with 135324 additions and 133265 deletions
+21
View File
@@ -0,0 +1,21 @@
import * as cache from '@actions/cache';
import * as core from '@actions/core';
import {isGhes} from './util.js';
export function isCacheFeatureAvailable(): boolean {
if (cache.isFeatureAvailable()) {
return true;
}
if (isGhes()) {
core.warning(
'Caching is only supported on GHES version >= 3.5. If you are on a version >= 3.5, please check with your GHES admin if the Actions cache service is enabled or not.'
);
return false;
}
core.warning(
'The runner was not able to contact the cache service. Caching will be skipped'
);
return false;
}
+1 -1
View File
@@ -2,7 +2,6 @@ import * as core from '@actions/core';
import * as gpg from './gpg.js';
import * as constants from './constants.js';
import {getBooleanInput, isJobStatusSuccess} from './util.js';
import {save} from './cache.js';
import {fileURLToPath} from 'url';
async function removePrivateKeyFromKeychain() {
@@ -37,6 +36,7 @@ async function saveCache() {
return;
}
const {save} = await import('./cache.js');
await save(cache);
}
+63 -42
View File
@@ -1,36 +1,14 @@
import {JavaBase} from './base-installer.js';
import {JavaInstallerOptions} from './base-models.js';
import {LocalDistribution} from './local/installer.js';
import {ZuluDistribution} from './zulu/installer.js';
import {AdoptDistribution, AdoptImplementation} from './adopt/installer.js';
import {
TemurinDistribution,
TemurinImplementation
} from './temurin/installer.js';
import {LibericaDistributions} from './liberica/installer.js';
import {LibericaNikDistributions} from './liberica-nik/installer.js';
import {MicrosoftDistributions} from './microsoft/installer.js';
import {SemeruDistribution} from './semeru/installer.js';
import {CorrettoDistribution} from './corretto/installer.js';
import {OracleDistribution} from './oracle/installer.js';
import {DragonwellDistribution} from './dragonwell/installer.js';
import {SapMachineDistribution} from './sapmachine/installer.js';
import {
GraalVMCommunityDistribution,
GraalVMDistribution
} from './graalvm/installer.js';
import {JetBrainsDistribution} from './jetbrains/installer.js';
import {KonaDistribution} from './kona/installer.js';
import {OpenJdkDistribution} from './openjdk/installer.js';
import {JavaDistribution, validateJavaPackage} from './package-types.js';
import os from 'os';
import {validateJavaPlatform} from './platform-types.js';
export function getJavaDistribution(
export async function getJavaDistribution(
distributionName: string,
installerOptions: JavaInstallerOptions,
jdkFile?: string
): JavaBase | null {
): Promise<JavaBase | null> {
validateJavaPackage(
distributionName,
installerOptions.packageType,
@@ -48,52 +26,95 @@ export function getJavaDistribution(
};
switch (distributionName) {
case JavaDistribution.JdkFile:
case JavaDistribution.JdkFile: {
const {LocalDistribution} = await import('./local/installer.js');
return new LocalDistribution(normalizedInstallerOptions, jdkFile);
}
case JavaDistribution.Adopt:
case JavaDistribution.AdoptHotspot:
case JavaDistribution.AdoptHotspot: {
const {AdoptDistribution, AdoptImplementation} =
await import('./adopt/installer.js');
return new AdoptDistribution(
normalizedInstallerOptions,
AdoptImplementation.Hotspot
);
case JavaDistribution.AdoptOpenJ9:
}
case JavaDistribution.AdoptOpenJ9: {
const {AdoptDistribution, AdoptImplementation} =
await import('./adopt/installer.js');
return new AdoptDistribution(
normalizedInstallerOptions,
AdoptImplementation.OpenJ9
);
case JavaDistribution.Temurin:
}
case JavaDistribution.Temurin: {
const {TemurinDistribution, TemurinImplementation} =
await import('./temurin/installer.js');
return new TemurinDistribution(
normalizedInstallerOptions,
TemurinImplementation.Hotspot
);
case JavaDistribution.Zulu:
}
case JavaDistribution.Zulu: {
const {ZuluDistribution} = await import('./zulu/installer.js');
return new ZuluDistribution(normalizedInstallerOptions);
case JavaDistribution.Liberica:
}
case JavaDistribution.Liberica: {
const {LibericaDistributions} = await import('./liberica/installer.js');
return new LibericaDistributions(normalizedInstallerOptions);
case JavaDistribution.LibericaNik:
}
case JavaDistribution.LibericaNik: {
const {LibericaNikDistributions} =
await import('./liberica-nik/installer.js');
return new LibericaNikDistributions(normalizedInstallerOptions);
case JavaDistribution.Microsoft:
}
case JavaDistribution.Microsoft: {
const {MicrosoftDistributions} = await import('./microsoft/installer.js');
return new MicrosoftDistributions(normalizedInstallerOptions);
case JavaDistribution.Semeru:
}
case JavaDistribution.Semeru: {
const {SemeruDistribution} = await import('./semeru/installer.js');
return new SemeruDistribution(normalizedInstallerOptions);
case JavaDistribution.Corretto:
}
case JavaDistribution.Corretto: {
const {CorrettoDistribution} = await import('./corretto/installer.js');
return new CorrettoDistribution(normalizedInstallerOptions);
case JavaDistribution.Oracle:
}
case JavaDistribution.Oracle: {
const {OracleDistribution} = await import('./oracle/installer.js');
return new OracleDistribution(normalizedInstallerOptions);
case JavaDistribution.Dragonwell:
}
case JavaDistribution.Dragonwell: {
const {DragonwellDistribution} =
await import('./dragonwell/installer.js');
return new DragonwellDistribution(normalizedInstallerOptions);
case JavaDistribution.SapMachine:
}
case JavaDistribution.SapMachine: {
const {SapMachineDistribution} =
await import('./sapmachine/installer.js');
return new SapMachineDistribution(normalizedInstallerOptions);
case JavaDistribution.GraalVM:
}
case JavaDistribution.GraalVM: {
const {GraalVMDistribution} = await import('./graalvm/installer.js');
return new GraalVMDistribution(normalizedInstallerOptions);
case JavaDistribution.GraalVMCommunity:
}
case JavaDistribution.GraalVMCommunity: {
const {GraalVMCommunityDistribution} =
await import('./graalvm/installer.js');
return new GraalVMCommunityDistribution(normalizedInstallerOptions);
case JavaDistribution.JetBrains:
}
case JavaDistribution.JetBrains: {
const {JetBrainsDistribution} = await import('./jetbrains/installer.js');
return new JetBrainsDistribution(normalizedInstallerOptions);
case JavaDistribution.Kona:
}
case JavaDistribution.Kona: {
const {KonaDistribution} = await import('./kona/installer.js');
return new KonaDistribution(normalizedInstallerOptions);
case JavaDistribution.OracleOpenJdk:
}
case JavaDistribution.OracleOpenJdk: {
const {OpenJdkDistribution} = await import('./openjdk/installer.js');
return new OpenJdkDistribution(normalizedInstallerOptions);
}
default:
return null;
}
+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);
}
-19
View File
@@ -2,7 +2,6 @@ import os from 'os';
import path from 'path';
import * as fs from 'fs';
import * as semver from 'semver';
import * as cache from '@actions/cache';
import * as core from '@actions/core';
import * as tc from '@actions/tool-cache';
@@ -126,24 +125,6 @@ export function isGhes(): boolean {
return !isGitHubHost && !isGitHubEnterpriseCloudHost && !isLocalHost;
}
export function isCacheFeatureAvailable(): boolean {
if (cache.isFeatureAvailable()) {
return true;
}
if (isGhes()) {
core.warning(
'Caching is only supported on GHES version >= 3.5. If you are on a version >= 3.5, please check with your GHES admin if the Actions cache service is enabled or not.'
);
return false;
}
core.warning(
'The runner was not able to contact the cache service. Caching will be skipped'
);
return false;
}
export interface VersionInfo {
version: string;
distribution?: string;