fix: support SDKMAN albba identifier

This commit is contained in:
lukaszgyg 2026-03-24 19:49:56 +01:00
parent 042265994c
commit e082345d2e
5 changed files with 79 additions and 49 deletions

View File

@ -95,6 +95,7 @@ describe('getVersionFromFileContent', () => {
['java=11.0.20.1-tem\njava=21.0.20.1-tem\n', '11.0.20', 'temurin'], // choose first match
['#java=11.0.20.1-tem\njava=21.0.20.1-tem\n', '21.0.20', 'temurin'], // first one is 'commented' in .sdkmanrc
['java=21.0.5-zulu', '21.0.5', 'zulu'],
['java=17.0.13-albba', '17.0.13', 'dragonwell'],
['java=17.0.13-amzn', '17', 'corretto'],
['java=21.0.5-graal', '21.0.5', 'graalvm'],
['java=17.0.9-graalce', '17.0.9', 'graalvm'],
@ -105,22 +106,39 @@ describe('getVersionFromFileContent', () => {
['java=21.0.5-jbr', '21.0.5', 'jetbrains'],
['java=11.0.25-sem', '11.0.25', 'semeru'],
['java=17.0.13-dragonwell', '17.0.13', 'dragonwell']
])('parsing %s should return version %s and distribution %s', (content: string, expectedVersion: string, expectedDist: string) => {
const actual = getVersionFromFileContent(content, 'openjdk', '.sdkmanrc');
expect(actual?.version).toBe(expectedVersion);
expect(actual?.distribution).toBe(expectedDist);
});
])(
'parsing %s should return version %s and distribution %s',
(content: string, expectedVersion: string, expectedDist: string) => {
const actual = getVersionFromFileContent(
content,
'openjdk',
'.sdkmanrc'
);
expect(actual?.version).toBe(expectedVersion);
expect(actual?.distribution).toBe(expectedDist);
}
);
it('should warn and return undefined distribution for unknown identifier', () => {
const warnSpy = jest.spyOn(core, 'warning');
const actual = getVersionFromFileContent('java=21.0.5-unknown', 'temurin', '.sdkmanrc');
const actual = getVersionFromFileContent(
'java=21.0.5-unknown',
'temurin',
'.sdkmanrc'
);
expect(actual?.version).toBe('21.0.5');
expect(actual?.distribution).toBeUndefined();
expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('Unknown SDKMAN distribution identifier'));
expect(warnSpy).toHaveBeenCalledWith(
expect.stringContaining('Unknown SDKMAN distribution identifier')
);
});
it('should return version without distribution when no suffix provided', () => {
const actual = getVersionFromFileContent('java=11.0.20', 'temurin', '.sdkmanrc');
const actual = getVersionFromFileContent(
'java=11.0.20',
'temurin',
'.sdkmanrc'
);
expect(actual?.version).toBe('11.0.20');
expect(actual?.distribution).toBeUndefined();
});

28
dist/cleanup/index.js vendored
View File

@ -49768,7 +49768,8 @@ function getVersionFromFileContent(content, distributionName, versionFile) {
}
else if (versionFileName == '.sdkmanrc') {
// Match both version and optional distribution identifier
javaVersionRegExp = /^java\s*=\s*(?<version>[^-\s]+)(?:-(?<distribution>[a-z0-9]+))?/m;
javaVersionRegExp =
/^java\s*=\s*(?<version>[^-\s]+)(?:-(?<distribution>[a-z0-9]+))?/m;
}
else {
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
@ -49811,18 +49812,19 @@ exports.getVersionFromFileContent = getVersionFromFileContent;
// Map SDKMAN distribution identifiers to setup-java distribution names
function mapSdkmanDistribution(sdkmanDist) {
const distributionMap = {
'tem': 'temurin',
'sem': 'semeru',
'zulu': 'zulu',
'amzn': 'corretto',
'graal': 'graalvm',
'graalce': 'graalvm',
'librca': 'liberica',
'ms': 'microsoft',
'oracle': 'oracle',
'sapmchn': 'sapmachine',
'jbr': 'jetbrains',
'dragonwell': 'dragonwell'
tem: 'temurin',
sem: 'semeru',
albba: 'dragonwell',
zulu: 'zulu',
amzn: 'corretto',
graal: 'graalvm',
graalce: 'graalvm',
librca: 'liberica',
ms: 'microsoft',
oracle: 'oracle',
sapmchn: 'sapmachine',
jbr: 'jetbrains',
dragonwell: 'dragonwell'
};
const mapped = distributionMap[sdkmanDist.toLowerCase()];
if (!mapped) {

28
dist/setup/index.js vendored
View File

@ -87932,7 +87932,8 @@ function getVersionFromFileContent(content, distributionName, versionFile) {
}
else if (versionFileName == '.sdkmanrc') {
// Match both version and optional distribution identifier
javaVersionRegExp = /^java\s*=\s*(?<version>[^-\s]+)(?:-(?<distribution>[a-z0-9]+))?/m;
javaVersionRegExp =
/^java\s*=\s*(?<version>[^-\s]+)(?:-(?<distribution>[a-z0-9]+))?/m;
}
else {
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
@ -87975,18 +87976,19 @@ exports.getVersionFromFileContent = getVersionFromFileContent;
// Map SDKMAN distribution identifiers to setup-java distribution names
function mapSdkmanDistribution(sdkmanDist) {
const distributionMap = {
'tem': 'temurin',
'sem': 'semeru',
'zulu': 'zulu',
'amzn': 'corretto',
'graal': 'graalvm',
'graalce': 'graalvm',
'librca': 'liberica',
'ms': 'microsoft',
'oracle': 'oracle',
'sapmchn': 'sapmachine',
'jbr': 'jetbrains',
'dragonwell': 'dragonwell'
tem: 'temurin',
sem: 'semeru',
albba: 'dragonwell',
zulu: 'zulu',
amzn: 'corretto',
graal: 'graalvm',
graalce: 'graalvm',
librca: 'liberica',
ms: 'microsoft',
oracle: 'oracle',
sapmchn: 'sapmachine',
jbr: 'jetbrains',
dragonwell: 'dragonwell'
};
const mapped = distributionMap[sdkmanDist.toLowerCase()];
if (!mapped) {

View File

@ -59,7 +59,9 @@ async function run() {
// Use distribution from file if available, otherwise use the input
if (versionInfo.distribution) {
core.info(`Using distribution '${versionInfo.distribution}' from ${versionFile}`);
core.info(
`Using distribution '${versionInfo.distribution}' from ${versionFile}`
);
distributionName = versionInfo.distribution;
} else if (!distributionName) {
throw new Error(

View File

@ -142,7 +142,8 @@ export function getVersionFromFileContent(
/^java\s+(?:\S*-)?(?<version>\d+(?:\.\d+)*([+_.-](?:openj9[-._]?\d[\w.-]*|java\d+|jre[-_\w]*|OpenJDK\d+[\w_.-]*|[a-z0-9]+))*)/im;
} else if (versionFileName == '.sdkmanrc') {
// Match both version and optional distribution identifier
javaVersionRegExp = /^java\s*=\s*(?<version>[^-\s]+)(?:-(?<distribution>[a-z0-9]+))?/m;
javaVersionRegExp =
/^java\s*=\s*(?<version>[^-\s]+)(?:-(?<distribution>[a-z0-9]+))?/m;
} else {
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
}
@ -183,7 +184,11 @@ export function getVersionFromFileContent(
// Apply DISTRIBUTIONS_ONLY_MAJOR_VERSION logic whenever the effective distribution
// (either explicitly provided or extracted from the version file) is in the list.
if (DISTRIBUTIONS_ONLY_MAJOR_VERSION.includes(extractedDistribution || distributionName)) {
if (
DISTRIBUTIONS_ONLY_MAJOR_VERSION.includes(
extractedDistribution || distributionName
)
) {
const coerceVersion = semver.coerce(version) ?? version;
version = semver.major(coerceVersion).toString();
}
@ -197,18 +202,19 @@ export function getVersionFromFileContent(
// Map SDKMAN distribution identifiers to setup-java distribution names
function mapSdkmanDistribution(sdkmanDist: string): string | undefined {
const distributionMap: Record<string, string> = {
'tem': 'temurin',
'sem': 'semeru',
'zulu': 'zulu',
'amzn': 'corretto',
'graal': 'graalvm',
'graalce': 'graalvm',
'librca': 'liberica',
'ms': 'microsoft',
'oracle': 'oracle',
'sapmchn': 'sapmachine',
'jbr': 'jetbrains',
'dragonwell': 'dragonwell'
tem: 'temurin',
sem: 'semeru',
albba: 'dragonwell',
zulu: 'zulu',
amzn: 'corretto',
graal: 'graalvm',
graalce: 'graalvm',
librca: 'liberica',
ms: 'microsoft',
oracle: 'oracle',
sapmchn: 'sapmachine',
jbr: 'jetbrains',
dragonwell: 'dragonwell'
};
const mapped = distributionMap[sdkmanDist.toLowerCase()];