mirror of
https://github.com/actions/setup-java.git
synced 2025-07-23 15:08:26 +02:00
add more capabilities
This commit is contained in:
parent
079229f185
commit
29d5f19da2
4 changed files with 107 additions and 18 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue