diff --git a/.github/workflows/e2e-versions.yml b/.github/workflows/e2e-versions.yml index 42d7d2dd..24b3c84e 100644 --- a/.github/workflows/e2e-versions.yml +++ b/.github/workflows/e2e-versions.yml @@ -78,6 +78,15 @@ jobs: - name: Verify Java run: bash __tests__/verify-java.sh "${{ matrix.version }}" "${{ steps.setup-java.outputs.path }}" shell: bash + - name: setup-java + uses: ./ + id: setup-java2 + with: + java-version: ${{ matrix.version }} + distribution: ${{ matrix.distribution }} + - name: Verify Java + run: bash __tests__/verify-java.sh "${{ matrix.version }}" "${{ steps.setup-java2.outputs.path }}" + shell: bash setup-java-check-latest: name: ${{ matrix.distribution }} ${{ matrix.version }} - check-latest flag - ${{ matrix.os }} @@ -217,4 +226,7 @@ jobs: with: distribution: ${{ matrix.distribution }} java-version: ${{ matrix.version }} - architecture: x86 \ No newline at end of file + architecture: x86 + - name: Verify Java + run: bash __tests__/verify-java.sh "${{ matrix.version }}" "${{ steps.setup-java.outputs.path }}" + shell: bash \ No newline at end of file diff --git a/__tests__/distributors/base-installer.test.ts b/__tests__/distributors/base-installer.test.ts index a36393a8..177c7ace 100644 --- a/__tests__/distributors/base-installer.test.ts +++ b/__tests__/distributors/base-installer.test.ts @@ -103,24 +103,27 @@ describe('findInToolcache', () => { }); it.each([ - ['11', '11.0.3'], - ['11.0', '11.0.3'], - ['11.0.1', '11.0.1'], - ['11.0.3', '11.0.3'], - ['15', '15.0.2'], - ['x', '15.0.2'], - ['x-ea', '17.4.4-ea'], - ['11-ea', '11.3.2-ea'], - ['11.2-ea', '11.2.1-ea'], - ['11.2.1-ea', '11.2.1-ea'] + ['11', { version: '11.0.3+2', versionInPath: '11.0.3-2' }], + ['11.0', { version: '11.0.3+2', versionInPath: '11.0.3-2' }], + ['11.0.1', { version: '11.0.1', versionInPath: '11.0.1' }], + ['11.0.3', { version: '11.0.3+2', versionInPath: '11.0.3-2' }], + ['15', { version: '15.0.2+4', versionInPath: '15.0.2-4' }], + ['x', { version: '15.0.2+4', versionInPath: '15.0.2-4' }], + ['x-ea', { version: '17.4.4', versionInPath: '17.4.4-ea' }], + ['11-ea', { version: '11.3.3+5.2.1231421', versionInPath: '11.3.3-ea.5.2.1231421' }], + ['11.2-ea', { version: '11.2.1', versionInPath: '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) => { spyTcFindAllVersions.mockReturnValue([ '17.4.4-ea', '11.0.2', - '15.0.2', - '11.0.3', + '15.0.2-4', + '11.0.3-2', '11.2.1-ea', '11.3.2-ea', + '11.3.2-ea.5', + '11.3.3-ea.5.2.1231421', + '12.3.2-0', '11.0.1' ]); spyGetToolcachePath.mockImplementation( @@ -134,7 +137,10 @@ describe('findInToolcache', () => { checkLatest: false }); 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); + }); +}); diff --git a/dist/setup/index.js b/dist/setup/index.js index f329f2d5..2c37a5bf 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -4006,30 +4006,49 @@ class JavaBase { } getToolcacheVersionName(version) { if (!this.stable) { - const cleanVersion = semver_1.default.clean(version); - return `${cleanVersion}-ea`; + if (version.includes('+')) { + 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() { // 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 const availableVersions = tc .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 - .filter(item => util_1.isVersionSatisfies(this.version, item.replace(/-ea$/, ''))) - .sort(semver_1.default.rcompare); + .filter(item => util_1.isVersionSatisfies(this.version, item.version)) + .filter(item => item.path) + .sort((a, b) => { + return -semver_1.default.compareBuild(a.version, b.version); + }); if (!satisfiedVersions || satisfiedVersions.length === 0) { return null; } - const javaPath = util_1.getToolcachePath(this.toolcacheFolderName, satisfiedVersions[0], this.architecture); - if (!javaPath) { - return null; - } return { - version: util_1.getVersionFromToolcachePath(javaPath), - path: javaPath + version: satisfiedVersions[0].version, + path: satisfiedVersions[0].path }; } normalizeVersion(version) { diff --git a/src/distributions/base-installer.ts b/src/distributions/base-installer.ts index bfecd20e..dd5b6df5 100644 --- a/src/distributions/base-installer.ts +++ b/src/distributions/base-installer.ts @@ -77,6 +77,9 @@ export abstract class JavaBase { } } + // 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('+', '-'); } @@ -90,18 +93,19 @@ export abstract class JavaBase { 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), + path: getToolcachePath(this.toolcacheFolderName, item, this.architecture) || '', stable: !item.includes('-ea') }; }) .filter(item => item.stable === this.stable); - console.log(`availableVersions = ${JSON.stringify(availableVersions)}`); - const satisfiedVersions = availableVersions .filter(item => isVersionSatisfies(this.version, item.version)) - .filter(item => item.path !== null) + .filter(item => item.path) .sort((a, b) => { return -semver.compareBuild(a.version, b.version); }); @@ -109,9 +113,10 @@ export abstract class JavaBase { return null; } - console.log(`satisfiedVersions = ${JSON.stringify(satisfiedVersions)}`); - - return satisfiedVersions[0] as JavaInstallerResults; + return { + version: satisfiedVersions[0].version, + path: satisfiedVersions[0].path + }; } protected normalizeVersion(version: string) {