feat: Add distribution detection support to .sdkmanrc file (#975)

* feat: Add distribution detection support to .sdkmanrc file

Extends .sdkmanrc support to automatically detect Java distribution from SDKMAN identifiers (e.g., java=21.0.5-tem maps to temurin distribution).

Makes distribution input optional when using .sdkmanrc with distribution suffix.

* fix: align SDKMAN sem identifier mapping

* fix: support SDKMAN albba identifier

* docs: clarify sdkmanrc distribution inference scope

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Add Tencent Kona SDKMAN mapping and format sdkmanrc docs as a table

- Map SDKMAN 'kona' identifier to the 'kona' distribution (added in #672)
- Add a .sdkmanrc test case for the kona suffix
- Convert the inline SDKMAN suffix mapping in advanced-usage.md to a table
- Rebuild dist bundles

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Bruno Borges <brborges@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Bruno Borges <bruno.borges@gmail.com>
This commit is contained in:
Lukasz
2026-07-07 20:49:12 +02:00
committed by GitHub
parent c4922bf809
commit 0f481fcb61
9 changed files with 333 additions and 89 deletions
+89 -27
View File
@@ -81542,9 +81542,7 @@ function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
const versions = core.getMultilineInput(constants.INPUT_JAVA_VERSION);
const distributionName = core.getInput(constants.INPUT_DISTRIBUTION, {
required: true
});
let distributionName = core.getInput(constants.INPUT_DISTRIBUTION);
const versionFile = core.getInput(constants.INPUT_JAVA_VERSION_FILE);
const architecture = core.getInput(constants.INPUT_ARCHITECTURE);
const packageType = core.getInput(constants.INPUT_JAVA_PACKAGE);
@@ -81563,29 +81561,54 @@ function run() {
if (!versions.length && !versionFile) {
throw new Error('java-version or java-version-file input expected');
}
const installerInputsOptions = {
architecture,
packageType,
checkLatest,
setDefault,
verifySignature,
verifySignaturePublicKey,
distributionName,
jdkFile,
toolchainIds
};
if (!versions.length) {
core.debug('java-version input is empty, looking for java-version-file input');
const content = fs_1.default.readFileSync(versionFile).toString().trim();
const version = (0, util_1.getVersionFromFileContent)(content, distributionName, versionFile);
core.debug(`Parsed version from file '${version}'`);
if (!version) {
const versionInfo = (0, util_1.getVersionFromFileContent)(content, distributionName, versionFile);
core.debug(`Parsed version from file '${versionInfo === null || versionInfo === void 0 ? void 0 : versionInfo.version}'`);
if (!versionInfo) {
throw new Error(`No supported version was found in file ${versionFile}`);
}
yield installVersion(version, installerInputsOptions);
// Use distribution from file if available, otherwise use the input
if (versionInfo.distribution) {
core.info(`Using distribution '${versionInfo.distribution}' from ${versionFile}`);
distributionName = versionInfo.distribution;
}
else if (!distributionName) {
throw new Error('distribution input is required when not specified in the version file');
}
const installerInputsOptions = {
architecture,
packageType,
checkLatest,
setDefault,
verifySignature,
verifySignaturePublicKey,
distributionName,
jdkFile,
toolchainIds
};
yield installVersion(versionInfo.version, installerInputsOptions);
}
for (const [index, version] of versions.entries()) {
yield installVersion(version, installerInputsOptions, index);
else {
// When using java-version input, distribution is still required
if (!distributionName) {
throw new Error('distribution input is required');
}
const installerInputsOptions = {
architecture,
packageType,
checkLatest,
setDefault,
verifySignature,
verifySignaturePublicKey,
distributionName,
jdkFile,
toolchainIds
};
for (const [index, version] of versions.entries()) {
yield installVersion(version, installerInputsOptions, index);
}
}
core.endGroup();
const matchersPath = path.join(__dirname, '..', '..', '.github');
@@ -81967,8 +81990,9 @@ function isCacheFeatureAvailable() {
}
exports.isCacheFeatureAvailable = isCacheFeatureAvailable;
function getVersionFromFileContent(content, distributionName, versionFile) {
var _a, _b, _c, _d, _e;
var _a, _b, _c;
let javaVersionRegExp;
let extractedDistribution;
function getFileName(versionFile) {
return path_1.default.basename(versionFile);
}
@@ -81978,14 +82002,23 @@ function getVersionFromFileContent(content, distributionName, versionFile) {
/^java\s+(?:\S*-)?(?<version>\d+(?:\.\d+)*([+_.-](?:openj9[-._]?\d[\w.-]*|java\d+|jre[-_\w]*|OpenJDK\d+[\w_.-]*|[a-z0-9]+))*)/im;
}
else if (versionFileName == '.sdkmanrc') {
javaVersionRegExp = /^java\s*=\s*(?<version>[^-]+)/m;
// Match both version and optional distribution identifier
javaVersionRegExp =
/^java\s*=\s*(?<version>[^-\s]+)(?:-(?<distribution>[a-z0-9]+))?/m;
}
else {
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
}
const capturedVersion = ((_b = (_a = content.match(javaVersionRegExp)) === null || _a === void 0 ? void 0 : _a.groups) === null || _b === void 0 ? void 0 : _b.version)
? (_d = (_c = content.match(javaVersionRegExp)) === null || _c === void 0 ? void 0 : _c.groups) === null || _d === void 0 ? void 0 : _d.version
const match = content.match(javaVersionRegExp);
const capturedVersion = ((_a = match === null || match === void 0 ? void 0 : match.groups) === null || _a === void 0 ? void 0 : _a.version)
? match.groups.version
: '';
// Extract distribution from .sdkmanrc file
if (versionFileName == '.sdkmanrc' && ((_b = match === null || match === void 0 ? void 0 : match.groups) === null || _b === void 0 ? void 0 : _b.distribution)) {
const sdkmanDist = match.groups.distribution;
extractedDistribution = mapSdkmanDistribution(sdkmanDist);
core.debug(`Parsed distribution '${extractedDistribution}' from SDKMAN identifier '${sdkmanDist}'`);
}
core.debug(`Parsed version '${capturedVersion}' from file '${versionFileName}'`);
if (!capturedVersion) {
return null;
@@ -81999,13 +82032,42 @@ function getVersionFromFileContent(content, distributionName, versionFile) {
if (!version) {
return null;
}
if (constants_1.DISTRIBUTIONS_ONLY_MAJOR_VERSION.includes(distributionName)) {
const coerceVersion = (_e = semver.coerce(version)) !== null && _e !== void 0 ? _e : version;
// Apply DISTRIBUTIONS_ONLY_MAJOR_VERSION logic whenever the effective distribution
// (either explicitly provided or extracted from the version file) is in the list.
if (constants_1.DISTRIBUTIONS_ONLY_MAJOR_VERSION.includes(extractedDistribution || distributionName)) {
const coerceVersion = (_c = semver.coerce(version)) !== null && _c !== void 0 ? _c : version;
version = semver.major(coerceVersion).toString();
}
return version.toString();
return {
version: version.toString(),
distribution: extractedDistribution
};
}
exports.getVersionFromFileContent = getVersionFromFileContent;
// Map SDKMAN distribution identifiers to setup-java distribution names
function mapSdkmanDistribution(sdkmanDist) {
const distributionMap = {
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',
kona: 'kona'
};
const mapped = distributionMap[sdkmanDist.toLowerCase()];
if (!mapped) {
core.warning(`Unknown SDKMAN distribution identifier '${sdkmanDist}'. Please specify the distribution explicitly.`);
}
return mapped;
}
// By convention, action expects version 8 in the format `8.*` instead of `1.8`
function avoidOldNotation(content) {
return content.startsWith('1.') ? content.substring(2) : content;