mirror of
https://gitea.com/actions/setup-java.git
synced 2026-07-10 19:31:55 +08:00
Support pinning java-version as "latest"
Add a `latest` alias for the `java-version` input that floats to the newest available stable (GA) release. It is normalized to the SemVer wildcard at the base-installer layer and always resolves from remote (like `check-latest: true`). List-based distributions resolve it automatically via the existing newest-first matching. Corretto selects its newest available major; Oracle and GraalVM look up the newest GA major via the Adoptium API and request it, failing with an actionable error if that major isn't published yet. The jdkfile distribution rejects `latest`. Closes #832 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
16
dist/cleanup/index.js
vendored
16
dist/cleanup/index.js
vendored
@@ -96154,6 +96154,22 @@ function renameWinArchive(javaArchivePath) {
|
||||
fs.renameSync(javaArchivePath, javaArchivePathRenamed);
|
||||
return javaArchivePathRenamed;
|
||||
}
|
||||
// Resolve the newest available stable/GA feature (major) release.
|
||||
//
|
||||
// Some distributions (e.g. Oracle, GraalVM) construct their download URLs from a
|
||||
// concrete major version and don't expose an endpoint to list every available
|
||||
// release, so a bare `latest` alias can't be resolved from their own metadata.
|
||||
// The Adoptium (Temurin) API is used as a proxy for "what is the newest GA major
|
||||
// version out there", which those distributions typically publish at the same time.
|
||||
async function getLatestMajorVersion(http) {
|
||||
const availableReleasesUrl = 'https://api.adoptium.net/v3/info/available_releases';
|
||||
const response = await http.getJson(availableReleasesUrl);
|
||||
const mostRecent = response.result?.most_recent_feature_release;
|
||||
if (!mostRecent || Number.isNaN(Number(mostRecent))) {
|
||||
throw new Error(`Could not determine the latest available Java major version from ${availableReleasesUrl}`);
|
||||
}
|
||||
return Number(mostRecent);
|
||||
}
|
||||
|
||||
;// CONCATENATED MODULE: ./src/gpg.ts
|
||||
|
||||
|
||||
87
dist/setup/index.js
vendored
87
dist/setup/index.js
vendored
@@ -127146,6 +127146,22 @@ function renameWinArchive(javaArchivePath) {
|
||||
external_fs_namespaceObject.renameSync(javaArchivePath, javaArchivePathRenamed);
|
||||
return javaArchivePathRenamed;
|
||||
}
|
||||
// Resolve the newest available stable/GA feature (major) release.
|
||||
//
|
||||
// Some distributions (e.g. Oracle, GraalVM) construct their download URLs from a
|
||||
// concrete major version and don't expose an endpoint to list every available
|
||||
// release, so a bare `latest` alias can't be resolved from their own metadata.
|
||||
// The Adoptium (Temurin) API is used as a proxy for "what is the newest GA major
|
||||
// version out there", which those distributions typically publish at the same time.
|
||||
async function getLatestMajorVersion(http) {
|
||||
const availableReleasesUrl = 'https://api.adoptium.net/v3/info/available_releases';
|
||||
const response = await http.getJson(availableReleasesUrl);
|
||||
const mostRecent = response.result?.most_recent_feature_release;
|
||||
if (!mostRecent || Number.isNaN(Number(mostRecent))) {
|
||||
throw new Error(`Could not determine the latest available Java major version from ${availableReleasesUrl}`);
|
||||
}
|
||||
return Number(mostRecent);
|
||||
}
|
||||
|
||||
;// CONCATENATED MODULE: ./src/gpg.ts
|
||||
|
||||
@@ -131045,6 +131061,7 @@ class JavaBase {
|
||||
architecture;
|
||||
packageType;
|
||||
stable;
|
||||
latest;
|
||||
checkLatest;
|
||||
setDefault;
|
||||
verifySignature;
|
||||
@@ -131055,7 +131072,11 @@ class JavaBase {
|
||||
allowRetries: true,
|
||||
maxRetries: 3
|
||||
});
|
||||
({ version: this.version, stable: this.stable } = this.normalizeVersion(installerOptions.version));
|
||||
({
|
||||
version: this.version,
|
||||
stable: this.stable,
|
||||
latest: this.latest
|
||||
} = this.normalizeVersion(installerOptions.version));
|
||||
this.architecture = installerOptions.architecture || external_os_default().arch();
|
||||
this.packageType = installerOptions.packageType;
|
||||
this.checkLatest = installerOptions.checkLatest;
|
||||
@@ -131071,7 +131092,7 @@ class JavaBase {
|
||||
throw new Error(`Input 'verify-signature' is not supported for distribution '${this.distribution}'.`);
|
||||
}
|
||||
let foundJava = this.findInToolcache();
|
||||
if (foundJava && !this.checkLatest) {
|
||||
if (foundJava && !this.checkLatest && !this.latest) {
|
||||
info(`Resolved Java ${foundJava.version} from tool-cache`);
|
||||
}
|
||||
else {
|
||||
@@ -131249,6 +131270,17 @@ class JavaBase {
|
||||
}
|
||||
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.
|
||||
if (version.trim().toLowerCase() === 'latest') {
|
||||
return {
|
||||
version: 'x',
|
||||
stable: true,
|
||||
latest: true
|
||||
};
|
||||
}
|
||||
if (version.endsWith('-ea')) {
|
||||
version = version.replace(/-ea$/, '');
|
||||
stable = false;
|
||||
@@ -131263,7 +131295,8 @@ class JavaBase {
|
||||
}
|
||||
return {
|
||||
version,
|
||||
stable
|
||||
stable,
|
||||
latest
|
||||
};
|
||||
}
|
||||
createVersionNotFoundError(versionOrRange, availableVersions, additionalContext) {
|
||||
@@ -131337,6 +131370,9 @@ class LocalDistribution extends JavaBase {
|
||||
this.jdkFile = jdkFile;
|
||||
}
|
||||
async setupJava() {
|
||||
if (this.latest) {
|
||||
throw new Error("The 'latest' version alias is not supported for the 'jdkfile' distribution. Please specify a concrete version.");
|
||||
}
|
||||
let foundJava = this.findInToolcache();
|
||||
if (foundJava) {
|
||||
info(`Resolved Java ${foundJava.version} from tool-cache`);
|
||||
@@ -132352,10 +132388,20 @@ class CorrettoDistribution extends JavaBase {
|
||||
if (!this.stable) {
|
||||
throw new Error('Early access versions are not supported');
|
||||
}
|
||||
const availableVersions = await this.getAvailableVersions();
|
||||
// The `latest` alias is normalized to the SemVer wildcard, but Corretto
|
||||
// matches on an exact major version, so resolve it to the newest available
|
||||
// major from Corretto's own list.
|
||||
if (this.latest) {
|
||||
const latestMajor = availableVersions
|
||||
.map(item => parseInt(item.version, 10))
|
||||
.filter(major => !Number.isNaN(major))
|
||||
.reduce((max, current) => (current > max ? current : max), 0);
|
||||
version = latestMajor.toString();
|
||||
}
|
||||
if (version.includes('.')) {
|
||||
throw new Error('Only major versions are supported');
|
||||
}
|
||||
const availableVersions = await this.getAvailableVersions();
|
||||
const matchingVersions = availableVersions
|
||||
.filter(item => item.version == version)
|
||||
.map(item => {
|
||||
@@ -132483,6 +132529,13 @@ class OracleDistribution extends JavaBase {
|
||||
}
|
||||
const platform = this.getPlatform();
|
||||
const extension = getDownloadArchiveExtension();
|
||||
// The `latest` alias is normalized to the SemVer wildcard. Oracle builds its
|
||||
// download URLs from a concrete major and has no endpoint to list releases,
|
||||
// so resolve the newest available GA major from the Adoptium API and use it.
|
||||
if (this.latest) {
|
||||
const latestMajor = await getLatestMajorVersion(this.http);
|
||||
range = latestMajor.toString();
|
||||
}
|
||||
const isOnlyMajorProvided = !range.includes('.');
|
||||
const major = isOnlyMajorProvided ? range : range.split('.')[0];
|
||||
const possibleUrls = [];
|
||||
@@ -132509,6 +132562,11 @@ class OracleDistribution extends JavaBase {
|
||||
throw new Error(`Http request for Oracle JDK failed with status code: ${response.message.statusCode}`);
|
||||
}
|
||||
}
|
||||
if (this.latest) {
|
||||
const error = this.createVersionNotFoundError(range);
|
||||
error.message += `\nThe latest Java major version (${range}) is not yet available for the Oracle JDK distribution. Please specify a concrete version instead of 'latest'.`;
|
||||
throw error;
|
||||
}
|
||||
throw this.createVersionNotFoundError(range);
|
||||
}
|
||||
getPlatform(platform = process.platform) {
|
||||
@@ -132907,6 +132965,12 @@ class GraalVMDistribution extends JavaBase {
|
||||
if (!this.stable) {
|
||||
return this.findEABuildDownloadUrl(`${range}-ea`);
|
||||
}
|
||||
// The `latest` alias is normalized to the SemVer wildcard. Oracle GraalVM
|
||||
// builds its download URLs from a concrete major and has no endpoint to list
|
||||
// releases, so resolve the newest available GA major from the Adoptium API.
|
||||
if (this.latest) {
|
||||
range = (await getLatestMajorVersion(this.http)).toString();
|
||||
}
|
||||
const { platform, extension, major } = this.validateStableBuildRequest(range);
|
||||
const fileUrl = this.constructFileUrl(range, major, platform, arch, extension);
|
||||
const response = await this.http.head(fileUrl);
|
||||
@@ -132955,6 +133019,9 @@ class GraalVMDistribution extends JavaBase {
|
||||
if (statusCode === HttpCodes.NotFound) {
|
||||
// Create the standard error with additional hint about checking the download URL
|
||||
const error = this.createVersionNotFoundError(range);
|
||||
if (this.latest) {
|
||||
error.message += `\nThe latest Java major version (${range}) is not yet available for the ${this.distribution} distribution. Please specify a concrete version instead of 'latest'.`;
|
||||
}
|
||||
error.message += `\nPlease check if this version is available at ${GRAALVM_DOWNLOAD_URL} . Pick a version from the list.`;
|
||||
throw error;
|
||||
}
|
||||
@@ -133041,6 +133108,12 @@ class GraalVMCommunityDistribution extends GraalVMDistribution {
|
||||
if (!this.stable) {
|
||||
throw new Error('GraalVM Community does not provide early access builds');
|
||||
}
|
||||
// The `latest` alias is normalized to the SemVer wildcard. Resolve the newest
|
||||
// available GA major from the Adoptium API so it can be matched against the
|
||||
// published GraalVM Community releases.
|
||||
if (this.latest) {
|
||||
range = (await getLatestMajorVersion(this.http)).toString();
|
||||
}
|
||||
const arch = this.getSupportedArchitecture();
|
||||
const { platform, extension } = this.validateStableBuildRequest(range);
|
||||
// GraalVM Community asset names embed the platform, architecture and
|
||||
@@ -133664,7 +133737,11 @@ async function installVersion(version, options, toolchainId = 0) {
|
||||
throw new Error(`No supported distribution was found for input ${distributionName}`);
|
||||
}
|
||||
const result = await distribution.setupJava();
|
||||
await configureToolchains(version, distributionName, result.path, toolchainIds[toolchainId]);
|
||||
// When the `latest` alias is used, the literal input isn't a real version, so
|
||||
// pass the resolved version to the toolchains configuration instead.
|
||||
const isLatest = version.trim().toLowerCase() === 'latest';
|
||||
const toolchainVersion = isLatest ? result.version : version;
|
||||
await configureToolchains(toolchainVersion, distributionName, result.path, toolchainIds[toolchainId]);
|
||||
info('');
|
||||
info('Java configuration:');
|
||||
info(` Distribution: ${distributionName}`);
|
||||
|
||||
Reference in New Issue
Block a user