mirror of
https://gitea.com/actions/setup-java.git
synced 2026-07-11 19:41:57 +08:00
Support pinning java-version as "latest" (#1093)
* 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> * Clarify latest note for oracle/graalvm version resolution vs download Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * graalvm-community: float latest to its own newest GA release GraalVM Community publishes its releases on GitHub, so the `latest` alias now matches against that real release list using the SemVer wildcard instead of asking the Adoptium API for the newest GA major. This prevents `latest` from hard-failing when GraalVM lags behind a freshly released Java major (e.g. Adoptium reports 26 before GraalVM ships it). Oracle GraalVM has no listing endpoint, so it keeps deriving the newest major from Adoptium and errors clearly if that major is not yet published. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Give latest+qualifier inputs (e.g. latest-ea) a targeted error Inputs like 'latest-ea' had their '-ea' suffix stripped and fell through to the generic SemVer validation, failing with a confusing "'latest' is not valid SemVer" message even though 'latest' is supported. Add an explicit guard so any 'latest*' value other than exactly 'latest' throws a targeted error explaining that 'latest' resolves GA releases only and cannot be combined with '-ea' or other qualifiers. 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: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
31
src/util.ts
31
src/util.ts
@@ -6,6 +6,7 @@ import * as cache from '@actions/cache';
|
||||
import * as core from '@actions/core';
|
||||
|
||||
import * as tc from '@actions/tool-cache';
|
||||
import * as httpm from '@actions/http-client';
|
||||
import {
|
||||
INPUT_JOB_STATUS,
|
||||
DISTRIBUTIONS_ONLY_MAJOR_VERSION
|
||||
@@ -382,3 +383,33 @@ export function renameWinArchive(javaArchivePath: string): string {
|
||||
fs.renameSync(javaArchivePath, javaArchivePathRenamed);
|
||||
return javaArchivePathRenamed;
|
||||
}
|
||||
|
||||
interface IAdoptiumAvailableReleases {
|
||||
most_recent_feature_release: number;
|
||||
}
|
||||
|
||||
// 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.
|
||||
export async function getLatestMajorVersion(
|
||||
http: httpm.HttpClient
|
||||
): Promise<number> {
|
||||
const availableReleasesUrl =
|
||||
'https://api.adoptium.net/v3/info/available_releases';
|
||||
|
||||
const response =
|
||||
await http.getJson<IAdoptiumAvailableReleases>(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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user