5
0
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:
Julien Dubois
2026-08-05 17:57:27 +02:00
committed by GitHub
parent ab597f914a
commit f4bfb3ddea
20 changed files with 1037 additions and 66 deletions
+73 -1
View File
@@ -30840,7 +30840,7 @@ const DISTRIBUTIONS_ONLY_MAJOR_VERSION = (/* unused pure expression or super */
/* harmony export */ Vt: () => (/* binding */ getBooleanInput),
/* harmony export */ lN: () => (/* binding */ isJdkCacheEnabled)
/* harmony export */ });
/* unused harmony exports getVersionFromToolcachePath, extractJdkFile, cacheJdkDir, getDownloadArchiveExtension, isVersionSatisfies, getToolcachePath, isGhes, getVersionFromFileContent, convertVersionToSemver, getGitHubHttpHeaders, MAX_PAGINATION_PAGES, getNextPageUrlFromLinkHeader, validatePaginationUrl, renameWinArchive, getLatestMajorVersion */
/* unused harmony exports getVersionFromToolcachePath, extractJdkFile, cacheJdkDir, getJavaVersionFromReleaseFile, getDownloadArchiveExtension, isVersionSatisfies, getToolcachePath, isGhes, getVersionFromFileContent, convertVersionToSemver, getArtifactFingerprint, getGitHubHttpHeaders, MAX_PAGINATION_PAGES, getNextPageUrlFromLinkHeader, validatePaginationUrl, renameWinArchive, getLatestMajorVersion */
/* harmony import */ var os__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(857);
/* harmony import */ var os__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nccwpck_require__.n(os__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(6928);
@@ -31005,6 +31005,46 @@ async function cacheJdkDir(sourceDir, toolName, version, architecture) {
}
return await tc.cacheDir(sourceDir, toolName, version, architecture);
}
function getJavaVersionFromReleaseFile(javaHome) {
const releasePaths = [
path.join(javaHome, 'release'),
path.join(javaHome, 'Contents', 'Home', 'release')
];
const releasePath = releasePaths.find(candidate => fs.existsSync(candidate));
if (!releasePath) {
throw new Error(`Unable to determine the installed Java version: no release file found under '${javaHome}'.`);
}
const properties = new Map();
for (const line of fs.readFileSync(releasePath, 'utf8').split(/\r?\n/)) {
const match = line.match(/^([A-Z0-9_]+)="(.*)"$/);
if (match) {
properties.set(match[1], match[2]);
}
}
const runtimeVersion = properties.get('JAVA_RUNTIME_VERSION');
const runtimeMatch = runtimeVersion?.match(/^(\d+(?:\.\d+)*(?:\+\d+(?:\.\d+)*)?)/);
if (runtimeMatch) {
return normalizeJavaReleaseVersion(runtimeMatch[1]);
}
const javaVersion = properties.get('JAVA_VERSION');
if (javaVersion && /^\d+(?:\.\d+)*$/.test(javaVersion)) {
return normalizeJavaReleaseVersion(javaVersion);
}
throw new Error(`Unable to determine the installed Java version from '${releasePath}'.`);
}
function normalizeJavaReleaseVersion(version) {
const [numericVersion, buildVersion] = version.split('+', 2);
const components = numericVersion.split('.');
while (components.length < 3) {
components.push('0');
}
const mainVersion = components.slice(0, 3).join('.');
const build = [
...components.slice(3),
...(buildVersion ? [buildVersion] : [])
];
return build.length > 0 ? `${mainVersion}+${build.join('.')}` : mainVersion;
}
function getToolcacheDestination(toolName, version, architecture) {
const toolcacheRoot = process.env['RUNNER_TOOL_CACHE'];
if (!toolcacheRoot) {
@@ -31195,6 +31235,38 @@ function convertVersionToSemver(version) {
}
return mainVersion;
}
/**
* Builds a validator for the bytes currently served by a URL from the response
* headers of a HEAD request. A vendor's `/latest/` URL never changes, so this
* is what lets a republished artifact be told apart from the previous one when
* no checksum is published alongside it.
*
* Returns `undefined` when the response carries no usable validator, in which
* case the caller must not treat the URL as a stable identity.
*/
function getArtifactFingerprint(headers) {
const readHeader = (name) => {
const value = headers?.[name];
const resolved = Array.isArray(value) ? value[0] : value;
return typeof resolved === 'string' && resolved.trim()
? resolved.trim()
: undefined;
};
// A strong or weak ETag already identifies a specific representation.
const etag = readHeader('etag');
if (etag) {
return `etag:${etag}`;
}
// Otherwise combine the two validators a static file server reliably sends.
// Neither alone is sufficient: `last-modified` has one-second granularity and
// `content-length` is unchanged by a same-size rebuild.
const lastModified = readHeader('last-modified');
const contentLength = readHeader('content-length');
if (lastModified && contentLength) {
return `mtime:${lastModified};length:${contentLength}`;
}
return undefined;
}
function getGitHubHttpHeaders() {
const resolvedToken = core.getInput('token') || process.env.GITHUB_TOKEN;
const auth = !resolvedToken ? undefined : `token ${resolvedToken}`;