add more capabilities

This commit is contained in:
George Adams 2020-05-27 14:53:29 +01:00
parent 079229f185
commit 29d5f19da2
No known key found for this signature in database
GPG key ID: 7B8D7E4421A0916D
4 changed files with 107 additions and 18 deletions

View file

@ -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

View file

@ -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```)

View file

@ -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);

View file

@ -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;
}