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:
@@ -56,7 +56,8 @@ const {
|
||||
isVersionSatisfies,
|
||||
isCacheFeatureAvailable,
|
||||
isGhes,
|
||||
validatePaginationUrl
|
||||
validatePaginationUrl,
|
||||
getLatestMajorVersion
|
||||
} = await import('../src/util.js');
|
||||
|
||||
describe('isVersionSatisfies', () => {
|
||||
@@ -400,3 +401,33 @@ describe('isGhes', () => {
|
||||
expect(isGhes()).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('getLatestMajorVersion', () => {
|
||||
const makeHttp = (getJson: jest.Mock) =>
|
||||
({getJson}) as unknown as import('@actions/http-client').HttpClient;
|
||||
|
||||
it('returns most_recent_feature_release from the Adoptium API', async () => {
|
||||
const getJson = jest.fn(async () => ({
|
||||
statusCode: 200,
|
||||
result: {most_recent_feature_release: 25},
|
||||
headers: {}
|
||||
}));
|
||||
|
||||
await expect(getLatestMajorVersion(makeHttp(getJson))).resolves.toBe(25);
|
||||
expect(getJson).toHaveBeenCalledWith(
|
||||
'https://api.adoptium.net/v3/info/available_releases'
|
||||
);
|
||||
});
|
||||
|
||||
it('throws when the response does not contain a usable value', async () => {
|
||||
const getJson = jest.fn(async () => ({
|
||||
statusCode: 200,
|
||||
result: {},
|
||||
headers: {}
|
||||
}));
|
||||
|
||||
await expect(getLatestMajorVersion(makeHttp(getJson))).rejects.toThrow(
|
||||
'Could not determine the latest available Java major version'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user