2026-07-29 17:53:33 -04:00
export const id = 242 ;
export const ids = [ 242 ] ;
export const modules = {
/***/ 6242 :
/***/ ( ( _ _unused _webpack _module , _ _webpack _exports _ _ , _ _webpack _require _ _ ) => {
// EXPORTS
_ _webpack _require _ _ . d ( _ _webpack _exports _ _ , {
O : ( ) => ( /* binding */ JavaBase )
} ) ;
// EXTERNAL MODULE: ./node_modules/@actions/tool-cache/lib/tool-cache.js + 2 modules
var tool _cache = _ _webpack _require _ _ ( 9805 ) ;
// EXTERNAL MODULE: ./node_modules/@actions/core/lib/core.js + 7 modules
var core = _ _webpack _require _ _ ( 3838 ) ;
// EXTERNAL MODULE: external "fs"
var external _fs _ = _ _webpack _require _ _ ( 9896 ) ;
// EXTERNAL MODULE: ./node_modules/semver/index.js
var semver = _ _webpack _require _ _ ( 2088 ) ;
var semver _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( semver ) ;
// EXTERNAL MODULE: external "path"
var external _path _ = _ _webpack _require _ _ ( 6928 ) ;
var external _path _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( external _path _ ) ;
// EXTERNAL MODULE: ./node_modules/@actions/http-client/lib/index.js + 1 modules
var lib = _ _webpack _require _ _ ( 4942 ) ;
// EXTERNAL MODULE: ./src/util.ts
var util = _ _webpack _require _ _ ( 4527 ) ;
// EXTERNAL MODULE: ./src/constants.ts
var constants = _ _webpack _require _ _ ( 7242 ) ;
; // CONCATENATED MODULE: ./src/retrying-http-client.ts
const RETRYABLE _HTTP _STATUS _CODES = new Set ( [ 429 , 502 , 503 , 504 , 522 ] ) ;
const RETRYABLE _NETWORK _ERROR _CODES = new Set ( [
'ETIMEDOUT' ,
'ECONNRESET' ,
'ENOTFOUND' ,
'ECONNREFUSED'
] ) ;
const RETRYABLE _HTTP _VERBS = new Set ( [ 'OPTIONS' , 'GET' , 'DELETE' , 'HEAD' ] ) ;
class RetryingHttpClient extends lib /* HttpClient */ . Qq {
maxAttempts ;
baseDelayMs ;
maxDelayMs ;
sleep ;
random ;
now ;
constructor ( userAgent , retryOptions = { } ) {
super ( userAgent , undefined , { allowRetries : false } ) ;
this . maxAttempts = retryOptions . maxAttempts ? ? 4 ;
this . baseDelayMs = retryOptions . baseDelayMs ? ? 1000 ;
this . maxDelayMs = retryOptions . maxDelayMs ? ? 10000 ;
this . sleep =
retryOptions . sleep ? ?
( delayMs => new Promise ( resolve => setTimeout ( resolve , delayMs ) ) ) ;
this . random = retryOptions . random ? ? Math . random ;
this . now = retryOptions . now ? ? Date . now ;
if ( this . maxAttempts < 1 ) {
throw new Error ( 'maxAttempts must be at least 1' ) ;
}
if ( this . baseDelayMs < 0 || this . maxDelayMs < this . baseDelayMs ) {
throw new Error ( 'baseDelayMs must be non-negative and no greater than maxDelayMs' ) ;
}
}
async request ( verb , requestUrl , data , headers ) {
if ( ! RETRYABLE _HTTP _VERBS . has ( verb ) ) {
return super . request ( verb , requestUrl , data , headers ) ;
}
for ( let attempt = 1 ; attempt <= this . maxAttempts ; attempt ++ ) {
try {
const response = await super . request ( verb , requestUrl , data , headers ) ;
const statusCode = response . message . statusCode ;
if ( ! statusCode ||
! RETRYABLE _HTTP _STATUS _CODES . has ( statusCode ) ||
attempt === this . maxAttempts ) {
return response ;
}
const delayMs = this . getDelayMs ( attempt , response . message . headers [ 'retry-after' ] ) ;
await response . readBody ( ) ;
this . logRetry ( attempt , delayMs , ` HTTP ${ statusCode } ` ) ;
await this . sleep ( delayMs ) ;
}
catch ( error ) {
if ( ! isRetryableNetworkError ( error ) || attempt === this . maxAttempts ) {
throw error ;
}
const delayMs = this . getDelayMs ( attempt ) ;
this . logRetry ( attempt , delayMs , getErrorMessage ( error ) ) ;
await this . sleep ( delayMs ) ;
}
}
throw new Error ( 'HTTP retry attempts exhausted unexpectedly' ) ;
}
getDelayMs ( failedAttempt , retryAfter ) {
const exponentialDelay = Math . min ( this . maxDelayMs , this . baseDelayMs * 2 * * ( failedAttempt - 1 ) ) ;
const jitteredDelay = Math . floor ( exponentialDelay / 2 + this . random ( ) * ( exponentialDelay / 2 ) ) ;
const retryAfterDelay = parseRetryAfter ( retryAfter , this . now ( ) ) ;
return Math . min ( this . maxDelayMs , Math . max ( jitteredDelay , retryAfterDelay ? ? 0 ) ) ;
}
logRetry ( failedAttempt , delayMs , reason ) {
core /* info */ . pq ( ` Request attempt ${ failedAttempt } of ${ this . maxAttempts } failed ( ${ reason } ); retrying in ${ delayMs } ms ` ) ;
}
}
function parseRetryAfter ( value , nowMs ) {
const retryAfter = Array . isArray ( value ) ? value [ 0 ] : value ;
if ( ! retryAfter ) {
return undefined ;
}
if ( /^\d+$/ . test ( retryAfter . trim ( ) ) ) {
return Number ( retryAfter ) * 1000 ;
}
const retryAt = Date . parse ( retryAfter ) ;
if ( Number . isNaN ( retryAt ) || retryAt <= nowMs ) {
return undefined ;
}
return retryAt - nowMs ;
}
function isRetryableNetworkError ( error ) {
if ( ! isErrorRecord ( error ) ) {
return false ;
}
if ( typeof error . code === 'string' &&
RETRYABLE _NETWORK _ERROR _CODES . has ( error . code ) ) {
return true ;
}
return ( Array . isArray ( error . errors ) &&
error . errors . some ( nestedError => isRetryableNetworkError ( nestedError ) ) ) ;
}
function isErrorRecord ( error ) {
return typeof error === 'object' && error !== null ;
}
function getErrorMessage ( error ) {
return error instanceof Error ? error . message : 'network error' ;
}
// EXTERNAL MODULE: external "os"
var external _os _ = _ _webpack _require _ _ ( 857 ) ;
var external _os _default = /*#__PURE__*/ _ _webpack _require _ _ . n ( external _os _ ) ;
// EXTERNAL MODULE: external "crypto"
var external _crypto _ = _ _webpack _require _ _ ( 6982 ) ;
// EXTERNAL MODULE: external "stream/promises"
Optimize Maven configuration warm path (#1182)
* Optimize Maven configuration warm path
Avoid eager Maven XML initialization on warm JDK runs by using deterministic serializers for new Maven settings/toolchains files, lazy-loading xmlbuilder2 for existing toolchains merges, and deferring Maven configuration modules until after Java setup.
Add targeted tests for XML escaping, lazy xmlbuilder2 loading, concurrent Maven configuration, and a manual benchmark workflow for warm-path validation.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
* Address Maven optimization PR feedback
Make the toolchain XML generator consistently async, remove redundant Maven configuration await handling, and reuse the existing XML test helper.
Configure CodeQL to skip generated dist output so newly split vendored chunks do not report duplicate generated-code alerts.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
* Apply rubber duck review suggestions
Document XML attribute escaping, simplify Maven configuration awaiting, and add a regression test that feeds fast-path toolchains output into the merge path.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
* Delete .github/codeql/codeql-config.yml
* Update codeql-analysis.yml
* Replace xmlbuilder2 in Maven toolchain merge
Use fast-xml-parser for existing toolchains.xml parsing and serialize merged Maven toolchains deterministically. This removes the bundled xmlbuilder2 DOM/XML builder chunk from dist while preserving merge behavior for custom attributes, custom toolchains, partial entries, duplicate filtering, and escaping.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
* Move Maven benchmark out of setup-java
Remove the Maven warm-path benchmark workflow and helper script from setup-java. Benchmark coverage is being moved to actions/setup-java-benchmarks so this action repository only carries the runtime optimization, tests, and generated distribution artifacts.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
---------
Copilot-Session: 4dc58426-5e20-44cb-af16-8da0965fac3b
2026-07-30 15:09:35 -04:00
var promises _ = _ _webpack _require _ _ ( 9786 ) ;
2026-07-29 17:53:33 -04:00
; // CONCATENATED MODULE: ./src/checksum.ts
function sanitizedSource ( source ) {
if ( ! source ) {
return '' ;
}
try {
const url = new URL ( source ) ;
return ` from ${ url . origin } ${ url . pathname } ` ;
}
catch {
return ' from an invalid checksum source' ;
}
}
// Length, in hex characters, of a digest produced by each supported algorithm.
// Exported so callers (e.g. fetchChecksum) can infer which algorithm a vendor
// actually used when it doesn't disclose it via the checksum URL/filename.
function expectedDigestLength ( algorithm ) {
return algorithm === 'sha256' ? 64 : algorithm === 'sha512' ? 128 : 0 ;
}
function normalizeExpectedDigest ( checksum ) {
const algorithm = checksum . algorithm ;
const digest = typeof checksum . value === 'string'
? checksum . value . trim ( ) . toLowerCase ( )
: '' ;
const expectedLength = expectedDigestLength ( algorithm ) ;
if ( expectedLength === 0 ) {
throw new Error ( ` Unsupported checksum algorithm ' ${ String ( algorithm ) } ' ${ sanitizedSource ( checksum . source ) } . Supported algorithms are sha256 and sha512. ` ) ;
}
if ( ! new RegExp ( ` ^[a-f0-9]{ ${ expectedLength } } $ ` ) . test ( digest ) ) {
throw new Error ( ` Malformed ${ algorithm } checksum metadata ${ sanitizedSource ( checksum . source ) } : expected a ${ expectedLength } -character hexadecimal digest. ` ) ;
}
return digest ;
}
async function calculateChecksum ( filePath , algorithm ) {
const hash = ( 0 , external _crypto _ . createHash ) ( algorithm ) ;
await ( 0 , promises _ . pipeline ) ( ( 0 , external _fs _ . createReadStream ) ( filePath ) , hash ) ;
return hash . digest ( 'hex' ) ;
}
async function verifyChecksum ( filePath , checksum , context ) {
const expected = normalizeExpectedDigest ( checksum ) ;
const actual = await calculateChecksum ( filePath , checksum . algorithm ) ;
const matches = ( 0 , external _crypto _ . timingSafeEqual ) ( Buffer . from ( expected , 'hex' ) , Buffer . from ( actual , 'hex' ) ) ;
if ( ! matches ) {
throw new Error ( ` Checksum verification failed for ${ context . distribution } version ${ context . version } : ${ checksum . algorithm } expected ${ expected } , actual ${ actual } . ` ) ;
}
}
// EXTERNAL MODULE: ./src/distributions/platform-types.ts
var platform _types = _ _webpack _require _ _ ( 7444 ) ;
; // CONCATENATED MODULE: ./src/distributions/base-installer.ts
class JavaBase {
distribution ;
http ;
version ;
architecture ;
packageType ;
stable ;
latest ;
checkLatest ;
forceDownload ;
Add conditional JDK caching (#1201)
* 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
2026-08-04 21:54:10 -04:00
cacheJdk ;
2026-08-05 12:08:32 -04:00
/ * *
* Whether the concrete version of a floating release has been established
* from the checksum - bound resolution cache . Until then the release version is
* only the requested major and says nothing about the bytes behind the URL .
* /
floatingVersionVerified = false ;
2026-07-29 17:53:33 -04:00
setDefault ;
verifySignature ;
2026-09-03 13:27:24 -04:00
verifySignatureExplicitlyRequested ;
2026-07-29 17:53:33 -04:00
verifySignaturePublicKey ;
constructor ( distribution , installerOptions ) {
this . distribution = distribution ;
this . http = new RetryingHttpClient ( 'actions/setup-java' ) ;
( {
version : this . version ,
stable : this . stable ,
latest : this . latest
} = this . normalizeVersion ( installerOptions . version ) ) ;
this . architecture = ( 0 , platform _types /* normalizeArchitecture */ . dV ) ( installerOptions . architecture || external _os _default ( ) . arch ( ) ) ;
this . packageType = installerOptions . packageType ;
this . checkLatest = installerOptions . checkLatest ;
this . forceDownload = installerOptions . forceDownload ? ? false ;
Add conditional JDK caching (#1201)
* 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
2026-08-04 21:54:10 -04:00
this . cacheJdk = installerOptions . cacheJdk ? ? false ;
2026-07-29 17:53:33 -04:00
this . setDefault =
installerOptions . setDefault !== undefined
? installerOptions . setDefault
: true ;
2026-08-24 15:08:03 +01:00
this . verifySignature =
installerOptions . verifySignature ? ? this . supportsSignatureVerification ( ) ;
2026-09-03 13:27:24 -04:00
this . verifySignatureExplicitlyRequested =
installerOptions . verifySignature === true ;
2026-07-29 17:53:33 -04:00
this . verifySignaturePublicKey = installerOptions . verifySignaturePublicKey ;
}
async downloadAndVerify ( javaRelease ) {
const archivePath = await tool _cache /* downloadTool */ . bq ( javaRelease . url ) ;
const checksum = javaRelease . checksum ;
if ( ! checksum || ! checksum . value ? . trim ( ) ) {
core /* debug */ . Yz ( ` No authoritative checksum is available for ${ this . distribution } version ${ javaRelease . version } ; skipping checksum verification. ` ) ;
return archivePath ;
}
try {
await verifyChecksum ( archivePath , checksum , {
distribution : this . distribution ,
version : javaRelease . version
} ) ;
core /* debug */ . Yz ( ` Verified ${ checksum . algorithm } checksum for ${ this . distribution } version ${ javaRelease . version } . ` ) ;
return archivePath ;
}
catch ( error ) {
let cleanupError ;
let cleanupFailed = false ;
try {
await external _fs _ . promises . rm ( archivePath , { force : true } ) ;
}
catch ( caughtCleanupError ) {
cleanupError = caughtCleanupError ;
cleanupFailed = true ;
}
if ( cleanupFailed ) {
throw new Error ( ` ${ error . message } Failed to remove the downloaded archive after verification failure: ${ cleanupError . message } ` , { cause : error } ) ;
}
throw error ;
}
}
async fetchChecksum ( checksumUrl , algorithm ) {
// Some vendors (e.g. JetBrains) publish a single, generically-named
// checksum sibling (`.checksum`) whose digest algorithm isn't disclosed
// by the URL and has changed across releases. Accepting a list of
// candidate algorithms lets callers pass every algorithm the vendor is
// known to use; the actual algorithm is then inferred from the length of
// the returned digest.
const algorithms = Array . isArray ( algorithm ) ? algorithm : [ algorithm ] ;
const algorithmLabel = algorithms . join ( ' or ' ) ;
const response = await this . http . get ( checksumUrl ) ;
const statusCode = response . message . statusCode ;
const source = ( ( ) => {
try {
const url = new URL ( checksumUrl ) ;
return ` ${ url . origin } ${ url . pathname } ` ;
}
catch {
return 'an invalid checksum URL' ;
}
} ) ( ) ;
if ( statusCode === lib /* HttpCodes */ . Hv . NotFound ) {
core /* debug */ . Yz ( ` No authoritative ${ algorithmLabel } checksum is available for ${ this . distribution } from ${ source } ; skipping checksum verification. ` ) ;
return undefined ;
}
if ( statusCode !== lib /* HttpCodes */ . Hv . OK ) {
throw new Error ( ` Failed to fetch the authoritative ${ algorithmLabel } checksum for ${ this . distribution } from ${ source } (HTTP ${ statusCode } ). ` ) ;
}
const body = await response . readBody ( ) ;
const value = body . trim ( ) . split ( /\s+/ , 1 ) [ 0 ] ? ? '' ;
if ( ! value ) {
throw new Error ( ` Received an empty authoritative ${ algorithmLabel } checksum for ${ this . distribution } from ${ source } . ` ) ;
}
// Prefer the strongest algorithm whose digest length matches what was
// actually returned; fall back to the first candidate (preserving prior
// behavior/error messages) when the digest doesn't match any of them.
const resolvedAlgorithm = algorithms . find ( algo => value . length === expectedDigestLength ( algo ) ) ? ?
algorithms [ 0 ] ;
return { algorithm : resolvedAlgorithm , value , source : checksumUrl } ;
}
async setupJava ( ) {
if ( this . verifySignature && ! this . supportsSignatureVerification ( ) ) {
throw new Error ( ` Input 'verify-signature' is not supported for distribution ' ${ this . distribution } '. ` ) ;
}
let foundJava = this . forceDownload ? null : this . findInToolcache ( ) ;
2026-08-05 17:57:27 +02:00
if ( foundJava &&
! this . checkLatest &&
! this . latest &&
! this . requiresRemoteResolution ( ) ) {
2026-07-29 17:53:33 -04:00
core /* info */ . pq ( ` Resolved Java ${ foundJava . version } from tool-cache ` ) ;
}
else {
core /* info */ . pq ( 'Trying to resolve the latest version from remote' ) ;
try {
2026-08-05 17:57:27 +02:00
let javaRelease = await this . resolveJavaRelease ( ) ;
2026-07-29 17:53:33 -04:00
core /* info */ . pq ( ` Resolved latest version as ${ javaRelease . version } ` ) ;
2026-08-05 17:57:27 +02:00
if ( javaRelease . floating ) {
2026-08-05 12:08:32 -04:00
// A tool-cache entry has no source identity, and until the
// checksum-bound resolution cache maps the current artifact to a
// concrete version the release version is still just the requested
// major — so nothing already on the runner can be trusted. Once that
// mapping is known, an installation of exactly that version is the
// artifact we would otherwise download.
foundJava =
this . floatingVersionVerified && ! this . forceDownload
? this . findConcreteVersionInToolcache ( javaRelease . version )
: null ;
2026-08-05 17:57:27 +02:00
}
2026-07-29 17:53:33 -04:00
if ( ! this . forceDownload && foundJava ? . version === javaRelease . version ) {
core /* info */ . pq ( ` Resolved Java ${ foundJava . version } from tool-cache ` ) ;
}
else {
2026-08-05 17:57:27 +02:00
let jdkCache = this . cacheJdk &&
( ! javaRelease . floating ||
( this . hasStableReleaseIdentity ( javaRelease ) &&
semver _default ( ) . valid ( javaRelease . version ) ) )
? await this . createJdkCache ( javaRelease )
: undefined ;
Add conditional JDK caching (#1201)
* 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
2026-08-04 21:54:10 -04:00
if ( ! this . forceDownload && jdkCache ) {
const { restoreJdk } = await Promise . all ( /* import() */ [ _ _webpack _require _ _ . e ( 824 ) , _ _webpack _require _ _ . e ( 971 ) , _ _webpack _require _ _ . e ( 779 ) ] ) . then ( _ _webpack _require _ _ . bind ( _ _webpack _require _ _ , 5779 ) ) ;
const restored = await restoreJdk ( jdkCache ) ;
if ( restored ) {
const restoredPath = this . getRestoredJdkPath ( javaRelease . version ) ;
if ( restoredPath ) {
foundJava = {
version : javaRelease . version ,
path : restoredPath
} ;
}
}
}
if ( ! foundJava || foundJava . version !== javaRelease . version ) {
core /* info */ . pq ( 'Trying to download...' ) ;
foundJava = await this . downloadTool ( javaRelease ) ;
core /* info */ . pq ( ` Java ${ foundJava . version } was downloaded ` ) ;
2026-08-05 17:57:27 +02:00
if ( javaRelease . floating ) {
if ( ! semver _default ( ) . valid ( foundJava . version ) ||
! ( 0 , util /* isVersionSatisfies */ . y ) ( this . version , foundJava . version ) ) {
throw new Error ( ` The downloaded ${ this . distribution } artifact reported Java ${ foundJava . version } , which does not satisfy ' ${ this . version } '. ` ) ;
}
javaRelease = { ... javaRelease , version : foundJava . version } ;
await this . registerFloatingResolution ( javaRelease ) ;
jdkCache =
this . cacheJdk && this . hasStableReleaseIdentity ( javaRelease )
? await this . createJdkCache ( javaRelease )
: undefined ;
}
Add conditional JDK caching (#1201)
* 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
2026-08-04 21:54:10 -04:00
if ( jdkCache ) {
// Register after the installation exists so its identity is
// captured; the post-job save refuses to upload a path whose
// installation was replaced afterwards.
const { registerJdk } = await Promise . all ( /* import() */ [ _ _webpack _require _ _ . e ( 824 ) , _ _webpack _require _ _ . e ( 971 ) , _ _webpack _require _ _ . e ( 779 ) ] ) . then ( _ _webpack _require _ _ . bind ( _ _webpack _require _ _ , 5779 ) ) ;
registerJdk ( jdkCache ) ;
}
}
2026-07-29 17:53:33 -04:00
}
}
catch ( error ) {
this . logSetupError ( error ) ;
throw error ;
}
}
if ( ! foundJava ) {
throw new Error ( 'Failed to resolve Java version' ) ;
}
// JDK folder may contain postfix "Contents/Home" on macOS
const macOSPostfixPath = external _path _default ( ) . join ( foundJava . path , constants /* MACOS_JAVA_CONTENT_POSTFIX */ . PG ) ;
if ( process . platform === 'darwin' && external _fs _ . existsSync ( macOSPostfixPath ) ) {
foundJava . path = macOSPostfixPath ;
}
if ( this . setDefault ) {
core /* info */ . pq ( ` Setting Java ${ foundJava . version } as the default ` ) ;
this . setJavaDefault ( foundJava . version , foundJava . path ) ;
}
else {
core /* info */ . pq ( ` Installing Java ${ foundJava . version } (not setting as default) ` ) ;
this . setJavaEnvironment ( foundJava . version , foundJava . path ) ;
}
return foundJava ;
}
Cache resolved JDK releases to remove the vendor API from warm jobs (#1208)
* Cache resolved JDK releases to remove the vendor API from warm jobs
Only Temurin is preinstalled in the runner tool cache, so for every other
distribution `findInToolcache()` misses on essentially every job. That
forces a call to the distribution's metadata API before the JDK cache key
can even be computed, which makes the vendor a hard per-job dependency
even when the JDK bytes are already cached, and turns a vendor 403, 429,
or outage into a job failure.
Store the resolved release in a small companion cache entry keyed only on
inputs known before any network call: runner OS, architecture,
distribution, package type, requested version, and stability. A job that
finds a current entry installs the JDK without contacting the metadata API
at all.
`@actions/cache` derives a cache version by hashing the requested paths, so
save and restore paths must match. The entry therefore uses a path that
excludes the date bucket while the key includes it, which lets restore keys
fall back to an older bucket. An entry older than the current day is not
used directly: the metadata API is still queried so floating requests such
as `java-version: 21` keep picking up new releases, and the older entry is
used only when that query fails. Because the entry also carries the
download URL and checksum, that fallback works even when the JDK itself is
not cached.
Releases whose URL is not content-addressed are never stored. Oracle JDK
and Oracle GraalVM build a `/latest/` URL for a major-only version, and its
bytes change when a new build is published, so the URL and checksum are
only consistent at the moment they are resolved. Mark those releases
floating and skip recording them.
Restored payloads are validated as untrusted input, and the post-job save
rewrites the payload the key was computed for rather than uploading
whatever is on disk, since a restore in a later step targets the same path.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b76d8cb0-f629-46e1-bf9a-ffde06948644
* Widen the resolution freshness window from a day to a week
A daily window gives no benefit to the repositories that need it most.
A repository whose workflows run once a day would re-resolve on every job,
and one running weekly would never see a current entry at all, yet those
are exactly the repositories with nothing warm in the tool cache.
Seven days is also the ceiling. GitHub removes cache entries that have not
been accessed for seven days, so a longer window would leave the previous
entry evicted by the time the window rolls over, removing the stale
fallback at the moment it is most likely to be needed. It comfortably
covers JDK release cadence, which is monthly at its fastest and usually
quarterly.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b76d8cb0-f629-46e1-bf9a-ffde06948644
* Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
* Rebuild dist to match the linted source
The pre-commit hook runs `eslint --fix` after `npm run check` has already
built `dist/`, so the fix it applied to the resolution fallback warning in
`base-installer.ts` never reached the bundle.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b76d8cb0-f629-46e1-bf9a-ffde06948644
* Rebuild dist to match the linted source
The autofix accepted on the pull request edited the resolution fallback
warning in `base-installer.ts` through the GitHub UI, which does not run
`npm run build`, so `dist/` still carried the pre-fix bundle.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b76d8cb0-f629-46e1-bf9a-ffde06948644
---------
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: b76d8cb0-f629-46e1-bf9a-ffde06948644
2026-08-04 23:58:03 -04:00
/ * *
* Resolves the release to install , preferring a cached resolution over the
* distribution ' s metadata API .
*
* Only Temurin is preinstalled on hosted runners , so for every other
* distribution the tool - cache lookup misses and the vendor API becomes a
* per - job dependency even when the JDK itself is already in the GitHub
* Actions cache . A cached resolution removes that dependency , and because it
* carries the download URL and checksum it also keeps a job working when the
* vendor API is unavailable but the JDK still has to be downloaded .
* /
async resolveJavaRelease ( ) {
if ( ! this . cacheJdk ||
this . checkLatest ||
this . latest ||
2026-08-05 17:57:27 +02:00
this . forceDownload ||
this . requiresRemoteResolution ( ) ) {
const release = await this . findPackageForDownload ( this . version ) ;
return this . restoreFloatingResolution ( release ) ;
Cache resolved JDK releases to remove the vendor API from warm jobs (#1208)
* Cache resolved JDK releases to remove the vendor API from warm jobs
Only Temurin is preinstalled in the runner tool cache, so for every other
distribution `findInToolcache()` misses on essentially every job. That
forces a call to the distribution's metadata API before the JDK cache key
can even be computed, which makes the vendor a hard per-job dependency
even when the JDK bytes are already cached, and turns a vendor 403, 429,
or outage into a job failure.
Store the resolved release in a small companion cache entry keyed only on
inputs known before any network call: runner OS, architecture,
distribution, package type, requested version, and stability. A job that
finds a current entry installs the JDK without contacting the metadata API
at all.
`@actions/cache` derives a cache version by hashing the requested paths, so
save and restore paths must match. The entry therefore uses a path that
excludes the date bucket while the key includes it, which lets restore keys
fall back to an older bucket. An entry older than the current day is not
used directly: the metadata API is still queried so floating requests such
as `java-version: 21` keep picking up new releases, and the older entry is
used only when that query fails. Because the entry also carries the
download URL and checksum, that fallback works even when the JDK itself is
not cached.
Releases whose URL is not content-addressed are never stored. Oracle JDK
and Oracle GraalVM build a `/latest/` URL for a major-only version, and its
bytes change when a new build is published, so the URL and checksum are
only consistent at the moment they are resolved. Mark those releases
floating and skip recording them.
Restored payloads are validated as untrusted input, and the post-job save
rewrites the payload the key was computed for rather than uploading
whatever is on disk, since a restore in a later step targets the same path.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b76d8cb0-f629-46e1-bf9a-ffde06948644
* Widen the resolution freshness window from a day to a week
A daily window gives no benefit to the repositories that need it most.
A repository whose workflows run once a day would re-resolve on every job,
and one running weekly would never see a current entry at all, yet those
are exactly the repositories with nothing warm in the tool cache.
Seven days is also the ceiling. GitHub removes cache entries that have not
been accessed for seven days, so a longer window would leave the previous
entry evicted by the time the window rolls over, removing the stale
fallback at the moment it is most likely to be needed. It comfortably
covers JDK release cadence, which is monthly at its fastest and usually
quarterly.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b76d8cb0-f629-46e1-bf9a-ffde06948644
* Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
* Rebuild dist to match the linted source
The pre-commit hook runs `eslint --fix` after `npm run check` has already
built `dist/`, so the fix it applied to the resolution fallback warning in
`base-installer.ts` never reached the bundle.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b76d8cb0-f629-46e1-bf9a-ffde06948644
* Rebuild dist to match the linted source
The autofix accepted on the pull request edited the resolution fallback
warning in `base-installer.ts` through the GitHub UI, which does not run
`npm run build`, so `dist/` still carried the pre-fix bundle.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b76d8cb0-f629-46e1-bf9a-ffde06948644
---------
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: b76d8cb0-f629-46e1-bf9a-ffde06948644
2026-08-04 23:58:03 -04:00
}
const { restoreJdkResolution , registerJdkResolution } = await Promise . all ( /* import() */ [ _ _webpack _require _ _ . e ( 824 ) , _ _webpack _require _ _ . e ( 971 ) , _ _webpack _require _ _ . e ( 348 ) ] ) . then ( _ _webpack _require _ _ . bind ( _ _webpack _require _ _ , 967 ) ) ;
const request = {
distribution : this . distribution ,
packageType : this . packageType ,
2026-08-05 18:45:11 +02:00
platform : ( 0 , platform _types /* getJavaPlatformIdentity */ . U ) ( ) ,
Cache resolved JDK releases to remove the vendor API from warm jobs (#1208)
* Cache resolved JDK releases to remove the vendor API from warm jobs
Only Temurin is preinstalled in the runner tool cache, so for every other
distribution `findInToolcache()` misses on essentially every job. That
forces a call to the distribution's metadata API before the JDK cache key
can even be computed, which makes the vendor a hard per-job dependency
even when the JDK bytes are already cached, and turns a vendor 403, 429,
or outage into a job failure.
Store the resolved release in a small companion cache entry keyed only on
inputs known before any network call: runner OS, architecture,
distribution, package type, requested version, and stability. A job that
finds a current entry installs the JDK without contacting the metadata API
at all.
`@actions/cache` derives a cache version by hashing the requested paths, so
save and restore paths must match. The entry therefore uses a path that
excludes the date bucket while the key includes it, which lets restore keys
fall back to an older bucket. An entry older than the current day is not
used directly: the metadata API is still queried so floating requests such
as `java-version: 21` keep picking up new releases, and the older entry is
used only when that query fails. Because the entry also carries the
download URL and checksum, that fallback works even when the JDK itself is
not cached.
Releases whose URL is not content-addressed are never stored. Oracle JDK
and Oracle GraalVM build a `/latest/` URL for a major-only version, and its
bytes change when a new build is published, so the URL and checksum are
only consistent at the moment they are resolved. Mark those releases
floating and skip recording them.
Restored payloads are validated as untrusted input, and the post-job save
rewrites the payload the key was computed for rather than uploading
whatever is on disk, since a restore in a later step targets the same path.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b76d8cb0-f629-46e1-bf9a-ffde06948644
* Widen the resolution freshness window from a day to a week
A daily window gives no benefit to the repositories that need it most.
A repository whose workflows run once a day would re-resolve on every job,
and one running weekly would never see a current entry at all, yet those
are exactly the repositories with nothing warm in the tool cache.
Seven days is also the ceiling. GitHub removes cache entries that have not
been accessed for seven days, so a longer window would leave the previous
entry evicted by the time the window rolls over, removing the stale
fallback at the moment it is most likely to be needed. It comfortably
covers JDK release cadence, which is monthly at its fastest and usually
quarterly.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b76d8cb0-f629-46e1-bf9a-ffde06948644
* Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
* Rebuild dist to match the linted source
The pre-commit hook runs `eslint --fix` after `npm run check` has already
built `dist/`, so the fix it applied to the resolution fallback warning in
`base-installer.ts` never reached the bundle.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b76d8cb0-f629-46e1-bf9a-ffde06948644
* Rebuild dist to match the linted source
The autofix accepted on the pull request edited the resolution fallback
warning in `base-installer.ts` through the GitHub UI, which does not run
`npm run build`, so `dist/` still carried the pre-fix bundle.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b76d8cb0-f629-46e1-bf9a-ffde06948644
---------
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: b76d8cb0-f629-46e1-bf9a-ffde06948644
2026-08-04 23:58:03 -04:00
architecture : this . architecture ,
versionSpec : this . version ,
stable : this . stable
} ;
const restored = await restoreJdkResolution ( request ) ;
if ( restored ? . fresh ) {
core /* info */ . pq ( ` Resolved ${ this . distribution } ${ restored . release . version } from the resolution cache ` ) ;
return restored . release ;
}
try {
const javaRelease = await this . findPackageForDownload ( this . version ) ;
if ( ! javaRelease . floating ) {
registerJdkResolution ( request , javaRelease ) ;
}
2026-08-05 17:57:27 +02:00
return this . restoreFloatingResolution ( javaRelease ) ;
Cache resolved JDK releases to remove the vendor API from warm jobs (#1208)
* Cache resolved JDK releases to remove the vendor API from warm jobs
Only Temurin is preinstalled in the runner tool cache, so for every other
distribution `findInToolcache()` misses on essentially every job. That
forces a call to the distribution's metadata API before the JDK cache key
can even be computed, which makes the vendor a hard per-job dependency
even when the JDK bytes are already cached, and turns a vendor 403, 429,
or outage into a job failure.
Store the resolved release in a small companion cache entry keyed only on
inputs known before any network call: runner OS, architecture,
distribution, package type, requested version, and stability. A job that
finds a current entry installs the JDK without contacting the metadata API
at all.
`@actions/cache` derives a cache version by hashing the requested paths, so
save and restore paths must match. The entry therefore uses a path that
excludes the date bucket while the key includes it, which lets restore keys
fall back to an older bucket. An entry older than the current day is not
used directly: the metadata API is still queried so floating requests such
as `java-version: 21` keep picking up new releases, and the older entry is
used only when that query fails. Because the entry also carries the
download URL and checksum, that fallback works even when the JDK itself is
not cached.
Releases whose URL is not content-addressed are never stored. Oracle JDK
and Oracle GraalVM build a `/latest/` URL for a major-only version, and its
bytes change when a new build is published, so the URL and checksum are
only consistent at the moment they are resolved. Mark those releases
floating and skip recording them.
Restored payloads are validated as untrusted input, and the post-job save
rewrites the payload the key was computed for rather than uploading
whatever is on disk, since a restore in a later step targets the same path.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b76d8cb0-f629-46e1-bf9a-ffde06948644
* Widen the resolution freshness window from a day to a week
A daily window gives no benefit to the repositories that need it most.
A repository whose workflows run once a day would re-resolve on every job,
and one running weekly would never see a current entry at all, yet those
are exactly the repositories with nothing warm in the tool cache.
Seven days is also the ceiling. GitHub removes cache entries that have not
been accessed for seven days, so a longer window would leave the previous
entry evicted by the time the window rolls over, removing the stale
fallback at the moment it is most likely to be needed. It comfortably
covers JDK release cadence, which is monthly at its fastest and usually
quarterly.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b76d8cb0-f629-46e1-bf9a-ffde06948644
* Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
* Rebuild dist to match the linted source
The pre-commit hook runs `eslint --fix` after `npm run check` has already
built `dist/`, so the fix it applied to the resolution fallback warning in
`base-installer.ts` never reached the bundle.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b76d8cb0-f629-46e1-bf9a-ffde06948644
* Rebuild dist to match the linted source
The autofix accepted on the pull request edited the resolution fallback
warning in `base-installer.ts` through the GitHub UI, which does not run
`npm run build`, so `dist/` still carried the pre-fix bundle.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b76d8cb0-f629-46e1-bf9a-ffde06948644
---------
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: b76d8cb0-f629-46e1-bf9a-ffde06948644
2026-08-04 23:58:03 -04:00
}
catch ( error ) {
if ( ! restored ) {
throw error ;
}
// The cached resolution is older than the current bucket, but falling
// back to it is strictly better than failing the job because the vendor
// metadata API is down.
core /* warning */ . $e ( ` Failed to resolve ${ this . distribution } ${ this . version } from remote ( ${ error instanceof Error ? error . message : String ( error ) } ); falling back to the cached resolution for ${ restored . release . version } . ` ) ;
return restored . release ;
}
}
2026-08-05 17:57:27 +02:00
requiresRemoteResolution ( ) {
return false ;
}
async createJdkCache ( javaRelease ) {
const { getJdkVerificationIdentity } = await Promise . all ( /* import() */ [ _ _webpack _require _ _ . e ( 824 ) , _ _webpack _require _ _ . e ( 971 ) , _ _webpack _require _ _ . e ( 779 ) ] ) . then ( _ _webpack _require _ _ . bind ( _ _webpack _require _ _ , 5779 ) ) ;
return {
distribution : this . distribution ,
packageType : this . packageType ,
architecture : this . architecture ,
version : javaRelease . version ,
source : this . getJdkReleaseIdentity ( javaRelease ) ,
2026-09-03 13:27:24 -04:00
verification : getJdkVerificationIdentity ( this . verifySignature , this . verifySignatureExplicitlyRequested , this . verifySignaturePublicKey ) ,
2026-08-05 17:57:27 +02:00
path : this . getJdkCachePath ( javaRelease . version )
} ;
}
async restoreFloatingResolution ( javaRelease ) {
if ( ! javaRelease . floating ||
! this . hasStableReleaseIdentity ( javaRelease ) ||
! this . cacheJdk ||
this . forceDownload ) {
return javaRelease ;
}
const { restoreJdkResolution } = await Promise . all ( /* import() */ [ _ _webpack _require _ _ . e ( 824 ) , _ _webpack _require _ _ . e ( 971 ) , _ _webpack _require _ _ . e ( 348 ) ] ) . then ( _ _webpack _require _ _ . bind ( _ _webpack _require _ _ , 967 ) ) ;
const restored = await restoreJdkResolution ( this . getFloatingResolutionRequest ( javaRelease ) ) ;
if ( ! restored ) {
return javaRelease ;
}
if ( ! semver _default ( ) . valid ( restored . release . version ) ||
! ( 0 , util /* isVersionSatisfies */ . y ) ( this . version , restored . release . version ) ) {
core /* debug */ . Yz ( ` Ignoring the cached concrete version ' ${ restored . release . version } ' for ${ this . distribution } ${ this . version } . ` ) ;
return javaRelease ;
}
core /* info */ . pq ( ` Resolved ${ this . distribution } ${ restored . release . version } for the current floating artifact ` ) ;
2026-08-05 12:08:32 -04:00
this . floatingVersionVerified = true ;
2026-08-05 17:57:27 +02:00
return { ... javaRelease , version : restored . release . version } ;
}
async registerFloatingResolution ( javaRelease ) {
if ( ! this . hasStableReleaseIdentity ( javaRelease ) ||
! this . cacheJdk ||
this . forceDownload ) {
return ;
}
const { registerJdkResolution } = await Promise . all ( /* import() */ [ _ _webpack _require _ _ . e ( 824 ) , _ _webpack _require _ _ . e ( 971 ) , _ _webpack _require _ _ . e ( 348 ) ] ) . then ( _ _webpack _require _ _ . bind ( _ _webpack _require _ _ , 967 ) ) ;
registerJdkResolution ( this . getFloatingResolutionRequest ( javaRelease ) , javaRelease ) ;
}
getFloatingResolutionRequest ( javaRelease ) {
return {
distribution : this . distribution ,
packageType : this . packageType ,
2026-08-05 18:45:11 +02:00
platform : ( 0 , platform _types /* getJavaPlatformIdentity */ . U ) ( ) ,
2026-08-05 17:57:27 +02:00
architecture : this . architecture ,
versionSpec : this . version ,
stable : this . stable ,
source : this . getJdkReleaseIdentity ( javaRelease )
} ;
}
2026-07-29 17:53:33 -04:00
logSetupError ( error ) {
const httpStatusCode = error instanceof tool _cache /* HTTPError */ . Hl
? error . httpStatusCode
: error instanceof lib /* HttpClientError */ . Kg
? error . statusCode
: undefined ;
if ( httpStatusCode ) {
if ( httpStatusCode === 403 ) {
core /* error */ . z3 ( 'HTTP 403: Permission denied or access restricted.' ) ;
}
else if ( httpStatusCode === 429 ) {
core /* warning */ . $e ( 'HTTP 429: Rate limit exceeded. Please retry later.' ) ;
}
else {
core /* error */ . z3 ( ` HTTP ${ httpStatusCode } : ${ error . message } ` ) ;
}
}
else if ( error && error . errors && Array . isArray ( error . errors ) ) {
core /* error */ . z3 ( ` Java setup failed due to network or configuration error(s) ` ) ;
if ( error instanceof Error && error . stack ) {
core /* debug */ . Yz ( error . stack ) ;
}
for ( const err of error . errors ) {
const endpoint = err ? . address || err ? . hostname || '' ;
const port = err ? . port ? ` : ${ err . port } ` : '' ;
const message = err ? . message || 'Aggregate error' ;
const endpointInfo = ! message . includes ( endpoint )
? ` ${ endpoint } ${ port } `
: '' ;
const localInfo = err . localAddress && err . localPort
? ` - Local ( ${ err . localAddress } : ${ err . localPort } ) `
: '' ;
const logMessage = ` ${ message } ${ endpointInfo } ${ localInfo } ` ;
core /* error */ . z3 ( logMessage ) ;
core /* debug */ . Yz ( ` ${ err . stack || err . message } ` ) ;
Object . entries ( err ) . forEach ( ( [ key , value ] ) => {
core /* debug */ . Yz ( ` " ${ key } ": ${ JSON . stringify ( value ) } ` ) ;
} ) ;
}
}
else {
const message = error instanceof Error ? error . message : JSON . stringify ( error ) ;
core /* error */ . z3 ( ` Java setup process failed due to: ${ message } ` ) ;
if ( typeof error ? . code === 'string' ) {
core /* debug */ . Yz ( error . stack ) ;
}
const errorDetails = {
name : error . name ,
message : error . message ,
... Object . getOwnPropertyNames ( error )
. filter ( prop => ! [ 'name' , 'message' , 'stack' ] . includes ( prop ) )
. reduce ( ( acc , prop ) => {
acc [ prop ] = error [ prop ] ;
return acc ;
} , { } )
} ;
Object . entries ( errorDetails ) . forEach ( ( [ key , value ] ) => {
core /* debug */ . Yz ( ` " ${ key } ": ${ JSON . stringify ( value ) } ` ) ;
} ) ;
}
}
get toolcacheFolderName ( ) {
return ` Java_ ${ this . distribution } _ ${ this . packageType } ` ;
}
supportsSignatureVerification ( ) {
return false ;
}
getToolcacheVersionName ( version ) {
if ( ! this . stable ) {
if ( version . includes ( '+' ) ) {
return version . replace ( '+' , '-ea.' ) ;
}
else {
return ` ${ version } -ea ` ;
}
}
// Kotlin and some Java dependencies don't work properly when Java path contains "+" sign
// so replace "/hostedtoolcache/Java/11.0.3+4/x64" to "/hostedtoolcache/Java/11.0.3-4/x64" when saves to cache
// related issue: https://github.com/actions/virtual-environments/issues/3014
return version . replace ( '+' , '-' ) ;
}
Add conditional JDK caching (#1201)
* 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
2026-08-04 21:54:10 -04:00
getJdkCachePath ( version ) {
const toolCache = process . env [ 'RUNNER_TOOL_CACHE' ] ;
if ( ! toolCache ) {
return '' ;
}
return external _path _default ( ) . join ( toolCache , this . toolcacheFolderName , this . getToolcacheVersionName ( version ) ) ;
}
getRestoredJdkPath ( version ) {
const basePath = this . getJdkCachePath ( version ) ;
if ( ! basePath ) {
return null ;
}
const architecturePath = external _path _default ( ) . join ( basePath , this . architecture ) ;
return external _fs _ . existsSync ( architecturePath ) &&
external _fs _ . existsSync ( ` ${ architecturePath } .complete ` )
? architecturePath
: null ;
}
2026-08-05 12:08:32 -04:00
/ * *
* Locates an installation of an exact version in the tool cache , unlike
* ` findInToolcache() ` which returns the newest entry satisfying the requested
* range . Used to reuse a JDK the runner already holds instead of downloading
* the identical artifact again .
* /
findConcreteVersionInToolcache ( version ) {
if ( ! semver _default ( ) . valid ( version ) ) {
return null ;
}
const installedPath = this . getRestoredJdkPath ( version ) ;
return installedPath ? { version , path : installedPath } : null ;
}
Add conditional JDK caching (#1201)
* 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
2026-08-04 21:54:10 -04:00
getJdkReleaseIdentity ( javaRelease ) {
if ( javaRelease . checksum ) {
return ` ${ javaRelease . checksum . algorithm } : ${ javaRelease . checksum . value } ` ;
}
2026-08-05 17:57:27 +02:00
if ( javaRelease . fingerprint ) {
return javaRelease . fingerprint ;
}
Add conditional JDK caching (#1201)
* 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
2026-08-04 21:54:10 -04:00
try {
const url = new URL ( javaRelease . url ) ;
return ` ${ url . origin } ${ url . pathname } ` ;
}
catch {
return javaRelease . url ;
}
}
2026-08-05 17:57:27 +02:00
/ * *
* Whether the release identity pins the exact bytes behind ` url ` . A floating
* URL is a constant string , so it only becomes a safe cache identity once a
* checksum or a response validator distinguishes one published build from the
* next .
* /
hasStableReleaseIdentity ( javaRelease ) {
return Boolean ( javaRelease . checksum ? ? javaRelease . fingerprint ) ;
}
2026-07-29 17:53:33 -04:00
findInToolcache ( ) {
// we can't use tc.find directly because firstly, we need to filter versions by stability flag
// if *-ea is provided, take only ea versions from toolcache, otherwise - only stable versions
const availableVersions = tool _cache /* findAllVersions */ . iq ( this . toolcacheFolderName , this . architecture )
. map ( item => {
return {
version : item
. replace ( '-ea.' , '+' )
. replace ( /-ea$/ , '' )
// Kotlin and some Java dependencies don't work properly when Java path contains "+" sign
// so replace "/hostedtoolcache/Java/11.0.3-4/x64" to "/hostedtoolcache/Java/11.0.3+4/x64" when retrieves to cache
// related issue: https://github.com/actions/virtual-environments/issues/3014
. replace ( '-' , '+' ) ,
path : ( 0 , util /* getToolcachePath */ . yH ) ( this . toolcacheFolderName , item , this . architecture ) || '' ,
stable : ! item . includes ( '-ea' )
} ;
} )
. filter ( item => item . stable === this . stable ) ;
const satisfiedVersions = availableVersions
. filter ( item => ( 0 , util /* isVersionSatisfies */ . y ) ( this . version , item . version ) )
. filter ( item => item . path )
. sort ( ( a , b ) => {
return - semver _default ( ) . compareBuild ( a . version , b . version ) ;
} ) ;
if ( ! satisfiedVersions || satisfiedVersions . length === 0 ) {
return null ;
}
return {
version : satisfiedVersions [ 0 ] . version ,
path : satisfiedVersions [ 0 ] . path
} ;
}
normalizeVersion ( version ) {
let stable = true ;
const latest = false ;
// Support the `latest` alias (case-insensitive), which floats to the newest
// available stable/GA release. It is translated to the SemVer wildcard `x`
// so the existing "newest satisfying version wins" resolution applies.
const normalized = version . trim ( ) . toLowerCase ( ) ;
if ( normalized === 'latest' ) {
return {
version : 'x' ,
stable : true ,
latest : true
} ;
}
// Reject `latest` combined with any qualifier (e.g. `latest-ea`). Such inputs
// would otherwise have their `-ea` suffix stripped and fall through to the
// generic SemVer check, which fails with a confusing "'latest' is not valid
// SemVer" message even though `latest` is a supported value. Fail early with a
// targeted explanation instead.
if ( normalized . startsWith ( 'latest' ) ) {
throw new Error ( ` The 'latest' alias resolves stable (GA) releases only and cannot be combined with '-ea' or other qualifiers (received ' ${ version } '). Use 'latest' on its own, or specify a concrete version. ` ) ;
}
if ( version . endsWith ( '-ea' ) ) {
version = version . replace ( /-ea$/ , '' ) ;
stable = false ;
}
else if ( version . includes ( '-ea.' ) ) {
// transform '11.0.3-ea.2' -> '11.0.3+2'
version = version . replace ( '-ea.' , '+' ) ;
stable = false ;
}
// Java uses a versioning scheme (JEP 322) that can contain more numeric
// fields than SemVer allows, e.g. '18.0.1.1' or '11.0.9.1'. Convert such
// exact versions to SemVer build notation ('18.0.1+1') so they are
// accepted. Ranges and versions that already carry build metadata are
// left untouched.
if ( /^\d+(\.\d+){3,}$/ . test ( version ) ) {
version = ( 0 , util /* convertVersionToSemver */ . ZY ) ( version ) ;
}
if ( ! semver _default ( ) . validRange ( version ) ) {
throw new Error ( ` The string ' ${ version } ' is not valid SemVer notation for a Java version. Please check README file for code snippets and more detailed information ` ) ;
}
return {
version ,
stable ,
latest
} ;
}
createVersionNotFoundError ( versionOrRange , availableVersions , additionalContext ) {
const parts = [
` No matching version found for SemVer ' ${ versionOrRange } '. ` ,
` Distribution: ${ this . distribution } ` ,
` Package type: ${ this . packageType } ` ,
` Architecture: ${ this . architecture } `
] ;
// Add additional context if provided (e.g., platform/OS info)
if ( additionalContext ) {
parts . push ( additionalContext ) ;
}
if ( availableVersions && availableVersions . length > 0 ) {
const maxVersionsToShow = core /* isDebug */ . _o ( ) ? availableVersions . length : 50 ;
const versionsToShow = availableVersions . slice ( 0 , maxVersionsToShow ) ;
const truncated = availableVersions . length > maxVersionsToShow ;
parts . push ( ` Available versions: ${ versionsToShow . join ( ', ' ) } ${ truncated ? ', ...' : '' } ` ) ;
if ( truncated ) {
parts . push ( ` (showing first ${ maxVersionsToShow } of ${ availableVersions . length } versions, enable debug mode to see all) ` ) ;
}
}
const error = new Error ( parts . join ( '\n' ) ) ;
error . name = 'VersionNotFoundError' ;
return error ;
}
setJavaDefault ( version , toolPath ) {
core /* exportVariable */ . dN ( 'JAVA_HOME' , toolPath ) ;
core /* addPath */ . fM ( external _path _default ( ) . join ( toolPath , 'bin' ) ) ;
this . setJavaEnvironment ( version , toolPath ) ;
}
setJavaEnvironment ( version , toolPath ) {
const majorVersion = version . split ( '.' ) [ 0 ] ;
core /* setOutput */ . uH ( 'distribution' , this . distribution ) ;
core /* setOutput */ . uH ( 'path' , toolPath ) ;
core /* setOutput */ . uH ( 'version' , version ) ;
core /* exportVariable */ . dN ( ` JAVA_HOME_ ${ majorVersion } _ ${ this . architecture . toUpperCase ( ) } ` , toolPath ) ;
}
distributionArchitecture ( ) {
return this . architecture ;
}
}
/***/ } )
} ;