mirror of
https://gitea.com/actions/setup-java.git
synced 2026-08-07 02:31:20 +00:00
Report concrete versions for floating Oracle JDK downloads (#1213)
* Fix floating Oracle JDK version resolution Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Update generated distribution bundles Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Harden floating artifact cache identity Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Regenerate setup bundle after cache hardening Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Temporarily enable hosted full validation Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Export hosted formatting results Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Apply repository formatting Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Run hosted validation after formatting Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Correct floating version regression tests Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Remove temporary validation wiring Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Cache checksum-less floating artifacts by their response fingerprint Oracle and Oracle GraalVM do not always publish a `.sha256` sibling next to a `/latest/` artifact. Those floating releases were excluded from both the resolution cache and the JDK cache, so `cache-jdk` users lost caching entirely for them. A floating URL is a constant string, so it cannot serve as a cache identity on its own — a stale entry would be reused forever. Instead, derive a validator from the headers of the HEAD request that already resolves the artifact: the ETag when present, otherwise `Last-Modified` combined with `Content-Length`. Republishing changes the validator, which changes the cache key, so a new build is downloaded rather than masked. `getJdkReleaseIdentity` now falls back to that fingerprint before the URL, and the floating cache gates ask whether the release has a stable identity (checksum or fingerprint) rather than a checksum specifically. A floating release with neither is still left uncached. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Co-authored-by: Bruno Borges <brborges@microsoft.com>
This commit is contained in:
Vendored
+100
-18
@@ -316,31 +316,33 @@ class JavaBase {
|
||||
throw new Error(`Input 'verify-signature' is not supported for distribution '${this.distribution}'.`);
|
||||
}
|
||||
let foundJava = this.forceDownload ? null : this.findInToolcache();
|
||||
if (foundJava && !this.checkLatest && !this.latest) {
|
||||
if (foundJava &&
|
||||
!this.checkLatest &&
|
||||
!this.latest &&
|
||||
!this.requiresRemoteResolution()) {
|
||||
core/* info */.pq(`Resolved Java ${foundJava.version} from tool-cache`);
|
||||
}
|
||||
else {
|
||||
core/* info */.pq('Trying to resolve the latest version from remote');
|
||||
try {
|
||||
const javaRelease = await this.resolveJavaRelease();
|
||||
let javaRelease = await this.resolveJavaRelease();
|
||||
core/* info */.pq(`Resolved latest version as ${javaRelease.version}`);
|
||||
if (javaRelease.floating) {
|
||||
// A tool-cache entry has no source identity. Even when its concrete
|
||||
// version matches, only the checksum-bound JDK cache can prove that
|
||||
// it contains the bytes currently served by the mutable URL.
|
||||
foundJava = null;
|
||||
}
|
||||
if (!this.forceDownload && foundJava?.version === javaRelease.version) {
|
||||
core/* info */.pq(`Resolved Java ${foundJava.version} from tool-cache`);
|
||||
}
|
||||
else {
|
||||
let jdkCache;
|
||||
if (this.cacheJdk) {
|
||||
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));
|
||||
jdkCache = {
|
||||
distribution: this.distribution,
|
||||
packageType: this.packageType,
|
||||
architecture: this.architecture,
|
||||
version: javaRelease.version,
|
||||
source: this.getJdkReleaseIdentity(javaRelease),
|
||||
verification: getJdkVerificationIdentity(this.verifySignature, this.verifySignaturePublicKey),
|
||||
path: this.getJdkCachePath(javaRelease.version)
|
||||
};
|
||||
}
|
||||
let jdkCache = this.cacheJdk &&
|
||||
(!javaRelease.floating ||
|
||||
(this.hasStableReleaseIdentity(javaRelease) &&
|
||||
semver_default().valid(javaRelease.version)))
|
||||
? await this.createJdkCache(javaRelease)
|
||||
: undefined;
|
||||
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);
|
||||
@@ -358,6 +360,18 @@ class JavaBase {
|
||||
core/* info */.pq('Trying to download...');
|
||||
foundJava = await this.downloadTool(javaRelease);
|
||||
core/* info */.pq(`Java ${foundJava.version} was downloaded`);
|
||||
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;
|
||||
}
|
||||
if (jdkCache) {
|
||||
// Register after the installation exists so its identity is
|
||||
// captured; the post-job save refuses to upload a path whose
|
||||
@@ -406,8 +420,10 @@ class JavaBase {
|
||||
if (!this.cacheJdk ||
|
||||
this.checkLatest ||
|
||||
this.latest ||
|
||||
this.forceDownload) {
|
||||
return this.findPackageForDownload(this.version);
|
||||
this.forceDownload ||
|
||||
this.requiresRemoteResolution()) {
|
||||
const release = await this.findPackageForDownload(this.version);
|
||||
return this.restoreFloatingResolution(release);
|
||||
}
|
||||
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 = {
|
||||
@@ -427,7 +443,7 @@ class JavaBase {
|
||||
if (!javaRelease.floating) {
|
||||
registerJdkResolution(request, javaRelease);
|
||||
}
|
||||
return javaRelease;
|
||||
return this.restoreFloatingResolution(javaRelease);
|
||||
}
|
||||
catch (error) {
|
||||
if (!restored) {
|
||||
@@ -440,6 +456,60 @@ class JavaBase {
|
||||
return restored.release;
|
||||
}
|
||||
}
|
||||
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),
|
||||
verification: getJdkVerificationIdentity(this.verifySignature, this.verifySignaturePublicKey),
|
||||
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`);
|
||||
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,
|
||||
architecture: this.architecture,
|
||||
versionSpec: this.version,
|
||||
stable: this.stable,
|
||||
source: this.getJdkReleaseIdentity(javaRelease)
|
||||
};
|
||||
}
|
||||
logSetupError(error) {
|
||||
const httpStatusCode = error instanceof tool_cache/* HTTPError */.Hl
|
||||
? error.httpStatusCode
|
||||
@@ -543,6 +613,9 @@ class JavaBase {
|
||||
if (javaRelease.checksum) {
|
||||
return `${javaRelease.checksum.algorithm}:${javaRelease.checksum.value}`;
|
||||
}
|
||||
if (javaRelease.fingerprint) {
|
||||
return javaRelease.fingerprint;
|
||||
}
|
||||
try {
|
||||
const url = new URL(javaRelease.url);
|
||||
return `${url.origin}${url.pathname}`;
|
||||
@@ -551,6 +624,15 @@ class JavaBase {
|
||||
return javaRelease.url;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user