diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 7e83a415..11f614bd 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -20,7 +20,33 @@ jobs: - name: npm test run: npm test - test: + testAdoptOpenJDK: + runs-on: ${{ matrix.operating-system }} + strategy: + matrix: + operating-system: [ubuntu-latest, windows-latest] + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Clear tool cache + if: runner.os != 'windows' + run: mv "${{ runner.tool_cache }}" "${{ runner.tool_cache }}.old" + - name: Clear tool cache (Windows) + if: runner.os == 'windows' + run: move "${{ runner.tool_cache }}" "${{ runner.tool_cache }}.old" + - name: Setup Java 13 + uses: ./ + with: + java-version: 13.0.2 + distro: adoptopenjdk + - name: Verify Java 13 + if: runner.os != 'windows' + run: __tests__/verify-java.sh 13.0.2 + - name: Verify Java 13 (Windows) + if: runner.os == 'windows' + run: __tests__/verify-java.ps1 13.0.2 + + testZulu: runs-on: ${{ matrix.operating-system }} strategy: matrix: @@ -46,6 +72,7 @@ jobs: if: runner.os == 'windows' run: __tests__/verify-java.ps1 13.0.2 "${{ steps.setup-java.outputs.path }}" "${{ steps.setup-java.outputs.version }}" +<<<<<<< HEAD test-proxy-adopt: runs-on: ubuntu-latest container: @@ -72,6 +99,9 @@ jobs: test-proxy-zulu: +======= + test-proxy: +>>>>>>> add more capabilities runs-on: ubuntu-latest container: image: ubuntu:latest diff --git a/README.md b/README.md index e466d8b4..aa6fbaef 100644 --- a/README.md +++ b/README.md @@ -30,12 +30,12 @@ Examples of version specifications that the java-version parameter will accept: - A major Java version e.g. ```6, 7, 8, 9, 10, 11, 12, 13, ...``` - -- A semver Java version specification (Zulu only) + +- A semver Java version specification e.g. ```8.0.232, 7.0.181, 11.0.4``` - - e.g. ```8.0.x, >11.0.3, >=13.0.1, <8.0.212``` + + e.g. ```8.0.x, >11.0.3, >=13.0.1, <8.0.212``` (Zulu only) - An early access (EA) Java version (Zulu only) @@ -46,8 +46,8 @@ Examples of version specifications that the java-version parameter will accept: e.g. ```14.0.0-ea.28, 15.0.0-ea.2``` (syntax for specifying an EA build number) Note that, per semver rules, EA builds will be matched by explicit EA version specifications. - -- 1.x syntax (Zulu only) + +- 1.x syntax e.g. ```1.8``` (same as ```8```) diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index ea970567..c41b3fcb 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -89,8 +89,8 @@ describe('installer tests', () => { }); it('Downloads java if no file given AdoptOpenJDK', async () => { - await installer.getJava('8', 'adoptopenjdk', 'x64', '', 'jdk'); - const JavaDir = path.join(toolDir, 'jdk', '8.0.0', 'x64'); + await installer.getJava('8.0.252', 'adoptopenjdk', 'x64', '', 'jdk'); + const JavaDir = path.join(toolDir, 'jdk', '8.0.252', 'x64'); expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true); expect(fs.existsSync(path.join(JavaDir, additionalPath, 'bin'))).toBe(true); @@ -103,7 +103,15 @@ describe('installer tests', () => { expect(fs.existsSync(path.join(JavaDir, 'bin'))).toBe(true); }, 100000); - it('Downloads java with 1.x syntax', async () => { + it('Downloads java with 1.x syntax AdoptOpenJDK', async () => { + await installer.getJava('1.13', 'adoptopenjdk', 'x64', '', 'jdk'); + const JavaDir = path.join(toolDir, 'jdk', '13.0.2', 'x64'); + + expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true); + expect(fs.existsSync(path.join(JavaDir, additionalPath, 'bin'))).toBe(true); + }, 100000); + + it('Downloads java with 1.x syntax Zulu', async () => { await installer.getJava('1.10', 'zulu', 'x64', '', 'jdk'); const JavaDir = path.join(toolDir, 'jdk', '10.0.2', 'x64'); @@ -111,7 +119,15 @@ describe('installer tests', () => { expect(fs.existsSync(path.join(JavaDir, 'bin'))).toBe(true); }, 100000); - it('Downloads java with normal semver syntax', async () => { + it('Downloads java with normal semver syntax AdoptOpenJDK', async () => { + await installer.getJava('13.0.x', 'adoptopenjdk', 'x64', '', 'jdk'); + const JavaDir = path.join(toolDir, 'jdk', '13.0.2', 'x64'); + + expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true); + expect(fs.existsSync(path.join(JavaDir, additionalPath, 'bin'))).toBe(true); + }, 100000); + + it('Downloads java with normal semver syntax Zulu', async () => { await installer.getJava('9.0.x', 'zulu', 'x64', '', 'jdk'); const JavaDir = path.join(toolDir, 'jdk', '9.0.7', 'x64'); @@ -120,8 +136,8 @@ describe('installer tests', () => { }, 100000); it('Downloads java if package is jre AdoptOpenJDK', async () => { - await installer.getJava('11', 'adoptopenjdk', 'x64', '', 'jre'); - const JavaDir = path.join(toolDir, 'jre', '11.0.0', 'x64'); + await installer.getJava('11.0.2', 'adoptopenjdk', 'x64', '', 'jre'); + const JavaDir = path.join(toolDir, 'jre', '11.0.2', 'x64'); expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true); expect(fs.existsSync(path.join(JavaDir, additionalPath, 'bin'))).toBe(true); diff --git a/src/distro/adoptopenjdk.ts b/src/distro/adoptopenjdk.ts index 706307c3..60c09877 100644 --- a/src/distro/adoptopenjdk.ts +++ b/src/distro/adoptopenjdk.ts @@ -1,5 +1,6 @@ import * as core from '@actions/core'; import * as tc from '@actions/tool-cache'; +import * as httpm from '@actions/http-client'; export async function getJavaAdoptOpenJDK( version: string, @@ -9,15 +10,57 @@ export async function getJavaAdoptOpenJDK( ) { core.debug('Downloading JDK from AdoptOpenJDK'); + const http = new httpm.HttpClient('setup-java', undefined, { + allowRetries: true, + maxRetries: 3 + }); + + const url = `https://api.adoptopenjdk.net/v3/assets/version/${normalizeVersion( + version + )}?architecture=${arch}&heap_size=normal&image_type=${javaPackage}&jvm_impl=hotspot&os=${OS}&page_size=1&release_type=ga&vendor=adoptopenjdk`; + + const response = await http.get(url); + const statusCode = response.message.statusCode || 0; + if (statusCode < 200 || statusCode > 299) { + let body = ''; + try { + body = await response.readBody(); + } catch (err) { + core.debug(`Unable to read body: ${err.message}`); + } + const message = `Unexpected HTTP status code '${response.message.statusCode}' when retrieving versions from '${url}'. ${body}`.trim(); + throw new Error(message); + } + + const contents = await response.readBody(); + + const parsedContents = JSON.parse(contents)[0]; + const jdkFile = await tc.downloadTool( - `https://api.adoptopenjdk.net/v3/binary/latest/${normalize( - version - )}/ga/${OS}/${arch}/${javaPackage}/hotspot/normal/adoptopenjdk` + parsedContents.binaries[0].package.link ); return [jdkFile, version]; } -function normalize(version: string): string { - if (version == '1.8') return '8'; +function normalizeVersion(version: string): string { + if (version.slice(0, 2) === '1.') { + // Trim leading 1. for versions like 1.8 + version = version.slice(2); + if (!version) { + throw new Error('1. is not a valid version'); + } + } + const parsedVersion = version.split('.'); + let versionNumber: number; + if (parsedVersion[1]) { + versionNumber = parseInt(parsedVersion[parsedVersion.length - 1]) + 1; + version = `%28%2C${version.replace( + parsedVersion[parsedVersion.length - 1], + versionNumber.toString() + )}%29`; + } else { + versionNumber = parseInt(version) + 1; + version = `%28%2C${versionNumber!.toString()}%29`; + } return version; }