diff --git a/.github/workflows/e2e-versions.yml b/.github/workflows/e2e-versions.yml index 1c17692e..619e4628 100644 --- a/.github/workflows/e2e-versions.yml +++ b/.github/workflows/e2e-versions.yml @@ -29,7 +29,6 @@ jobs: id: setup-java with: java-version: ${{ matrix.version }} - java-package: 'jdk' distribution: ${{ matrix.distribution }} - name: Verify Java run: bash __tests__/verify-java.sh "${{ matrix.version }}" "${{ steps.setup-java.outputs.path }}" @@ -45,17 +44,19 @@ jobs: os: [macos-latest, windows-latest, ubuntu-latest] distribution: ['adoptium', 'zulu'] version: - - '8.0.282' - '11.0' - - '11.0.10' - - '15.0' - exclude: - - os: windows-latest - distribution: 'zulu' - version: '8.0.282' - - os: windows-latest - distribution: 'zulu' - version: '11.0.10' + - '8.0.282' + - '11.0.2+7' + include: + - distribution: 'adoptium' + version: '12.0.2+10.1' + os: macos-latest + - distribution: 'adoptium' + version: '12.0.2+10.1' + os: windows-latest + - distribution: 'adoptium' + version: '12.0.2+10.1' + os: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v2 @@ -64,22 +65,20 @@ jobs: id: setup-java with: java-version: ${{ matrix.version }} - java-package: jdk distribution: ${{ matrix.distribution }} - name: Verify Java run: bash __tests__/verify-java.sh "${{ matrix.version }}" "${{ steps.setup-java.outputs.path }}" shell: bash - - setup-java-ea-versions: - name: ${{ matrix.distribution }} ${{ matrix.version }} (jdk-x64) - ${{ matrix.os }} + + setup-java-ea-versions-zulu: + name: zulu ${{ matrix.version }} (jdk-x64) - ${{ matrix.os }} needs: setup-java-major-minor-versions runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: os: [macos-latest, windows-latest, ubuntu-latest] - distribution: ['adoptium', 'zulu'] - version: ['14-ea', '15-ea'] + version: ['17-ea', '15.0.0-ea.14'] steps: - name: Checkout uses: actions/checkout@v2 @@ -88,11 +87,26 @@ jobs: id: setup-java with: java-version: ${{ matrix.version }} - java-package: jdk - distribution: ${{ matrix.distribution }} - - name: Verify Java - run: bash __tests__/verify-java.sh "${{ matrix.version }}" "${{ steps.setup-java.outputs.path }}" - shell: bash + distribution: zulu + + setup-java-ea-versions-adoptium: + name: adoptium ${{ matrix.version }} (jdk-x64) - ${{ matrix.os }} + needs: setup-java-major-minor-versions + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [macos-latest, windows-latest, ubuntu-latest] + version: ['17-ea', '15.0.0-ea.14.1.202003160455'] + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: setup-java + uses: ./ + id: setup-java + with: + java-version: ${{ matrix.version }} + distribution: adoptium setup-java-custom-package-type: name: ${{ matrix.distribution }} ${{ matrix.version }} (${{ matrix.java-package }}-x64) - ${{ matrix.os }} @@ -105,18 +119,7 @@ jobs: distribution: ['adoptium', 'zulu'] java-package: ['jre'] version: - - '8.0.282' - - '11.0.10' - '15.0' - exclude: - - os: windows-latest - distribution: 'zulu' - java-package: 'jre' - version: '8.0.282' - - os: windows-latest - java-package: 'jre' - distribution: 'zulu' - version: '11.0.10' include: - distribution: 'zulu' java-package: jre+fx @@ -150,7 +153,7 @@ jobs: # Only Zulu provides x86 arch for now and only for windows / ubuntu os: [windows-latest, ubuntu-latest] distribution: ['zulu'] - version: ['8', '11'] + version: ['11'] steps: - name: Checkout uses: actions/checkout@v2 @@ -160,7 +163,4 @@ jobs: with: distribution: ${{ matrix.distribution }} java-version: ${{ matrix.version }} - 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 + architecture: x86 \ No newline at end of file diff --git a/__tests__/data/adoptium.json b/__tests__/data/adoptium.json index 631b1380..bcf14030 100644 --- a/__tests__/data/adoptium.json +++ b/__tests__/data/adoptium.json @@ -528,6 +528,47 @@ "semver": "12.0.2+10.2" } }, + { + "binaries": [ + { + "architecture": "x64", + "download_count": 24493, + "heap_size": "normal", + "image_type": "jdk", + "jvm_impl": "hotspot", + "os": "mac", + "package": { + "checksum": "9919eee037554d40c7d2f219bbd654f2bf119e16a2f4d284d8dedaf525ee59e6", + "checksum_link": "https://github.com/AdoptOpenJDK/openjdk12-binaries/releases/download/jdk-12.0.2%2B10/OpenJDK12U-jdk_x64_mac_hotspot_12.0.2_10.tar.gz.sha256.txt", + "download_count": 22907, + "link": "https://github.com/AdoptOpenJDK/openjdk12-binaries/releases/download/jdk-12.0.2%2B10/OpenJDK12U-jdk_x64_mac_hotspot_12.0.2_10.tar.gz", + "metadata_link": "https://github.com/AdoptOpenJDK/openjdk12-binaries/releases/download/jdk-12.0.2%2B10/OpenJDK12U-jdk_x64_mac_hotspot_12.0.2_10.tar.gz.json", + "name": "OpenJDK12U-jdk_x64_mac_hotspot_12.0.2_10.tar.gz", + "size": 198392994 + }, + "project": "jdk", + "scm_ref": "jdk-12.0.2+9_adopt", + "updated_at": "2019-07-18T20:27:24Z" + } + ], + "download_count": 396318, + "id": "MDc6UmVsZWFzZTE4NzE2Mzk5.S/VUFSgnrVIv8A==", + "release_link": "https://github.com/AdoptOpenJDK/openjdk12-binaries/releases/tag/jdk-12.0.2%2B10", + "release_name": "jdk-12.0.2+9", + "release_type": "ga", + "timestamp": "2019-07-18T20:26:29Z", + "updated_at": "2019-07-18T20:26:29Z", + "vendor": "adoptopenjdk", + "version_data": { + "adopt_build_number": 1, + "build": 10, + "major": 12, + "minor": 0, + "openjdk_version": "12.0.2+9", + "security": 2, + "semver": "12.0.2+9.1" + } + }, { "binaries": [ { diff --git a/__tests__/distributors/adoptium-installer.test.ts b/__tests__/distributors/adoptium-installer.test.ts index 0408535f..4a180ad8 100644 --- a/__tests__/distributors/adoptium-installer.test.ts +++ b/__tests__/distributors/adoptium-installer.test.ts @@ -96,7 +96,10 @@ describe('findPackageForDownload', () => { ['15.0.1', '15.0.1+9.1'], ['11.x', '11.0.10+9'], ['x', '15.0.2+7'], - ['12', '12.0.2+10.3'] // make sure that '12.0.2+10.1', '12.0.2+10.3', '12.0.2+10.2' are sorted correctly + ['12', '12.0.2+10.3'], // make sure that '12.0.2+10.1', '12.0.2+10.3', '12.0.2+10.2' are sorted correctly + ['12.0.2+10.1', '12.0.2+10.1'], + ['15.0.1+9', '15.0.1+9'], + ['15.0.1+9.1', '15.0.1+9.1'] ])('version is resolved correctly %s -> %s', async (input, expected) => { const distribution = new AdoptiumDistribution({ version: '11', @@ -104,7 +107,7 @@ describe('findPackageForDownload', () => { packageType: 'jdk' }); distribution['getAvailableVersions'] = async () => manifestData; - const resolvedVersion = await distribution['findPackageForDownload'](new semver.Range(input)); + const resolvedVersion = await distribution['findPackageForDownload'](input); expect(resolvedVersion.version).toBe(expected); }); @@ -115,9 +118,9 @@ describe('findPackageForDownload', () => { packageType: 'jdk' }); distribution['getAvailableVersions'] = async () => manifestData; - await expect( - distribution['findPackageForDownload'](new semver.Range('9.0.8')) - ).rejects.toThrowError(/Could not find satisfied version for SemVer */); + await expect(distribution['findPackageForDownload']('9.0.8')).rejects.toThrowError( + /Could not find satisfied version for SemVer */ + ); }); it('version is not found', async () => { @@ -127,9 +130,9 @@ describe('findPackageForDownload', () => { packageType: 'jdk' }); distribution['getAvailableVersions'] = async () => manifestData; - await expect( - distribution['findPackageForDownload'](new semver.Range('7.x')) - ).rejects.toThrowError(/Could not find satisfied version for SemVer */); + await expect(distribution['findPackageForDownload']('7.x')).rejects.toThrowError( + /Could not find satisfied version for SemVer */ + ); }); it('version list is empty', async () => { @@ -139,8 +142,8 @@ describe('findPackageForDownload', () => { packageType: 'jdk' }); distribution['getAvailableVersions'] = async () => []; - await expect( - distribution['findPackageForDownload'](new semver.Range('11')) - ).rejects.toThrowError(/Could not find satisfied version for SemVer */); + await expect(distribution['findPackageForDownload']('11')).rejects.toThrowError( + /Could not find satisfied version for SemVer */ + ); }); }); diff --git a/__tests__/distributors/base-installer.test.ts b/__tests__/distributors/base-installer.test.ts index 37cd13f3..ddd1d2db 100644 --- a/__tests__/distributors/base-installer.test.ts +++ b/__tests__/distributors/base-installer.test.ts @@ -1,5 +1,6 @@ import * as tc from '@actions/tool-cache'; import * as core from '@actions/core'; +import * as util from '../../src/util'; import path from 'path'; import * as semver from 'semver'; @@ -23,7 +24,7 @@ class EmptyJavaBase extends JavaBase { }; } - protected async findPackageForDownload(range: semver.Range): Promise { + protected async findPackageForDownload(range: string): Promise { const availableVersion = '11.0.8'; if (!semver.satisfies(availableVersion, range)) { throw new Error('Available version not found'); @@ -41,11 +42,11 @@ describe('findInToolcache', () => { const javaPath = path.join('Java_Empty_jdk', actualJavaVersion, 'x64'); let mockJavaBase: EmptyJavaBase; - let spyTcFind: jest.SpyInstance; + let spyGetToolcachePath: jest.SpyInstance; let spyTcFindAllVersions: jest.SpyInstance; beforeEach(() => { - spyTcFind = jest.spyOn(tc, 'find'); + spyGetToolcachePath = jest.spyOn(util, 'getToolcachePath'); spyTcFindAllVersions = jest.spyOn(tc, 'findAllVersions'); }); @@ -74,15 +75,17 @@ describe('findInToolcache', () => { [{ version: '11', arch: 'x86', packageType: 'jre' }, null] ])(`should find java for path %s -> %s`, (input, expected) => { spyTcFindAllVersions.mockReturnValue([actualJavaVersion]); - spyTcFind.mockImplementation((toolname: string, javaVersion: string, architecture: string) => { - const semverVersion = new semver.Range(javaVersion); + spyGetToolcachePath.mockImplementation( + (toolname: string, javaVersion: string, architecture: string) => { + const semverVersion = new semver.Range(javaVersion); - if (path.basename(javaPath) !== architecture || !javaPath.includes(toolname)) { - return ''; + if (path.basename(javaPath) !== architecture || !javaPath.includes(toolname)) { + return ''; + } + + return semver.satisfies(actualJavaVersion, semverVersion) ? javaPath : ''; } - - return semver.satisfies(actualJavaVersion, semverVersion) ? javaPath : ''; - }); + ); mockJavaBase = new EmptyJavaBase(input); expect(mockJavaBase['findInToolcache']()).toEqual(expected); }); @@ -108,7 +111,7 @@ describe('findInToolcache', () => { '11.3.2-ea', '11.0.1' ]); - spyTcFind.mockImplementation( + spyGetToolcachePath.mockImplementation( (toolname: string, javaVersion: string, architecture: string) => `/hostedtoolcache/${toolname}/${javaVersion}/${architecture}` ); @@ -124,7 +127,7 @@ describe('setupJava', () => { let mockJavaBase: EmptyJavaBase; - let spyTcFind: jest.SpyInstance; + let spyGetToolcachePath: jest.SpyInstance; let spyTcFindAllVersions: jest.SpyInstance; let spyCoreDebug: jest.SpyInstance; let spyCoreInfo: jest.SpyInstance; @@ -133,16 +136,18 @@ describe('setupJava', () => { let spyCoreSetOutput: jest.SpyInstance; beforeEach(() => { - spyTcFind = jest.spyOn(tc, 'find'); - spyTcFind.mockImplementation((toolname: string, javaVersion: string, architecture: string) => { - const semverVersion = new semver.Range(javaVersion); + spyGetToolcachePath = jest.spyOn(util, 'getToolcachePath'); + spyGetToolcachePath.mockImplementation( + (toolname: string, javaVersion: string, architecture: string) => { + const semverVersion = new semver.Range(javaVersion); - if (path.basename(javaPath) !== architecture || !javaPath.includes(toolname)) { - return ''; + if (path.basename(javaPath) !== architecture || !javaPath.includes(toolname)) { + return ''; + } + + return semver.satisfies(actualJavaVersion, semverVersion) ? javaPath : ''; } - - return semver.satisfies(actualJavaVersion, semverVersion) ? javaPath : ''; - }); + ); spyTcFindAllVersions = jest.spyOn(tc, 'findAllVersions'); spyTcFindAllVersions.mockReturnValue([actualJavaVersion]); @@ -186,7 +191,7 @@ describe('setupJava', () => { ])('should find java locally for %s', (input, expected) => { mockJavaBase = new EmptyJavaBase(input); expect(mockJavaBase.setupJava()).resolves.toEqual(expected); - expect(spyTcFind).toHaveBeenCalled(); + expect(spyGetToolcachePath).toHaveBeenCalled(); }); it.each([ @@ -205,7 +210,7 @@ describe('setupJava', () => { ])('download java with configuration %s', async (input, expected) => { mockJavaBase = new EmptyJavaBase(input); await expect(mockJavaBase.setupJava()).resolves.toEqual(expected); - expect(spyTcFind).toHaveBeenCalled(); + expect(spyGetToolcachePath).toHaveBeenCalled(); expect(spyCoreAddPath).toHaveBeenCalled(); expect(spyCoreExportVariable).toHaveBeenCalled(); expect(spyCoreSetOutput).toHaveBeenCalled(); @@ -228,11 +233,11 @@ describe('normalizeVersion', () => { const DummyJavaBase = JavaBase as any; it.each([ - ['11', { version: new semver.Range('11'), stable: true }], - ['11.0', { version: new semver.Range('11.0'), stable: true }], - ['11.0.10', { version: new semver.Range('11.0.10'), stable: true }], - ['11-ea', { version: new semver.Range('11'), stable: false }], - ['11.0.2-ea', { version: new semver.Range('11.0.2'), stable: false }] + ['11', { version: '11', stable: true }], + ['11.0', { version: '11.0', stable: true }], + ['11.0.10', { version: '11.0.10', stable: true }], + ['11-ea', { version: '11', stable: false }], + ['11.0.2-ea', { version: '11.0.2', stable: false }] ])('normalizeVersion from %s to %s', (input, expected) => { expect(DummyJavaBase.prototype.normalizeVersion.call(null, input)).toEqual(expected); }); diff --git a/__tests__/distributors/local-installer.test.ts b/__tests__/distributors/local-installer.test.ts index 95c12f93..96f02f4d 100644 --- a/__tests__/distributors/local-installer.test.ts +++ b/__tests__/distributors/local-installer.test.ts @@ -5,7 +5,7 @@ import * as core from '@actions/core'; import path from 'path'; import * as semver from 'semver'; -import * as utils from '../../src/util'; +import * as util from '../../src/util'; import { LocalDistribution } from '../../src/distributions/local/installer'; @@ -15,7 +15,7 @@ describe('setupJava', () => { let mockJavaBase: LocalDistribution; - let spyTcFind: jest.SpyInstance; + let spyGetToolcachePath: jest.SpyInstance; let spyTcCacheDir: jest.SpyInstance; let spyTcFindAllVersions: jest.SpyInstance; let spyCoreDebug: jest.SpyInstance; @@ -30,16 +30,18 @@ describe('setupJava', () => { let expectedJdkFile = 'JavaLocalJdkFile'; beforeEach(() => { - spyTcFind = jest.spyOn(tc, 'find'); - spyTcFind.mockImplementation((toolname: string, javaVersion: string, architecture: string) => { - const semverVersion = new semver.Range(javaVersion); + spyGetToolcachePath = jest.spyOn(util, 'getToolcachePath'); + spyGetToolcachePath.mockImplementation( + (toolname: string, javaVersion: string, architecture: string) => { + const semverVersion = new semver.Range(javaVersion); - if (path.basename(javaPath) !== architecture || !javaPath.includes(toolname)) { - return ''; + if (path.basename(javaPath) !== architecture || !javaPath.includes(toolname)) { + return ''; + } + + return semver.satisfies(actualJavaVersion, semverVersion) ? javaPath : ''; } - - return semver.satisfies(actualJavaVersion, semverVersion) ? javaPath : ''; - }); + ); spyTcCacheDir = jest.spyOn(tc, 'cacheDir'); spyTcCacheDir.mockImplementation( @@ -76,7 +78,7 @@ describe('setupJava', () => { }); // Spy on util methods - spyUtilsExtractJdkFile = jest.spyOn(utils, 'extractJdkFile'); + spyUtilsExtractJdkFile = jest.spyOn(util, 'extractJdkFile'); spyUtilsExtractJdkFile.mockImplementation(() => 'some/random/path/'); // Spy on path methods @@ -100,7 +102,7 @@ describe('setupJava', () => { mockJavaBase = new LocalDistribution(inputs, jdkFile); await expect(mockJavaBase.setupJava()).resolves.toEqual(expected); - expect(spyTcFind).toHaveBeenCalled(); + expect(spyGetToolcachePath).toHaveBeenCalled(); expect(spyCoreInfo).toHaveBeenCalledWith(`Resolved Java ${actualJavaVersion} from tool-cache`); expect(spyCoreInfo).not.toHaveBeenCalledWith( `Java ${inputs.version} was not found in tool-cache. Trying to unpack JDK file...` @@ -117,7 +119,7 @@ describe('setupJava', () => { mockJavaBase = new LocalDistribution(inputs, jdkFile); await expect(mockJavaBase.setupJava()).resolves.toEqual(expected); - expect(spyTcFind).toHaveBeenCalled(); + expect(spyGetToolcachePath).toHaveBeenCalled(); expect(spyCoreInfo).toHaveBeenCalledWith(`Resolved Java ${actualJavaVersion} from tool-cache`); expect(spyCoreInfo).not.toHaveBeenCalledWith( `Java ${inputs.version} was not found in tool-cache. Trying to unpack JDK file...` diff --git a/__tests__/distributors/zulu-installer.test.ts b/__tests__/distributors/zulu-installer.test.ts index eb310b06..c4f4783c 100644 --- a/__tests__/distributors/zulu-installer.test.ts +++ b/__tests__/distributors/zulu-installer.test.ts @@ -96,7 +96,10 @@ describe('findPackageForDownload', () => { ['15', '15.0.2+7'], ['9.0.0', '9.0.0+0'], ['9.0', '9.0.1+0'], - ['8.0.262', '8.0.262+19'] // validate correct choise between [8.0.262.17, 8.0.262.19, 8.0.262.18] + ['8.0.262', '8.0.262+19'], // validate correct choise between [8.0.262.17, 8.0.262.19, 8.0.262.18] + ['8.0.262+17', '8.0.262+17'], + ['15.0.1+8', '15.0.1+8'], + ['15.0.1+9', '15.0.1+9'] ])('version is %s -> %s', async (input, expected) => { const distribution = new ZuluDistribution({ version: input, @@ -111,7 +114,7 @@ describe('findPackageForDownload', () => { it('select correct bundle if there are multiple items with the same jdk version but different zulu versions', async () => { const distribution = new ZuluDistribution({ version: '', arch: 'x86', packageType: 'jdk' }); distribution['getAvailableVersions'] = async () => manifestData; - const result = await distribution['findPackageForDownload'](new semver.Range('11.0.5')); + const result = await distribution['findPackageForDownload']('11.0.5'); expect(result.url).toBe( 'https://cdn.azul.com/zulu/bin/zulu11.35.15-ca-jdk11.0.5-macosx_x64.tar.gz' ); diff --git a/__tests__/util.test.ts b/__tests__/util.test.ts new file mode 100644 index 00000000..6509917e --- /dev/null +++ b/__tests__/util.test.ts @@ -0,0 +1,22 @@ +import { isVersionSatisfies } from '../src/util'; + +describe('isVersionSatisfies', () => { + it.each([ + ['x', '11.0.0', true], + ['3', '3.7.1', true], + ['3', '3.7.2', true], + ['3', '3.7.2+4', true], + ['2.5', '2.5.0', true], + ['2.5', '2.5.0+1', true], + ['2.5', '2.6.1', false], + ['2.5.1', '2.5.0', false], + ['2.5.1+3', '2.5.0', false], + ['2.5.1+3', '2.5.1+3', true], + ['2.5.1+3', '2.5.1+2', false], + ['15.0.0+14', '15.0.0+14.1.202003190635', false], + ['15.0.0+14.1.202003190635', '15.0.0+14.1.202003190635', true] + ])('%s, %s -> %s', (inputRange: string, inputVersion: string, expected: boolean) => { + const actual = isVersionSatisfies(inputRange, inputVersion); + expect(actual).toBe(expected); + }); +}); diff --git a/__tests__/verify-java.sh b/__tests__/verify-java.sh index 130ae36b..1bad5d35 100755 --- a/__tests__/verify-java.sh +++ b/__tests__/verify-java.sh @@ -10,12 +10,16 @@ if [ -z "$2" ]; then exit 1 fi -EXPECTED_JAVA_VERSION=${1/-ea/} +EXPECTED_JAVA_VERSION=$1 EXPECTED_PATH=$2 +EXPECTED_JAVA_VERSION=$(echo $EXPECTED_JAVA_VERSION | cut -d'+' -f1) if [[ $EXPECTED_JAVA_VERSION == 8 ]] || [[ $EXPECTED_JAVA_VERSION == 8.* ]]; then EXPECTED_JAVA_VERSION="1.${EXPECTED_JAVA_VERSION}" fi +if [[ $EXPECTED_JAVA_VERSION == *-ea* ]]; then + EXPECTED_JAVA_VERSION=$(echo $EXPECTED_JAVA_VERSION | cut -d'-' -f1 | cut -d'.' -f1) +fi ACTUAL_JAVA_VERSION="$(java -version 2>&1)" echo "Found java version: $ACTUAL_JAVA_VERSION"