mirror of
https://github.com/actions/setup-java.git
synced 2026-02-19 13:13:36 +00:00
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.
This commit is contained in:
parent
be666c2fcd
commit
d2b3ef8f78
@ -2,7 +2,7 @@
|
||||
7.0.352-zulu, 7.0.352
|
||||
8.0.282-trava, 8.0.282
|
||||
8.0.432-albba, 8.0.432
|
||||
8.0.432-amzn, 8.0.432
|
||||
8.0.432-amzn, 8
|
||||
8.0.432-kona, 8.0.432
|
||||
8.0.432-librca, 8.0.432
|
||||
8.0.432-sem, 8.0.432
|
||||
@ -10,7 +10,7 @@
|
||||
8.0.432-zulu, 8.0.432
|
||||
8.0.432.fx-librca, 8.0.432
|
||||
8.0.432.fx-zulu, 8.0.432
|
||||
8.0.442-amzn, 8.0.442
|
||||
8.0.442-amzn, 8
|
||||
8.0.442-librca, 8.0.442
|
||||
8.0.442-tem, 8.0.442
|
||||
8.0.442-zulu, 8.0.442
|
||||
@ -19,7 +19,7 @@
|
||||
11.0.14.1-jbr, 11.0.14
|
||||
11.0.15-trava, 11.0.15
|
||||
11.0.25-albba, 11.0.25
|
||||
11.0.25-amzn, 11.0.25
|
||||
11.0.25-amzn, 11
|
||||
11.0.25-kona, 11.0.25
|
||||
11.0.25-librca, 11.0.25
|
||||
11.0.25-ms, 11.0.25
|
||||
@ -29,7 +29,7 @@
|
||||
11.0.25-zulu, 11.0.25
|
||||
11.0.25.fx-librca, 11.0.25
|
||||
11.0.25.fx-zulu, 11.0.25
|
||||
11.0.26-amzn, 11.0.26
|
||||
11.0.26-amzn, 11
|
||||
11.0.26-librca, 11.0.26
|
||||
11.0.26-ms, 11.0.26
|
||||
11.0.26-sapmchn, 11.0.26
|
||||
@ -40,7 +40,7 @@
|
||||
17.0.12-jbr, 17.0.12
|
||||
17.0.12-oracle, 17.0.12
|
||||
17.0.13-albba, 17.0.13
|
||||
17.0.13-amzn, 17.0.13
|
||||
17.0.13-amzn, 17
|
||||
17.0.13-kona, 17.0.13
|
||||
17.0.13-librca, 17.0.13
|
||||
17.0.13-ms, 17.0.13
|
||||
@ -52,7 +52,7 @@
|
||||
17.0.13.crac-zulu, 17.0.13
|
||||
17.0.13.fx-librca, 17.0.13
|
||||
17.0.13.fx-zulu, 17.0.13
|
||||
17.0.14-amzn, 17.0.14
|
||||
17.0.14-amzn, 17
|
||||
17.0.14-librca, 17.0.14
|
||||
17.0.14-ms, 17.0.14
|
||||
17.0.14-sapmchn, 17.0.14
|
||||
@ -62,7 +62,7 @@
|
||||
17.0.9-graalce, 17.0.9
|
||||
21.0.2-graalce, 21.0.2
|
||||
21.0.2-open, 21.0.2
|
||||
21.0.5-amzn, 21.0.5
|
||||
21.0.5-amzn, 21
|
||||
21.0.5-graal, 21.0.5
|
||||
21.0.5-jbr, 21.0.5
|
||||
21.0.5-kona, 21.0.5
|
||||
@ -77,7 +77,7 @@
|
||||
21.0.5.crac-zulu, 21.0.5
|
||||
21.0.5.fx-librca, 21.0.5
|
||||
21.0.5.fx-zulu, 21.0.5
|
||||
21.0.6-amzn, 21.0.6
|
||||
21.0.6-amzn, 21
|
||||
21.0.6-graal, 21.0.6
|
||||
21.0.6-librca, 21.0.6
|
||||
21.0.6-ms, 21.0.6
|
||||
@ -94,7 +94,7 @@
|
||||
22.3.5.r17-mandrel, 22.3.5
|
||||
22.3.5.r17-nik, 22.3.5
|
||||
23-open, 23
|
||||
23.0.1-amzn, 23.0.1
|
||||
23.0.1-amzn, 23
|
||||
23.0.1-graal, 23.0.1
|
||||
23.0.1-graalce, 23.0.1
|
||||
23.0.1-librca, 23.0.1
|
||||
@ -106,7 +106,7 @@
|
||||
23.0.1.crac-zulu, 23.0.1
|
||||
23.0.1.fx-librca, 23.0.1
|
||||
23.0.1.fx-zulu, 23.0.1
|
||||
23.0.2-amzn, 23.0.2
|
||||
23.0.2-amzn, 23
|
||||
23.0.2-graal, 23.0.2
|
||||
23.0.2-graalce, 23.0.2
|
||||
23.0.2-librca, 23.0.2
|
||||
|
||||
|
@ -88,15 +88,41 @@ describe('convertVersionToSemver', () => {
|
||||
describe('getVersionFromFileContent', () => {
|
||||
describe('.sdkmanrc', () => {
|
||||
it.each([
|
||||
['java=11.0.20.1-tem', '11.0.20'],
|
||||
['java = 11.0.20.1-tem', '11.0.20'],
|
||||
['java=11.0.20.1-tem # a comment in sdkmanrc', '11.0.20'],
|
||||
['java=11.0.20.1-tem\n#java=21.0.20.1-tem\n', '11.0.20'], // choose first match
|
||||
['java=11.0.20.1-tem\njava=21.0.20.1-tem\n', '11.0.20'], // choose first match
|
||||
['#java=11.0.20.1-tem\njava=21.0.20.1-tem\n', '21.0.20'] // first one is 'commented' in .sdkmanrc
|
||||
])('parsing %s should return %s', (content: string, expected: string) => {
|
||||
['java=11.0.20.1-tem', '11.0.20', 'temurin'],
|
||||
['java = 11.0.20.1-tem', '11.0.20', 'temurin'],
|
||||
['java=11.0.20.1-tem # a comment in sdkmanrc', '11.0.20', 'temurin'],
|
||||
['java=11.0.20.1-tem\n#java=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', '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-amzn', '17', 'corretto'],
|
||||
['java=21.0.5-graal', '21.0.5', 'graalvm'],
|
||||
['java=17.0.9-graalce', '17.0.9', 'graalvm'],
|
||||
['java=11.0.25-librca', '11.0.25', 'liberica'],
|
||||
['java=11.0.25-ms', '11.0.25', 'microsoft'],
|
||||
['java=21.0.5-oracle', '21.0.5', 'oracle'],
|
||||
['java=11.0.25-sapmchn', '11.0.25', 'sapmachine'],
|
||||
['java=21.0.5-jbr', '21.0.5', 'jetbrains'],
|
||||
['java=11.0.25-sem', '11.0.25', 'temurin'],
|
||||
['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).toBe(expected);
|
||||
expect(actual?.version).toBe(expectedVersion);
|
||||
expect(actual?.distribution).toBe(expectedDist);
|
||||
});
|
||||
|
||||
it('should warn and return undefined distribution for unknown identifier', () => {
|
||||
const warnSpy = jest.spyOn(require('@actions/core'), 'warning');
|
||||
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'));
|
||||
});
|
||||
|
||||
it('should return version without distribution when no suffix provided', () => {
|
||||
const actual = getVersionFromFileContent('java=11.0.20', 'temurin', '.sdkmanrc');
|
||||
expect(actual?.version).toBe('11.0.20');
|
||||
expect(actual?.distribution).toBeUndefined();
|
||||
});
|
||||
|
||||
describe('known versions', () => {
|
||||
@ -115,7 +141,7 @@ describe('getVersionFromFileContent', () => {
|
||||
'openjdk',
|
||||
'.sdkmanrc'
|
||||
);
|
||||
expect(actual).toBe(expected);
|
||||
expect(actual?.version).toBe(expected);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
@ -8,8 +8,8 @@ inputs:
|
||||
java-version-file:
|
||||
description: 'The path to the `.java-version` file. See examples of supported syntax in README file'
|
||||
distribution:
|
||||
description: 'Java distribution. See the list of supported distributions in README file'
|
||||
required: true
|
||||
description: 'Java distribution. See the list of supported distributions in README file. When using .sdkmanrc with a distribution suffix (e.g., java=21.0.5-tem), this input is optional.'
|
||||
required: false
|
||||
java-package:
|
||||
description: 'The package type (jdk, jre, jdk+fx, jre+fx)'
|
||||
required: false
|
||||
|
||||
50
dist/cleanup/index.js
vendored
50
dist/cleanup/index.js
vendored
@ -49755,8 +49755,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);
|
||||
}
|
||||
@ -49766,14 +49767,22 @@ 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;
|
||||
@ -49787,13 +49796,40 @@ 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': 'temurin',
|
||||
'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) {
|
||||
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;
|
||||
|
||||
104
dist/setup/index.js
vendored
104
dist/setup/index.js
vendored
@ -87511,9 +87511,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);
|
||||
@ -87529,26 +87527,48 @@ function run() {
|
||||
if (!versions.length && !versionFile) {
|
||||
throw new Error('java-version or java-version-file input expected');
|
||||
}
|
||||
const installerInputsOptions = {
|
||||
architecture,
|
||||
packageType,
|
||||
checkLatest,
|
||||
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,
|
||||
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,
|
||||
distributionName,
|
||||
jdkFile,
|
||||
toolchainIds
|
||||
};
|
||||
for (const [index, version] of versions.entries()) {
|
||||
yield installVersion(version, installerInputsOptions, index);
|
||||
}
|
||||
}
|
||||
core.endGroup();
|
||||
const matchersPath = path.join(__dirname, '..', '..', '.github');
|
||||
@ -87899,8 +87919,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);
|
||||
}
|
||||
@ -87910,14 +87931,22 @@ 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;
|
||||
@ -87931,13 +87960,40 @@ 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': 'temurin',
|
||||
'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) {
|
||||
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;
|
||||
|
||||
7
package-lock.json
generated
7
package-lock.json
generated
@ -496,7 +496,6 @@
|
||||
"resolved": "https://registry.npmjs.org/@babel/core/-/core-7.23.3.tgz",
|
||||
"integrity": "sha512-Jg+msLuNuCJDyBvFv5+OKOUjWMZgd85bKjbICd3zWrKAo+bJ49HJufi7CQE0q0uR8NGyO6xkCACScNqyjHSZew==",
|
||||
"dev": true,
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@ampproject/remapping": "^2.2.0",
|
||||
"@babel/code-frame": "^7.22.13",
|
||||
@ -1788,7 +1787,6 @@
|
||||
"integrity": "sha512-B7RIQiTsCBBmY+yW4+ILd6mF5h1FUwJsVvpqkrgpszYifetQ2Ke+Z4u6aZh0CblkUGIdR59iYVyXqqZGkZ3aBw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@typescript-eslint/scope-manager": "8.43.0",
|
||||
"@typescript-eslint/types": "8.43.0",
|
||||
@ -2037,7 +2035,6 @@
|
||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz",
|
||||
"integrity": "sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==",
|
||||
"dev": true,
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"acorn": "bin/acorn"
|
||||
},
|
||||
@ -2317,7 +2314,6 @@
|
||||
"url": "https://github.com/sponsors/ai"
|
||||
}
|
||||
],
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"caniuse-lite": "^1.0.30001541",
|
||||
"electron-to-chromium": "^1.4.535",
|
||||
@ -2687,7 +2683,6 @@
|
||||
"resolved": "https://registry.npmjs.org/eslint/-/eslint-8.57.0.tgz",
|
||||
"integrity": "sha512-dZ6+mexnaTIbSBZWgou51U6OmzIhYM2VcNdtiTtI7qPNZm35Akpr0f6vtw3w1Kmn5PYo+tZVfh13WrhpS6oLqQ==",
|
||||
"dev": true,
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@eslint-community/eslint-utils": "^4.2.0",
|
||||
"@eslint-community/regexpp": "^4.6.1",
|
||||
@ -3634,7 +3629,6 @@
|
||||
"resolved": "https://registry.npmjs.org/jest/-/jest-29.7.0.tgz",
|
||||
"integrity": "sha512-NIy3oAFp9shda19hy4HK0HRTWKtPJmGdnvywu01nOqNC2vZg+Z+fvJDxpMQA88eb2I9EcafcdjYgsDthnYTvGw==",
|
||||
"dev": true,
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@jest/core": "^29.7.0",
|
||||
"@jest/types": "^29.6.3",
|
||||
@ -5299,7 +5293,6 @@
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz",
|
||||
"integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==",
|
||||
"dev": true,
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
"tsserver": "bin/tsserver"
|
||||
|
||||
@ -16,9 +16,7 @@ import {JavaInstallerOptions} from './distributions/base-models';
|
||||
async function run() {
|
||||
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);
|
||||
@ -40,39 +38,63 @@ async function run() {
|
||||
throw new Error('java-version or java-version-file input expected');
|
||||
}
|
||||
|
||||
const installerInputsOptions: installerInputsOptions = {
|
||||
architecture,
|
||||
packageType,
|
||||
checkLatest,
|
||||
distributionName,
|
||||
jdkFile,
|
||||
toolchainIds
|
||||
};
|
||||
|
||||
if (!versions.length) {
|
||||
core.debug(
|
||||
'java-version input is empty, looking for java-version-file input'
|
||||
);
|
||||
const content = fs.readFileSync(versionFile).toString().trim();
|
||||
|
||||
const version = getVersionFromFileContent(
|
||||
const versionInfo = getVersionFromFileContent(
|
||||
content,
|
||||
distributionName,
|
||||
versionFile
|
||||
);
|
||||
core.debug(`Parsed version from file '${version}'`);
|
||||
core.debug(`Parsed version from file '${versionInfo?.version}'`);
|
||||
|
||||
if (!version) {
|
||||
if (!versionInfo) {
|
||||
throw new Error(
|
||||
`No supported version was found in file ${versionFile}`
|
||||
);
|
||||
}
|
||||
|
||||
await 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'
|
||||
);
|
||||
}
|
||||
|
||||
for (const [index, version] of versions.entries()) {
|
||||
await installVersion(version, installerInputsOptions, index);
|
||||
const installerInputsOptions: installerInputsOptions = {
|
||||
architecture,
|
||||
packageType,
|
||||
checkLatest,
|
||||
distributionName,
|
||||
jdkFile,
|
||||
toolchainIds
|
||||
};
|
||||
|
||||
await installVersion(versionInfo.version, installerInputsOptions);
|
||||
} else {
|
||||
// When using java-version input, distribution is still required
|
||||
if (!distributionName) {
|
||||
throw new Error('distribution input is required');
|
||||
}
|
||||
|
||||
const installerInputsOptions: installerInputsOptions = {
|
||||
architecture,
|
||||
packageType,
|
||||
checkLatest,
|
||||
distributionName,
|
||||
jdkFile,
|
||||
toolchainIds
|
||||
};
|
||||
|
||||
for (const [index, version] of versions.entries()) {
|
||||
await installVersion(version, installerInputsOptions, index);
|
||||
}
|
||||
}
|
||||
core.endGroup();
|
||||
const matchersPath = path.join(__dirname, '..', '..', '.github');
|
||||
|
||||
60
src/util.ts
60
src/util.ts
@ -119,12 +119,18 @@ export function isCacheFeatureAvailable(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
export interface VersionInfo {
|
||||
version: string;
|
||||
distribution?: string;
|
||||
}
|
||||
|
||||
export function getVersionFromFileContent(
|
||||
content: string,
|
||||
distributionName: string,
|
||||
versionFile: string
|
||||
): string | null {
|
||||
): VersionInfo | null {
|
||||
let javaVersionRegExp: RegExp;
|
||||
let extractedDistribution: string | undefined;
|
||||
|
||||
function getFileName(versionFile: string) {
|
||||
return path.basename(versionFile);
|
||||
@ -135,15 +141,26 @@ export function getVersionFromFileContent(
|
||||
javaVersionRegExp =
|
||||
/^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 = content.match(javaVersionRegExp)?.groups?.version
|
||||
? (content.match(javaVersionRegExp)?.groups?.version as string)
|
||||
const match = content.match(javaVersionRegExp);
|
||||
const capturedVersion = match?.groups?.version
|
||||
? (match.groups.version as string)
|
||||
: '';
|
||||
|
||||
// Extract distribution from .sdkmanrc file
|
||||
if (versionFileName == '.sdkmanrc' && match?.groups?.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}'`
|
||||
);
|
||||
@ -164,12 +181,43 @@ export function getVersionFromFileContent(
|
||||
return null;
|
||||
}
|
||||
|
||||
if (DISTRIBUTIONS_ONLY_MAJOR_VERSION.includes(distributionName)) {
|
||||
// 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)) {
|
||||
const coerceVersion = semver.coerce(version) ?? version;
|
||||
version = semver.major(coerceVersion).toString();
|
||||
}
|
||||
|
||||
return version.toString();
|
||||
return {
|
||||
version: version.toString(),
|
||||
distribution: extractedDistribution
|
||||
};
|
||||
}
|
||||
|
||||
// Map SDKMAN distribution identifiers to setup-java distribution names
|
||||
function mapSdkmanDistribution(sdkmanDist: string): string | undefined {
|
||||
const distributionMap: Record<string, string> = {
|
||||
'tem': 'temurin',
|
||||
'sem': 'temurin',
|
||||
'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) {
|
||||
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`
|
||||
|
||||
Loading…
Reference in New Issue
Block a user