Skip to content

Commit 4e7e684

Browse files
feat: Add support for .sdkmanrc file in java-version-file parameter (#736)
* chore(e2e-versions): Add e2e test scenario on `setup-java-version-from-file-major-minor-patch-with-dist` for `.sdkmanrc` * chore(e2e-versions): Update `setup-java-version-from-file-major-minor-patch-with-dist` test to include the file name of the java-version-file that is used * feat: Add support for `.sdkmanrc` as *Java Version File* * chore: Add test for the latest known sdkman java versions * docs(advanced-usage): Document support for `.sdkmanrc` as java-version-file * chore(docs): Anyone can contribute and maintain 🤷 * Update advanced-usage.md Add example step/file for `.sdkmanrc` * Update advanced-usage.md * Update util.ts * chore: format and rebuild * chore: untouch toolchains.ts * fix check dist error --------- Co-authored-by: mahabaleshwars <147705296+mahabaleshwars@users.noreply.github.com>
1 parent 46c56d6 commit 4e7e684

File tree

8 files changed

+228
-25
lines changed

8 files changed

+228
-25
lines changed

.github/workflows/e2e-versions.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,14 +490,14 @@ jobs:
490490
shell: bash
491491

492492
setup-java-version-from-file-major-minor-patch-with-dist:
493-
name: ${{ matrix.distribution }} version from file 'openjdk64-17.0.10' - ${{ matrix.os }}
493+
name: ${{ matrix.distribution }} version from file '${{ matrix.java-version-file }}' - ${{ matrix.os }}
494494
runs-on: ${{ matrix.os }}
495495
strategy:
496496
fail-fast: false
497497
matrix:
498498
os: [macos-latest, windows-latest, ubuntu-latest]
499499
distribution: ['adopt', 'zulu', 'liberica']
500-
java-version-file: ['.java-version', '.tool-versions']
500+
java-version-file: ['.java-version', '.tool-versions', '.sdkmanrc']
501501
steps:
502502
- name: Checkout
503503
uses: actions/checkout@v5
@@ -507,6 +507,9 @@ jobs:
507507
- name: Create .tool-versions file
508508
shell: bash
509509
run: echo "java openjdk64-17.0.10" > .tool-versions
510+
- name: Create .sdkmanrc file
511+
shell: bash
512+
run: echo "java=17.0.10-tem" > .sdkmanrc
510513
- name: setup-java
511514
uses: ./
512515
id: setup-java
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
6.0.119-zulu, 6.0.119
2+
7.0.352-zulu, 7.0.352
3+
8.0.282-trava, 8.0.282
4+
8.0.432-albba, 8.0.432
5+
8.0.432-amzn, 8.0.432
6+
8.0.432-kona, 8.0.432
7+
8.0.432-librca, 8.0.432
8+
8.0.432-sem, 8.0.432
9+
8.0.432-tem, 8.0.432
10+
8.0.432-zulu, 8.0.432
11+
8.0.432.fx-librca, 8.0.432
12+
8.0.432.fx-zulu, 8.0.432
13+
8.0.442-amzn, 8.0.442
14+
8.0.442-librca, 8.0.442
15+
8.0.442-tem, 8.0.442
16+
8.0.442-zulu, 8.0.442
17+
8.0.442.fx-librca, 8.0.442
18+
8.0.442.fx-zulu, 8.0.442
19+
11.0.14.1-jbr, 11.0.14
20+
11.0.15-trava, 11.0.15
21+
11.0.25-albba, 11.0.25
22+
11.0.25-amzn, 11.0.25
23+
11.0.25-kona, 11.0.25
24+
11.0.25-librca, 11.0.25
25+
11.0.25-ms, 11.0.25
26+
11.0.25-sapmchn, 11.0.25
27+
11.0.25-sem, 11.0.25
28+
11.0.25-tem, 11.0.25
29+
11.0.25-zulu, 11.0.25
30+
11.0.25.fx-librca, 11.0.25
31+
11.0.25.fx-zulu, 11.0.25
32+
11.0.26-amzn, 11.0.26
33+
11.0.26-librca, 11.0.26
34+
11.0.26-ms, 11.0.26
35+
11.0.26-sapmchn, 11.0.26
36+
11.0.26-zulu, 11.0.26
37+
11.0.26.fx-librca, 11.0.26
38+
11.0.26.fx-zulu, 11.0.26
39+
17.0.12-graal, 17.0.12
40+
17.0.12-jbr, 17.0.12
41+
17.0.12-oracle, 17.0.12
42+
17.0.13-albba, 17.0.13
43+
17.0.13-amzn, 17.0.13
44+
17.0.13-kona, 17.0.13
45+
17.0.13-librca, 17.0.13
46+
17.0.13-ms, 17.0.13
47+
17.0.13-sapmchn, 17.0.13
48+
17.0.13-sem, 17.0.13
49+
17.0.13-tem, 17.0.13
50+
17.0.13-zulu, 17.0.13
51+
17.0.13.crac-librca, 17.0.13
52+
17.0.13.crac-zulu, 17.0.13
53+
17.0.13.fx-librca, 17.0.13
54+
17.0.13.fx-zulu, 17.0.13
55+
17.0.14-amzn, 17.0.14
56+
17.0.14-librca, 17.0.14
57+
17.0.14-ms, 17.0.14
58+
17.0.14-sapmchn, 17.0.14
59+
17.0.14-zulu, 17.0.14
60+
17.0.14.fx-librca, 17.0.14
61+
17.0.14.fx-zulu, 17.0.14
62+
17.0.9-graalce, 17.0.9
63+
21.0.2-graalce, 21.0.2
64+
21.0.2-open, 21.0.2
65+
21.0.5-amzn, 21.0.5
66+
21.0.5-graal, 21.0.5
67+
21.0.5-jbr, 21.0.5
68+
21.0.5-kona, 21.0.5
69+
21.0.5-librca, 21.0.5
70+
21.0.5-ms, 21.0.5
71+
21.0.5-oracle, 21.0.5
72+
21.0.5-sapmchn, 21.0.5
73+
21.0.5-sem, 21.0.5
74+
21.0.5-tem, 21.0.5
75+
21.0.5-zulu, 21.0.5
76+
21.0.5.crac-librca, 21.0.5
77+
21.0.5.crac-zulu, 21.0.5
78+
21.0.5.fx-librca, 21.0.5
79+
21.0.5.fx-zulu, 21.0.5
80+
21.0.6-amzn, 21.0.6
81+
21.0.6-graal, 21.0.6
82+
21.0.6-librca, 21.0.6
83+
21.0.6-ms, 21.0.6
84+
21.0.6-oracle, 21.0.6
85+
21.0.6-sapmchn, 21.0.6
86+
21.0.6-tem, 21.0.6
87+
21.0.6-zulu, 21.0.6
88+
21.0.6.fx-librca, 21.0.6
89+
21.0.6.fx-zulu, 21.0.6
90+
22.0.2-oracle, 22.0.2
91+
22.1.0.1.r11-gln, 22.1.0
92+
22.1.0.1.r17-gln, 22.1.0
93+
22.3.5.r11-nik, 22.3.5
94+
22.3.5.r17-mandrel, 22.3.5
95+
22.3.5.r17-nik, 22.3.5
96+
23-open, 23
97+
23.0.1-amzn, 23.0.1
98+
23.0.1-graal, 23.0.1
99+
23.0.1-graalce, 23.0.1
100+
23.0.1-librca, 23.0.1
101+
23.0.1-open, 23.0.1
102+
23.0.1-oracle, 23.0.1
103+
23.0.1-sapmchn, 23.0.1
104+
23.0.1-tem, 23.0.1
105+
23.0.1-zulu, 23.0.1
106+
23.0.1.crac-zulu, 23.0.1
107+
23.0.1.fx-librca, 23.0.1
108+
23.0.1.fx-zulu, 23.0.1
109+
23.0.2-amzn, 23.0.2
110+
23.0.2-graal, 23.0.2
111+
23.0.2-graalce, 23.0.2
112+
23.0.2-librca, 23.0.2
113+
23.0.2-oracle, 23.0.2
114+
23.0.2-sapmchn, 23.0.2
115+
23.0.2-tem, 23.0.2
116+
23.0.2-zulu, 23.0.2
117+
23.0.2.fx-librca, 23.0.2
118+
23.0.2.fx-zulu, 23.0.2
119+
23.0.6.fx-nik, 23.0.6
120+
23.0.6.r17-mandrel, 23.0.6
121+
23.0.6.r17-nik, 23.0.6
122+
23.1.5.fx-nik, 23.1.5
123+
23.1.5.r21-mandrel, 23.1.5
124+
23.1.5.r21-nik, 23.1.5
125+
24.0.2.r22-mandrel, 24.0.2
126+
24.ea.27-graal, 24.0.0
127+
24.ea.28-graal, 24.0.0
128+
24.ea.31-open, 24.0.0
129+
24.ea.32-open, 24.0.0
130+
24.1.1.r23-mandrel, 24.1.1
131+
24.1.1.r23-nik, 24.1.1
132+
25.ea.4-graal, 25.0.0
133+
25.ea.5-graal, 25.0.0
134+
25.ea.5-open, 25.0.0
135+
25.ea.6-open, 25.0.0

__tests__/util.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import * as cache from '@actions/cache';
22
import * as core from '@actions/core';
3+
import * as fs from 'fs';
4+
import * as path from 'path';
35
import {
46
convertVersionToSemver,
7+
getVersionFromFileContent,
58
isVersionSatisfies,
69
isCacheFeatureAvailable,
710
isGhes
@@ -82,6 +85,43 @@ describe('convertVersionToSemver', () => {
8285
});
8386
});
8487

88+
describe('getVersionFromFileContent', () => {
89+
describe('.sdkmanrc', () => {
90+
it.each([
91+
['java=11.0.20.1-tem', '11.0.20'],
92+
['java = 11.0.20.1-tem', '11.0.20'],
93+
['java=11.0.20.1-tem # a comment in sdkmanrc', '11.0.20'],
94+
['java=11.0.20.1-tem\n#java=21.0.20.1-tem\n', '11.0.20'], // choose first match
95+
['java=11.0.20.1-tem\njava=21.0.20.1-tem\n', '11.0.20'], // choose first match
96+
['#java=11.0.20.1-tem\njava=21.0.20.1-tem\n', '21.0.20'] // first one is 'commented' in .sdkmanrc
97+
])('parsing %s should return %s', (content: string, expected: string) => {
98+
const actual = getVersionFromFileContent(content, 'openjdk', '.sdkmanrc');
99+
expect(actual).toBe(expected);
100+
});
101+
102+
describe('known versions', () => {
103+
const csv = fs.readFileSync(
104+
path.join(__dirname, 'data/sdkman-java-versions.csv'),
105+
'utf8'
106+
);
107+
const versions = csv.split('\n').map(r => r.split(', '));
108+
109+
it.each(versions)(
110+
'parsing %s should return %s',
111+
(sdkmanJavaVersion: string, expected: string) => {
112+
const asContent = `java=${sdkmanJavaVersion}`;
113+
const actual = getVersionFromFileContent(
114+
asContent,
115+
'openjdk',
116+
'.sdkmanrc'
117+
);
118+
expect(actual).toBe(expected);
119+
}
120+
);
121+
});
122+
});
123+
});
124+
85125
describe('isGhes', () => {
86126
const pristineEnv = process.env;
87127

dist/cleanup/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94706,17 +94706,20 @@ function getVersionFromFileContent(content, distributionName, versionFile) {
9470694706
javaVersionRegExp =
9470794707
/^java\s+(?:\S*-)?(?<version>\d+(?:\.\d+)*([+_.-](?:openj9[-._]?\d[\w.-]*|java\d+|jre[-_\w]*|OpenJDK\d+[\w_.-]*|[a-z0-9]+))*)/im;
9470894708
}
94709+
else if (versionFileName == '.sdkmanrc') {
94710+
javaVersionRegExp = /^java\s*=\s*(?<version>[^-]+)/m;
94711+
}
9470994712
else {
9471094713
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
9471194714
}
94712-
const fileContent = ((_b = (_a = content.match(javaVersionRegExp)) === null || _a === void 0 ? void 0 : _a.groups) === null || _b === void 0 ? void 0 : _b.version)
94715+
const capturedVersion = ((_b = (_a = content.match(javaVersionRegExp)) === null || _a === void 0 ? void 0 : _a.groups) === null || _b === void 0 ? void 0 : _b.version)
9471394716
? (_d = (_c = content.match(javaVersionRegExp)) === null || _c === void 0 ? void 0 : _c.groups) === null || _d === void 0 ? void 0 : _d.version
9471494717
: '';
94715-
if (!fileContent) {
94718+
core.debug(`Parsed version '${capturedVersion}' from file '${versionFileName}'`);
94719+
if (!capturedVersion) {
9471694720
return null;
9471794721
}
94718-
core.debug(`Version from file '${fileContent}'`);
94719-
const tentativeVersion = avoidOldNotation(fileContent);
94722+
const tentativeVersion = avoidOldNotation(capturedVersion);
9472094723
const rawVersion = tentativeVersion.split('-')[0];
9472194724
let version = semver.validRange(rawVersion)
9472294725
? tentativeVersion

dist/setup/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132850,17 +132850,20 @@ function getVersionFromFileContent(content, distributionName, versionFile) {
132850132850
javaVersionRegExp =
132851132851
/^java\s+(?:\S*-)?(?<version>\d+(?:\.\d+)*([+_.-](?:openj9[-._]?\d[\w.-]*|java\d+|jre[-_\w]*|OpenJDK\d+[\w_.-]*|[a-z0-9]+))*)/im;
132852132852
}
132853+
else if (versionFileName == '.sdkmanrc') {
132854+
javaVersionRegExp = /^java\s*=\s*(?<version>[^-]+)/m;
132855+
}
132853132856
else {
132854132857
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
132855132858
}
132856-
const fileContent = ((_b = (_a = content.match(javaVersionRegExp)) === null || _a === void 0 ? void 0 : _a.groups) === null || _b === void 0 ? void 0 : _b.version)
132859+
const capturedVersion = ((_b = (_a = content.match(javaVersionRegExp)) === null || _a === void 0 ? void 0 : _a.groups) === null || _b === void 0 ? void 0 : _b.version)
132857132860
? (_d = (_c = content.match(javaVersionRegExp)) === null || _c === void 0 ? void 0 : _c.groups) === null || _d === void 0 ? void 0 : _d.version
132858132861
: '';
132859-
if (!fileContent) {
132862+
core.debug(`Parsed version '${capturedVersion}' from file '${versionFileName}'`);
132863+
if (!capturedVersion) {
132860132864
return null;
132861132865
}
132862-
core.debug(`Version from file '${fileContent}'`);
132863-
const tentativeVersion = avoidOldNotation(fileContent);
132866+
const tentativeVersion = avoidOldNotation(capturedVersion);
132864132867
const rawVersion = tentativeVersion.split('-')[0];
132865132868
let version = semver.validRange(rawVersion)
132866132869
? tentativeVersion

docs/advanced-usage.md

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -601,14 +601,29 @@ steps:
601601
## Java version file
602602
If the `java-version-file` input is specified, the action will extract the version from the file and install it.
603603

604-
Supported files are .java-version and .tool-versions.
605-
In .java-version file, only the version should be specified (e.g., 17.0.7).
606-
In .tool-versions file, java version should be preceded by the java keyword (e.g., java 17.0.7).
607-
The `.java-version` file recognizes all variants of the version description according to [jenv](https://github.com/jenv/jenv). Similarly, the `.tool-versions` file supports version specifications in accordance with [asdf](https://github.com/asdf-vm/asdf) standards, adhering to Semantic Versioning ([semver](https://semver.org/)).
608-
609-
If both java-version and java-version-file inputs are provided, the java-version input will be used.
604+
Supported files are `.java-version`, `.tool-versions` and `.sdkmanrc`.
605+
* In `.java-version` file, only the version should be specified (e.g., 17.0.7). The `.java-version` file recognizes all variants of the version description according to [jenv](https://github.com/jenv/jenv).
606+
* In `.tool-versions` file, java version should be preceded by the java keyword (e.g., java 17.0.7). The `.tool-versions` file supports version specifications in accordance with [asdf](https://github.com/asdf-vm/asdf) standards, adhering to Semantic Versioning ([semver](https://semver.org/)).
607+
* In `.sdkmanrc` file, java version should be preceded by the `java=` prefix (e.g., java=17.0.7-tem) and include the distribution. The `.sdkmanrc` file supports version specifications in accordance with [file format](https://sdkman.io/usage#env-command), see [Sdkman! documentation](https://sdkman.io/jdks) for more information.
608+
609+
610+
If both `java-version` and `java-version-file` **inputs** are provided, the `java-version` input will be used.
611+
612+
**Example step using `Sdkman!`**:
613+
```yml
614+
- name: Setup java
615+
uses: actions/setup-java@v5
616+
with:
617+
java-version-file: '.sdkmanrc'
618+
distribution: 'temurin'
619+
```
620+
621+
**Example `.sdkmanrc`**:
622+
```
623+
java=17.0.7-tem
624+
```
610625
611-
Valid entry options:
626+
Valid entry options (does not apply to `.sdkmanrc`):
612627
```
613628
major versions: 8, 11, 16, 17, 21
614629
more specific versions: 8.0.282+8, 8.0.232, 11.0, 11.0.4, 17.0
@@ -619,4 +634,4 @@ LTS versions : temurin-21.0.5+11.0.LTS
619634
If the file contains multiple versions, only the first one will be recognized.
620635
621636
***NOTE***:
622-
For the tool-version file, ensure that you use standard semantic versioning (semver) formats, as non-standard formats (such as jetbrains-21b212.1) may not be parsed correctly. Additionally, for complex version strings containing multiple version-like segments (for example, java semeru-openj9-11.0.15+10_openj9-0.32.0), the extraction logic may incorrectly capture the last segment (0.32.0) instead of the main version (11.0.15+10).
637+
For the tool-version file, ensure that you use standard semantic versioning (semver) formats, as non-standard formats (such as jetbrains-21b212.1) may not be parsed correctly. Additionally, for complex version strings containing multiple version-like segments (for example, java semeru-openj9-11.0.15+10_openj9-0.32.0), the extraction logic may incorrectly capture the last segment (0.32.0) instead of the main version (11.0.15+10).

docs/contributors.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ Pull requests are the easiest way to contribute changes to git repos at GitHub.
6868
Adding or changing tests is an integral part of making a change to the code.
6969
Unit tests are in the `__tests__` folder, and end-to-end tests are in the `workflows` folder, particularly take a look at the files with `e2e` prefix, for instance, [e2e-cache.yml](https://github.com/actions/setup-java/blob/main/.github/workflows/e2e-cache.yml).
7070

71-
- The contributor can add various types of tests (like unit tests or end-to-end tests), which, in his opinion, will be necessary and sufficient for testing new or changed functionality
71+
- The contributor can add various types of tests (like unit tests or end-to-end tests), which, in their opinion, will be necessary and sufficient for testing new or changed functionality
7272
- Tests should cover a successful execution, as well as some edge cases and possible errors
7373
- As already mentioned, pull requests without tests will be considered more carefully by maintainers. If you are sure that in this situation the tests are not needed or cannot be implemented with a commensurate effort - please add this clarification message to your pull request
7474

7575
**Once you've filed the pull request:**
7676

7777
- CI will start automatically with some checks. Wait until the end of the execution and make sure that all checks passed successfully. If some checks fail, you can open them one by one, try to find the reason for failing and make changes to your code to resolve the problem
7878
- Maintainers will review your pull request
79-
- If a maintainer requests changes, first of all, try to think about his request critically and only after that implement and request another review
79+
- If a maintainer requests changes, first of all, try to think about their request critically and only after that implement and request another review
8080
- If your PR gets accepted, it will soon be merged into the main branch. But your contribution will take effect only after the release of a new version of the action and updating the major tag
8181
> Sometimes maintainers reject pull requests and that's ok! Usually, along with rejection, we supply the reason for it. Nonetheless, we still really appreciate you taking the time to do it, and we don't take that lightly :heart:
8282

src/util.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,20 +134,24 @@ export function getVersionFromFileContent(
134134
if (versionFileName == '.tool-versions') {
135135
javaVersionRegExp =
136136
/^java\s+(?:\S*-)?(?<version>\d+(?:\.\d+)*([+_.-](?:openj9[-._]?\d[\w.-]*|java\d+|jre[-_\w]*|OpenJDK\d+[\w_.-]*|[a-z0-9]+))*)/im;
137+
} else if (versionFileName == '.sdkmanrc') {
138+
javaVersionRegExp = /^java\s*=\s*(?<version>[^-]+)/m;
137139
} else {
138140
javaVersionRegExp = /(?<version>(?<=(^|\s|-))(\d+\S*))(\s|$)/;
139141
}
140142

141-
const fileContent = content.match(javaVersionRegExp)?.groups?.version
143+
const capturedVersion = content.match(javaVersionRegExp)?.groups?.version
142144
? (content.match(javaVersionRegExp)?.groups?.version as string)
143145
: '';
144-
if (!fileContent) {
146+
147+
core.debug(
148+
`Parsed version '${capturedVersion}' from file '${versionFileName}'`
149+
);
150+
if (!capturedVersion) {
145151
return null;
146152
}
147153

148-
core.debug(`Version from file '${fileContent}'`);
149-
150-
const tentativeVersion = avoidOldNotation(fileContent);
154+
const tentativeVersion = avoidOldNotation(capturedVersion);
151155
const rawVersion = tentativeVersion.split('-')[0];
152156

153157
let version = semver.validRange(rawVersion)

0 commit comments

Comments
 (0)