Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ For more details, see the full release notes on the [releases page](https://git

- `java-version`: The Java version that is going to be set up. Takes a whole or [semver](#supported-version-syntax) Java version. If not specified, the action will expect `java-version-file` input to be specified.

- `java-version-file`: The path to a file containing java version. Supported file types are `.java-version` and `.tool-versions`. See more details in [about .java-version-file](docs/advanced-usage.md#Java-version-file).
- `java-version-file`: The path to a file containing java version. Supported file types are `.java-version`, `.tool-versions`, and `.sdkmanrc`. See more details in [about .java-version-file](docs/advanced-usage.md#Java-version-file).

- `distribution`: _(required)_ Java [distribution](#supported-distributions).
- `distribution`: Java [distribution](#supported-distributions). Required unless `java-version-file` points to `.sdkmanrc` with a recognized distribution suffix (for example `java=21.0.5-tem`).

- `java-package`: The packaging variant of the chosen distribution. Possible values: `jdk`, `jre`, `jdk+fx`, `jre+fx`. Default value: `jdk`.

Expand Down
20 changes: 10 additions & 10 deletions __tests__/data/sdkman-java-versions.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
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
8.0.432-tem, 8.0.432
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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
64 changes: 54 additions & 10 deletions __tests__/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,59 @@ describe('validatePaginationUrl', () => {
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) => {
const actual = getVersionFromFileContent(content, 'openjdk', '.sdkmanrc');
expect(actual).toBe(expected);
['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-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'],
['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', '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);
}
);

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'
);
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', () => {
Expand All @@ -193,7 +237,7 @@ describe('getVersionFromFileContent', () => {
'openjdk',
'.sdkmanrc'
);
expect(actual).toBe(expected);
expect(actual?.version).toBe(expected);
}
);
});
Expand Down
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ inputs:
description: 'The path to a file containing the Java version to set up (.java-version, .tool-versions, .sdkmanrc). Used when java-version is not set. See examples of supported syntax in README file'
required: false
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. This input is required except when java-version-file points to .sdkmanrc with a recognized distribution suffix (e.g., java=21.0.5-tem).'
required: false
java-package:
description: 'The package type (jdk, jre, jdk+fx, jre+fx)'
required: false
Expand Down
52 changes: 45 additions & 7 deletions dist/cleanup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52509,8 +52509,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);
}
Expand All @@ -52520,14 +52521,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;
Expand All @@ -52541,13 +52551,41 @@ 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'
};
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;
Expand Down
Loading
Loading