Skip to content

Commit 46d5f06

Browse files
Avoid "+" sign in Java path in v2-preview (#145)
* try to handle _ versions * more logs * more debug * test 1 * more fixes * fix typo * Update e2e-versions.yml * add unit-tests * remove debug info from tests * debug pre-cached versions * change e2e tests to ubuntu-latest
1 parent 022e86d commit 46d5f06

File tree

5 files changed

+110
-50
lines changed

5 files changed

+110
-50
lines changed

.github/workflows/e2e-versions.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,7 @@ jobs:
192192
with:
193193
distribution: ${{ matrix.distribution }}
194194
java-version: ${{ matrix.version }}
195-
architecture: x86
195+
architecture: x86
196+
- name: Verify Java
197+
run: bash __tests__/verify-java.sh "${{ matrix.version }}" "${{ steps.setup-java.outputs.path }}"
198+
shell: bash

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ The `java-version` input supports an exact version or a version range using [Sem
4848
- more specific versions: `11.0`, `11.0.4`, `8.0.232`, `8.0.282+8`
4949
- early access (EA) versions: `15-ea`, `15.0.0-ea`, `15.0.0-ea.2`, `15.0.0+2-ea`
5050

51-
**Note:** 4-digit notation will always force action to skip checking pre-cached versions and download version in runtime.
52-
5351
#### Supported distributions
5452
Currently, the following distributions are supported:
5553
| Keyword | Distribution | Official site | License |

__tests__/distributors/base-installer.test.ts

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,24 +103,27 @@ describe('findInToolcache', () => {
103103
});
104104

105105
it.each([
106-
['11', '11.0.3'],
107-
['11.0', '11.0.3'],
108-
['11.0.1', '11.0.1'],
109-
['11.0.3', '11.0.3'],
110-
['15', '15.0.2'],
111-
['x', '15.0.2'],
112-
['x-ea', '17.4.4-ea'],
113-
['11-ea', '11.3.2-ea'],
114-
['11.2-ea', '11.2.1-ea'],
115-
['11.2.1-ea', '11.2.1-ea']
106+
['11', { version: '11.0.3+2', versionInPath: '11.0.3-2' }],
107+
['11.0', { version: '11.0.3+2', versionInPath: '11.0.3-2' }],
108+
['11.0.1', { version: '11.0.1', versionInPath: '11.0.1' }],
109+
['11.0.3', { version: '11.0.3+2', versionInPath: '11.0.3-2' }],
110+
['15', { version: '15.0.2+4', versionInPath: '15.0.2-4' }],
111+
['x', { version: '15.0.2+4', versionInPath: '15.0.2-4' }],
112+
['x-ea', { version: '17.4.4', versionInPath: '17.4.4-ea' }],
113+
['11-ea', { version: '11.3.3+5.2.1231421', versionInPath: '11.3.3-ea.5.2.1231421' }],
114+
['11.2-ea', { version: '11.2.1', versionInPath: '11.2.1-ea' }],
115+
['11.2.1-ea', { version: '11.2.1', versionInPath: '11.2.1-ea' }]
116116
])('should choose correct java from tool-cache for input %s', (input, expected) => {
117117
spyTcFindAllVersions.mockReturnValue([
118118
'17.4.4-ea',
119119
'11.0.2',
120-
'15.0.2',
121-
'11.0.3',
120+
'15.0.2-4',
121+
'11.0.3-2',
122122
'11.2.1-ea',
123123
'11.3.2-ea',
124+
'11.3.2-ea.5',
125+
'11.3.3-ea.5.2.1231421',
126+
'12.3.2-0',
124127
'11.0.1'
125128
]);
126129
spyGetToolcachePath.mockImplementation(
@@ -134,7 +137,10 @@ describe('findInToolcache', () => {
134137
checkLatest: false
135138
});
136139
const foundVersion = mockJavaBase['findInToolcache']();
137-
expect(foundVersion?.version).toEqual(expected);
140+
expect(foundVersion).toEqual({
141+
version: expected.version,
142+
path: `/hostedtoolcache/Java_Empty_jdk/${expected.versionInPath}/x64`
143+
});
138144
});
139145
});
140146

@@ -318,3 +324,28 @@ describe('normalizeVersion', () => {
318324
);
319325
});
320326
});
327+
328+
describe('getToolcacheVersionName', () => {
329+
const DummyJavaBase = JavaBase as any;
330+
331+
it.each([
332+
[{ version: '11', stable: true }, '11'],
333+
[{ version: '11.0.2', stable: true }, '11.0.2'],
334+
[{ version: '11.0.2+4', stable: true }, '11.0.2-4'],
335+
[{ version: '11.0.2+4.1.2563234', stable: true }, '11.0.2-4.1.2563234'],
336+
[{ version: '11.0', stable: false }, '11.0-ea'],
337+
[{ version: '11.0.3', stable: false }, '11.0.3-ea'],
338+
[{ version: '11.0.3+4', stable: false }, '11.0.3-ea.4'],
339+
[{ version: '11.0.3+4.2.256', stable: false }, '11.0.3-ea.4.2.256']
340+
])('returns correct version name for %s', (input, expected) => {
341+
const inputVersion = input.stable ? '11' : '11-ea';
342+
const mockJavaBase = new EmptyJavaBase({
343+
version: inputVersion,
344+
packageType: 'jdk',
345+
architecture: 'x64',
346+
checkLatest: false
347+
});
348+
const actual = mockJavaBase['getToolcacheVersionName'](input.version);
349+
expect(actual).toBe(expected);
350+
});
351+
});

dist/setup/index.js

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3970,7 +3970,6 @@ class JavaBase {
39703970
this.checkLatest = installerOptions.checkLatest;
39713971
}
39723972
setupJava() {
3973-
var _a, _b;
39743973
return __awaiter(this, void 0, void 0, function* () {
39753974
let foundJava = this.findInToolcache();
39763975
if (foundJava && !this.checkLatest) {
@@ -3980,8 +3979,6 @@ class JavaBase {
39803979
core.info('Trying to resolve the latest version from remote');
39813980
const javaRelease = yield this.findPackageForDownload(this.version);
39823981
core.info(`Resolved latest version as ${javaRelease.version}`);
3983-
core.info((_a = foundJava === null || foundJava === void 0 ? void 0 : foundJava.version) !== null && _a !== void 0 ? _a : '');
3984-
core.info((_b = javaRelease.version) !== null && _b !== void 0 ? _b : '');
39853982
if ((foundJava === null || foundJava === void 0 ? void 0 : foundJava.version) === javaRelease.version) {
39863983
core.info(`Resolved Java ${foundJava.version} from tool-cache`);
39873984
}
@@ -4006,30 +4003,49 @@ class JavaBase {
40064003
}
40074004
getToolcacheVersionName(version) {
40084005
if (!this.stable) {
4009-
const cleanVersion = semver_1.default.clean(version);
4010-
return `${cleanVersion}-ea`;
4006+
if (version.includes('+')) {
4007+
return version.replace('+', '-ea.');
4008+
}
4009+
else {
4010+
return `${version}-ea`;
4011+
}
40114012
}
4012-
return version;
4013+
// Kotlin and some Java dependencies don't work properly when Java path contains "+" sign
4014+
// so replace "/hostedtoolcache/Java/11.0.3+4/x64" to "/hostedtoolcache/Java/11.0.3-4/x64" when saves to cache
4015+
// related issue: https://github.com/actions/virtual-environments/issues/3014
4016+
return version.replace('+', '-');
40134017
}
40144018
findInToolcache() {
40154019
// we can't use tc.find directly because firstly, we need to filter versions by stability flag
40164020
// if *-ea is provided, take only ea versions from toolcache, otherwise - only stable versions
40174021
const availableVersions = tc
40184022
.findAllVersions(this.toolcacheFolderName, this.architecture)
4019-
.filter(item => item.endsWith('-ea') === !this.stable);
4023+
.map(item => {
4024+
return {
4025+
version: item
4026+
.replace('-ea.', '+')
4027+
.replace(/-ea$/, '')
4028+
// Kotlin and some Java dependencies don't work properly when Java path contains "+" sign
4029+
// so replace "/hostedtoolcache/Java/11.0.3-4/x64" to "/hostedtoolcache/Java/11.0.3+4/x64" when retrieves to cache
4030+
// related issue: https://github.com/actions/virtual-environments/issues/3014
4031+
.replace('-', '+'),
4032+
path: util_1.getToolcachePath(this.toolcacheFolderName, item, this.architecture) || '',
4033+
stable: !item.includes('-ea')
4034+
};
4035+
})
4036+
.filter(item => item.stable === this.stable);
40204037
const satisfiedVersions = availableVersions
4021-
.filter(item => util_1.isVersionSatisfies(this.version, item.replace(/-ea$/, '')))
4022-
.sort(semver_1.default.rcompare);
4038+
.filter(item => util_1.isVersionSatisfies(this.version, item.version))
4039+
.filter(item => item.path)
4040+
.sort((a, b) => {
4041+
return -semver_1.default.compareBuild(a.version, b.version);
4042+
});
40234043
if (!satisfiedVersions || satisfiedVersions.length === 0) {
40244044
return null;
40254045
}
4026-
const javaPath = util_1.getToolcachePath(this.toolcacheFolderName, satisfiedVersions[0], this.architecture);
4027-
if (!javaPath) {
4028-
return null;
4029-
}
40304046
return {
4031-
version: util_1.getVersionFromToolcachePath(javaPath),
4032-
path: javaPath
4047+
version: satisfiedVersions[0].version,
4048+
path: satisfiedVersions[0].path
40334049
};
40344050
}
40354051
normalizeVersion(version) {

src/distributions/base-installer.ts

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ export abstract class JavaBase {
4141
core.info('Trying to resolve the latest version from remote');
4242
const javaRelease = await this.findPackageForDownload(this.version);
4343
core.info(`Resolved latest version as ${javaRelease.version}`);
44-
core.info(foundJava?.version ?? '');
45-
core.info(javaRelease.version ?? '');
4644
if (foundJava?.version === javaRelease.version) {
4745
core.info(`Resolved Java ${foundJava.version} from tool-cache`);
4846
} else {
@@ -70,38 +68,52 @@ export abstract class JavaBase {
7068

7169
protected getToolcacheVersionName(version: string): string {
7270
if (!this.stable) {
73-
const cleanVersion = semver.clean(version);
74-
return `${cleanVersion}-ea`;
71+
if (version.includes('+')) {
72+
return version.replace('+', '-ea.');
73+
} else {
74+
return `${version}-ea`;
75+
}
7576
}
76-
return version;
77+
78+
// Kotlin and some Java dependencies don't work properly when Java path contains "+" sign
79+
// so replace "/hostedtoolcache/Java/11.0.3+4/x64" to "/hostedtoolcache/Java/11.0.3-4/x64" when saves to cache
80+
// related issue: https://github.com/actions/virtual-environments/issues/3014
81+
return version.replace('+', '-');
7782
}
7883

7984
protected findInToolcache(): JavaInstallerResults | null {
8085
// we can't use tc.find directly because firstly, we need to filter versions by stability flag
8186
// if *-ea is provided, take only ea versions from toolcache, otherwise - only stable versions
8287
const availableVersions = tc
8388
.findAllVersions(this.toolcacheFolderName, this.architecture)
84-
.filter(item => item.endsWith('-ea') === !this.stable);
89+
.map(item => {
90+
return {
91+
version: item
92+
.replace('-ea.', '+')
93+
.replace(/-ea$/, '')
94+
// Kotlin and some Java dependencies don't work properly when Java path contains "+" sign
95+
// so replace "/hostedtoolcache/Java/11.0.3-4/x64" to "/hostedtoolcache/Java/11.0.3+4/x64" when retrieves to cache
96+
// related issue: https://github.com/actions/virtual-environments/issues/3014
97+
.replace('-', '+'),
98+
path: getToolcachePath(this.toolcacheFolderName, item, this.architecture) || '',
99+
stable: !item.includes('-ea')
100+
};
101+
})
102+
.filter(item => item.stable === this.stable);
85103

86104
const satisfiedVersions = availableVersions
87-
.filter(item => isVersionSatisfies(this.version, item.replace(/-ea$/, '')))
88-
.sort(semver.rcompare);
105+
.filter(item => isVersionSatisfies(this.version, item.version))
106+
.filter(item => item.path)
107+
.sort((a, b) => {
108+
return -semver.compareBuild(a.version, b.version);
109+
});
89110
if (!satisfiedVersions || satisfiedVersions.length === 0) {
90111
return null;
91112
}
92113

93-
const javaPath = getToolcachePath(
94-
this.toolcacheFolderName,
95-
satisfiedVersions[0],
96-
this.architecture
97-
);
98-
if (!javaPath) {
99-
return null;
100-
}
101-
102114
return {
103-
version: getVersionFromToolcachePath(javaPath),
104-
path: javaPath
115+
version: satisfiedVersions[0].version,
116+
path: satisfiedVersions[0].path
105117
};
106118
}
107119

0 commit comments

Comments
 (0)