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
+92 -1
View File
@@ -14,7 +14,7 @@ import {
DISTRIBUTIONS_ONLY_MAJOR_VERSION,
INPUT_CACHE_JDK
} from './constants.js';
import {OutgoingHttpHeaders} from 'http';
import {IncomingHttpHeaders, OutgoingHttpHeaders} from 'http';
export function getTempDir() {
const tempDirectory = process.env['RUNNER_TEMP'] || os.tmpdir();
@@ -192,6 +192,59 @@ export async function cacheJdkDir(
return await tc.cacheDir(sourceDir, toolName, version, architecture);
}
export function getJavaVersionFromReleaseFile(javaHome: string): string {
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<string, string>();
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: string): string {
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: string,
version: string,
@@ -453,6 +506,44 @@ export function convertVersionToSemver(version: number[] | string) {
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.
*/
export function getArtifactFingerprint(
headers: IncomingHttpHeaders | undefined
): string | undefined {
const readHeader = (name: string): string | undefined => {
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;
}
export function getGitHubHttpHeaders(): OutgoingHttpHeaders {
const resolvedToken = core.getInput('token') || process.env.GITHUB_TOKEN;
const auth = !resolvedToken ? undefined : `token ${resolvedToken}`;