mirror of
https://github.com/actions/setup-java.git
synced 2026-11-06 09:50:31 +08:00
Fix Liberica SDKMAN patch release resolution (#1291)
* Fix Liberica SDKMAN patch release resolution Preserve BellSoft's fourth version component as SDKMAN patch metadata and cover real API version formats for Java 17 and 25. Fixes #1290 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: d5b53868-538f-4c5f-b2aa-c66dc4ad06e2 * Fix Liberica patch ordering and build-less requests Share overridable matching and ordering with toolcache selection. Keep patch-only requests distinct from exact SDKMAN build requests and cover the reported API pair across remote and cached resolution. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: d5b53868-538f-4c5f-b2aa-c66dc4ad06e2 --------- Copilot-Session: d5b53868-538f-4c5f-b2aa-c66dc4ad06e2
This commit is contained in:
co-authored by
Copilot App
parent
b843ebf9b9
commit
816722acf8
@@ -241,7 +241,7 @@ export abstract class JavaBase {
|
||||
if (javaRelease.floating) {
|
||||
if (
|
||||
!semver.valid(foundJava.version) ||
|
||||
!isVersionSatisfies(this.version, foundJava.version)
|
||||
!this.isVersionSatisfied(this.version, foundJava.version)
|
||||
) {
|
||||
throw new Error(
|
||||
`The downloaded ${this.distribution} artifact reported Java ${foundJava.version}, which does not satisfy '${this.version}'.`
|
||||
@@ -401,7 +401,7 @@ export abstract class JavaBase {
|
||||
}
|
||||
if (
|
||||
!semver.valid(restored.release.version) ||
|
||||
!isVersionSatisfies(this.version, restored.release.version)
|
||||
!this.isVersionSatisfied(this.version, restored.release.version)
|
||||
) {
|
||||
core.debug(
|
||||
`Ignoring the cached concrete version '${restored.release.version}' for ${this.distribution} ${this.version}.`
|
||||
@@ -622,10 +622,10 @@ export abstract class JavaBase {
|
||||
.filter(item => item.stable === this.stable);
|
||||
|
||||
const satisfiedVersions = availableVersions
|
||||
.filter(item => isVersionSatisfies(this.version, item.version))
|
||||
.filter(item => this.isVersionSatisfied(this.version, item.version))
|
||||
.filter(item => item.path)
|
||||
.sort((a, b) => {
|
||||
return -semver.compareBuild(a.version, b.version);
|
||||
return -this.compareVersions(a.version, b.version);
|
||||
});
|
||||
if (!satisfiedVersions || satisfiedVersions.length === 0) {
|
||||
return null;
|
||||
@@ -637,6 +637,14 @@ export abstract class JavaBase {
|
||||
};
|
||||
}
|
||||
|
||||
protected isVersionSatisfied(range: string, version: string): boolean {
|
||||
return isVersionSatisfies(range, version);
|
||||
}
|
||||
|
||||
protected compareVersions(a: string, b: string): number {
|
||||
return semver.compareBuild(a, b);
|
||||
}
|
||||
|
||||
protected normalizeVersion(version: string) {
|
||||
let stable = true;
|
||||
const latest = false;
|
||||
|
||||
@@ -9,7 +9,6 @@ import {
|
||||
cacheJdkDir,
|
||||
extractJdkFile,
|
||||
getDownloadArchiveExtension,
|
||||
isVersionSatisfies,
|
||||
renameWinArchive
|
||||
} from '../../util.js';
|
||||
import * as core from '@actions/core';
|
||||
@@ -66,8 +65,8 @@ export class LibericaDistributions extends JavaBase {
|
||||
}));
|
||||
|
||||
const satisfiedVersion = availableVersions
|
||||
.filter(item => isVersionSatisfies(range, item.version))
|
||||
.sort((a, b) => -semver.compareBuild(a.version, b.version))[0];
|
||||
.filter(item => this.isVersionSatisfied(range, item.version))
|
||||
.sort((a, b) => -this.compareVersions(a.version, b.version))[0];
|
||||
|
||||
if (!satisfiedVersion) {
|
||||
const availableVersionStrings = availableVersions.map(
|
||||
@@ -79,6 +78,45 @@ export class LibericaDistributions extends JavaBase {
|
||||
return satisfiedVersion;
|
||||
}
|
||||
|
||||
protected normalizeVersion(version: string) {
|
||||
const normalized = super.normalizeVersion(version);
|
||||
if (/^\d+\.\d+\.\d+\.\d+(?:-ea)?$/.test(version)) {
|
||||
// Keep patch-only requests distinct from exact SDKMAN build requests.
|
||||
normalized.version = version.replace(/-ea$/, '');
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
|
||||
protected isVersionSatisfied(range: string, version: string): boolean {
|
||||
const patchRequest = range.match(/^(\d+\.\d+\.\d+)\.(\d+)$/);
|
||||
if (patchRequest) {
|
||||
const candidate = semver.parse(version);
|
||||
if (!candidate || !semver.eq(patchRequest[1], candidate)) {
|
||||
return false;
|
||||
}
|
||||
const patch = candidate.build.length > 1 ? candidate.build[0] : '0';
|
||||
return patch === patchRequest[2];
|
||||
}
|
||||
return super.isVersionSatisfied(range, version);
|
||||
}
|
||||
|
||||
protected compareVersions(a: string, b: string): number {
|
||||
const mainComparison = semver.compare(a, b);
|
||||
if (mainComparison !== 0) {
|
||||
return mainComparison;
|
||||
}
|
||||
|
||||
// SDKMAN encodes patch.build, but unpatched releases contain only build.
|
||||
const patchAndBuild = (version: string): string => {
|
||||
const build = new semver.SemVer(version).build;
|
||||
return (build.length > 1 ? build : ['0', ...build]).join('.');
|
||||
};
|
||||
return semver.compareBuild(
|
||||
`0.0.0+${patchAndBuild(a)}`,
|
||||
`0.0.0+${patchAndBuild(b)}`
|
||||
);
|
||||
}
|
||||
|
||||
private async getAvailableVersions(): Promise<LibericaVersion[]> {
|
||||
if (core.isDebug()) {
|
||||
console.time('Retrieving available versions for Liberica took'); // eslint-disable-line no-console
|
||||
@@ -171,6 +209,10 @@ export class LibericaDistributions extends JavaBase {
|
||||
const mainVersion = [featureVersion, interimVersion, updateVersion].join(
|
||||
'.'
|
||||
);
|
||||
const patchVersion = version.version.split('+')[0].split('.')[3];
|
||||
if (patchVersion) {
|
||||
return `${mainVersion}+${patchVersion}.${buildVersion}`;
|
||||
}
|
||||
if (buildVersion != 0) {
|
||||
return `${mainVersion}+${buildVersion}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user