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
This commit is contained in:
Maxim Lobanov 2021-03-27 10:56:12 +03:00 committed by GitHub
parent 022e86d5c9
commit 46d5f06eb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 110 additions and 50 deletions

View File

@ -193,3 +193,6 @@ jobs:
distribution: ${{ matrix.distribution }} distribution: ${{ matrix.distribution }}
java-version: ${{ matrix.version }} java-version: ${{ matrix.version }}
architecture: x86 architecture: x86
- name: Verify Java
run: bash __tests__/verify-java.sh "${{ matrix.version }}" "${{ steps.setup-java.outputs.path }}"
shell: bash

View File

@ -48,8 +48,6 @@ The `java-version` input supports an exact version or a version range using [Sem
- more specific versions: `11.0`, `11.0.4`, `8.0.232`, `8.0.282+8` - more specific versions: `11.0`, `11.0.4`, `8.0.232`, `8.0.282+8`
- early access (EA) versions: `15-ea`, `15.0.0-ea`, `15.0.0-ea.2`, `15.0.0+2-ea` - early access (EA) versions: `15-ea`, `15.0.0-ea`, `15.0.0-ea.2`, `15.0.0+2-ea`
**Note:** 4-digit notation will always force action to skip checking pre-cached versions and download version in runtime.
#### Supported distributions #### Supported distributions
Currently, the following distributions are supported: Currently, the following distributions are supported:
| Keyword | Distribution | Official site | License | | Keyword | Distribution | Official site | License |

View File

@ -103,24 +103,27 @@ describe('findInToolcache', () => {
}); });
it.each([ it.each([
['11', '11.0.3'], ['11', { version: '11.0.3+2', versionInPath: '11.0.3-2' }],
['11.0', '11.0.3'], ['11.0', { version: '11.0.3+2', versionInPath: '11.0.3-2' }],
['11.0.1', '11.0.1'], ['11.0.1', { version: '11.0.1', versionInPath: '11.0.1' }],
['11.0.3', '11.0.3'], ['11.0.3', { version: '11.0.3+2', versionInPath: '11.0.3-2' }],
['15', '15.0.2'], ['15', { version: '15.0.2+4', versionInPath: '15.0.2-4' }],
['x', '15.0.2'], ['x', { version: '15.0.2+4', versionInPath: '15.0.2-4' }],
['x-ea', '17.4.4-ea'], ['x-ea', { version: '17.4.4', versionInPath: '17.4.4-ea' }],
['11-ea', '11.3.2-ea'], ['11-ea', { version: '11.3.3+5.2.1231421', versionInPath: '11.3.3-ea.5.2.1231421' }],
['11.2-ea', '11.2.1-ea'], ['11.2-ea', { version: '11.2.1', versionInPath: '11.2.1-ea' }],
['11.2.1-ea', '11.2.1-ea'] ['11.2.1-ea', { version: '11.2.1', versionInPath: '11.2.1-ea' }]
])('should choose correct java from tool-cache for input %s', (input, expected) => { ])('should choose correct java from tool-cache for input %s', (input, expected) => {
spyTcFindAllVersions.mockReturnValue([ spyTcFindAllVersions.mockReturnValue([
'17.4.4-ea', '17.4.4-ea',
'11.0.2', '11.0.2',
'15.0.2', '15.0.2-4',
'11.0.3', '11.0.3-2',
'11.2.1-ea', '11.2.1-ea',
'11.3.2-ea', '11.3.2-ea',
'11.3.2-ea.5',
'11.3.3-ea.5.2.1231421',
'12.3.2-0',
'11.0.1' '11.0.1'
]); ]);
spyGetToolcachePath.mockImplementation( spyGetToolcachePath.mockImplementation(
@ -134,7 +137,10 @@ describe('findInToolcache', () => {
checkLatest: false checkLatest: false
}); });
const foundVersion = mockJavaBase['findInToolcache'](); const foundVersion = mockJavaBase['findInToolcache']();
expect(foundVersion?.version).toEqual(expected); expect(foundVersion).toEqual({
version: expected.version,
path: `/hostedtoolcache/Java_Empty_jdk/${expected.versionInPath}/x64`
});
}); });
}); });
@ -318,3 +324,28 @@ describe('normalizeVersion', () => {
); );
}); });
}); });
describe('getToolcacheVersionName', () => {
const DummyJavaBase = JavaBase as any;
it.each([
[{ version: '11', stable: true }, '11'],
[{ version: '11.0.2', stable: true }, '11.0.2'],
[{ version: '11.0.2+4', stable: true }, '11.0.2-4'],
[{ version: '11.0.2+4.1.2563234', stable: true }, '11.0.2-4.1.2563234'],
[{ version: '11.0', stable: false }, '11.0-ea'],
[{ version: '11.0.3', stable: false }, '11.0.3-ea'],
[{ version: '11.0.3+4', stable: false }, '11.0.3-ea.4'],
[{ version: '11.0.3+4.2.256', stable: false }, '11.0.3-ea.4.2.256']
])('returns correct version name for %s', (input, expected) => {
const inputVersion = input.stable ? '11' : '11-ea';
const mockJavaBase = new EmptyJavaBase({
version: inputVersion,
packageType: 'jdk',
architecture: 'x64',
checkLatest: false
});
const actual = mockJavaBase['getToolcacheVersionName'](input.version);
expect(actual).toBe(expected);
});
});

46
dist/setup/index.js vendored
View File

@ -3970,7 +3970,6 @@ class JavaBase {
this.checkLatest = installerOptions.checkLatest; this.checkLatest = installerOptions.checkLatest;
} }
setupJava() { setupJava() {
var _a, _b;
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
let foundJava = this.findInToolcache(); let foundJava = this.findInToolcache();
if (foundJava && !this.checkLatest) { if (foundJava && !this.checkLatest) {
@ -3980,8 +3979,6 @@ class JavaBase {
core.info('Trying to resolve the latest version from remote'); core.info('Trying to resolve the latest version from remote');
const javaRelease = yield this.findPackageForDownload(this.version); const javaRelease = yield this.findPackageForDownload(this.version);
core.info(`Resolved latest version as ${javaRelease.version}`); core.info(`Resolved latest version as ${javaRelease.version}`);
core.info((_a = foundJava === null || foundJava === void 0 ? void 0 : foundJava.version) !== null && _a !== void 0 ? _a : '');
core.info((_b = javaRelease.version) !== null && _b !== void 0 ? _b : '');
if ((foundJava === null || foundJava === void 0 ? void 0 : foundJava.version) === javaRelease.version) { if ((foundJava === null || foundJava === void 0 ? void 0 : foundJava.version) === javaRelease.version) {
core.info(`Resolved Java ${foundJava.version} from tool-cache`); core.info(`Resolved Java ${foundJava.version} from tool-cache`);
} }
@ -4006,30 +4003,49 @@ class JavaBase {
} }
getToolcacheVersionName(version) { getToolcacheVersionName(version) {
if (!this.stable) { if (!this.stable) {
const cleanVersion = semver_1.default.clean(version); if (version.includes('+')) {
return `${cleanVersion}-ea`; return version.replace('+', '-ea.');
}
else {
return `${version}-ea`;
}
} }
return version; // Kotlin and some Java dependencies don't work properly when Java path contains "+" sign
// so replace "/hostedtoolcache/Java/11.0.3+4/x64" to "/hostedtoolcache/Java/11.0.3-4/x64" when saves to cache
// related issue: https://github.com/actions/virtual-environments/issues/3014
return version.replace('+', '-');
} }
findInToolcache() { findInToolcache() {
// we can't use tc.find directly because firstly, we need to filter versions by stability flag // we can't use tc.find directly because firstly, we need to filter versions by stability flag
// if *-ea is provided, take only ea versions from toolcache, otherwise - only stable versions // if *-ea is provided, take only ea versions from toolcache, otherwise - only stable versions
const availableVersions = tc const availableVersions = tc
.findAllVersions(this.toolcacheFolderName, this.architecture) .findAllVersions(this.toolcacheFolderName, this.architecture)
.filter(item => item.endsWith('-ea') === !this.stable); .map(item => {
return {
version: item
.replace('-ea.', '+')
.replace(/-ea$/, '')
// Kotlin and some Java dependencies don't work properly when Java path contains "+" sign
// so replace "/hostedtoolcache/Java/11.0.3-4/x64" to "/hostedtoolcache/Java/11.0.3+4/x64" when retrieves to cache
// related issue: https://github.com/actions/virtual-environments/issues/3014
.replace('-', '+'),
path: util_1.getToolcachePath(this.toolcacheFolderName, item, this.architecture) || '',
stable: !item.includes('-ea')
};
})
.filter(item => item.stable === this.stable);
const satisfiedVersions = availableVersions const satisfiedVersions = availableVersions
.filter(item => util_1.isVersionSatisfies(this.version, item.replace(/-ea$/, ''))) .filter(item => util_1.isVersionSatisfies(this.version, item.version))
.sort(semver_1.default.rcompare); .filter(item => item.path)
.sort((a, b) => {
return -semver_1.default.compareBuild(a.version, b.version);
});
if (!satisfiedVersions || satisfiedVersions.length === 0) { if (!satisfiedVersions || satisfiedVersions.length === 0) {
return null; return null;
} }
const javaPath = util_1.getToolcachePath(this.toolcacheFolderName, satisfiedVersions[0], this.architecture);
if (!javaPath) {
return null;
}
return { return {
version: util_1.getVersionFromToolcachePath(javaPath), version: satisfiedVersions[0].version,
path: javaPath path: satisfiedVersions[0].path
}; };
} }
normalizeVersion(version) { normalizeVersion(version) {

View File

@ -41,8 +41,6 @@ export abstract class JavaBase {
core.info('Trying to resolve the latest version from remote'); core.info('Trying to resolve the latest version from remote');
const javaRelease = await this.findPackageForDownload(this.version); const javaRelease = await this.findPackageForDownload(this.version);
core.info(`Resolved latest version as ${javaRelease.version}`); core.info(`Resolved latest version as ${javaRelease.version}`);
core.info(foundJava?.version ?? '');
core.info(javaRelease.version ?? '');
if (foundJava?.version === javaRelease.version) { if (foundJava?.version === javaRelease.version) {
core.info(`Resolved Java ${foundJava.version} from tool-cache`); core.info(`Resolved Java ${foundJava.version} from tool-cache`);
} else { } else {
@ -70,10 +68,17 @@ export abstract class JavaBase {
protected getToolcacheVersionName(version: string): string { protected getToolcacheVersionName(version: string): string {
if (!this.stable) { if (!this.stable) {
const cleanVersion = semver.clean(version); if (version.includes('+')) {
return `${cleanVersion}-ea`; return version.replace('+', '-ea.');
} else {
return `${version}-ea`;
}
} }
return version;
// Kotlin and some Java dependencies don't work properly when Java path contains "+" sign
// so replace "/hostedtoolcache/Java/11.0.3+4/x64" to "/hostedtoolcache/Java/11.0.3-4/x64" when saves to cache
// related issue: https://github.com/actions/virtual-environments/issues/3014
return version.replace('+', '-');
} }
protected findInToolcache(): JavaInstallerResults | null { protected findInToolcache(): JavaInstallerResults | null {
@ -81,27 +86,34 @@ export abstract class JavaBase {
// if *-ea is provided, take only ea versions from toolcache, otherwise - only stable versions // if *-ea is provided, take only ea versions from toolcache, otherwise - only stable versions
const availableVersions = tc const availableVersions = tc
.findAllVersions(this.toolcacheFolderName, this.architecture) .findAllVersions(this.toolcacheFolderName, this.architecture)
.filter(item => item.endsWith('-ea') === !this.stable); .map(item => {
return {
version: item
.replace('-ea.', '+')
.replace(/-ea$/, '')
// Kotlin and some Java dependencies don't work properly when Java path contains "+" sign
// so replace "/hostedtoolcache/Java/11.0.3-4/x64" to "/hostedtoolcache/Java/11.0.3+4/x64" when retrieves to cache
// related issue: https://github.com/actions/virtual-environments/issues/3014
.replace('-', '+'),
path: getToolcachePath(this.toolcacheFolderName, item, this.architecture) || '',
stable: !item.includes('-ea')
};
})
.filter(item => item.stable === this.stable);
const satisfiedVersions = availableVersions const satisfiedVersions = availableVersions
.filter(item => isVersionSatisfies(this.version, item.replace(/-ea$/, ''))) .filter(item => isVersionSatisfies(this.version, item.version))
.sort(semver.rcompare); .filter(item => item.path)
.sort((a, b) => {
return -semver.compareBuild(a.version, b.version);
});
if (!satisfiedVersions || satisfiedVersions.length === 0) { if (!satisfiedVersions || satisfiedVersions.length === 0) {
return null; return null;
} }
const javaPath = getToolcachePath(
this.toolcacheFolderName,
satisfiedVersions[0],
this.architecture
);
if (!javaPath) {
return null;
}
return { return {
version: getVersionFromToolcachePath(javaPath), version: satisfiedVersions[0].version,
path: javaPath path: satisfiedVersions[0].path
}; };
} }