mirror of
https://github.com/actions/setup-java.git
synced 2025-04-19 17:36:45 +00:00
Download from zulu
This commit is contained in:
parent
012e07621e
commit
d04dab381d
2 changed files with 70 additions and 4 deletions
|
@ -22,6 +22,7 @@ const exec = __importStar(require("@actions/exec"));
|
||||||
const tc = __importStar(require("@actions/tool-cache"));
|
const tc = __importStar(require("@actions/tool-cache"));
|
||||||
const fs = __importStar(require("fs"));
|
const fs = __importStar(require("fs"));
|
||||||
const path = __importStar(require("path"));
|
const path = __importStar(require("path"));
|
||||||
|
const httpm = __importStar(require("typed-rest-client/HttpClient"));
|
||||||
const IS_WINDOWS = process.platform === 'win32';
|
const IS_WINDOWS = process.platform === 'win32';
|
||||||
if (!tempDirectory) {
|
if (!tempDirectory) {
|
||||||
let baseLocation;
|
let baseLocation;
|
||||||
|
@ -47,7 +48,8 @@ function getJava(version, arch, jdkFile) {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!jdkFile) {
|
if (!jdkFile) {
|
||||||
throw new Error(`Failed to find Java ${version} in the cache. Please specify a valid jdk file to install from instead.`);
|
const downloadUrl = yield getDownloadUrl(version);
|
||||||
|
jdkFile = yield tc.downloadTool(downloadUrl);
|
||||||
}
|
}
|
||||||
core.debug('Retrieving Jdk from local path');
|
core.debug('Retrieving Jdk from local path');
|
||||||
const compressedFileExtension = getFileEnding(jdkFile);
|
const compressedFileExtension = getFileEnding(jdkFile);
|
||||||
|
@ -143,3 +145,32 @@ function unzipJavaDownload(repoRoot, fileEnding, destinationFolder) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
function getDownloadUrl(version) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
let filterString = '';
|
||||||
|
if (IS_WINDOWS) {
|
||||||
|
filterString = `jdk${version}-win_x64.zip`;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (process.platform === 'darwin') {
|
||||||
|
filterString = `jdk${version}-macosx_x64.tar.gz`;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
filterString = `jdk${version}-linux_x64.tar.gz`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let http = new httpm.HttpClient('setup-java');
|
||||||
|
let contents = yield (yield http.get('https://static.azul.com/zulu/bin/')).readBody();
|
||||||
|
let refs = contents.match(/<a href.*\">/gi) || [];
|
||||||
|
refs = refs.filter(val => {
|
||||||
|
if (val.indexOf(filterString) > -1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (refs.length == 0) {
|
||||||
|
throw new Error(`No valid download found for version ${version}. Check https://static.azul.com/zulu/bin/ for a list of valid versions or download your own jdk file and add the jdkFile argument`);
|
||||||
|
}
|
||||||
|
const downloadLocation = refs[0].slice('<a href="'.length, refs[0].length - '">'.length);
|
||||||
|
return `https://static.azul.com/zulu/bin/${downloadLocation}`;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import * as exec from '@actions/exec';
|
||||||
import * as tc from '@actions/tool-cache';
|
import * as tc from '@actions/tool-cache';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
import * as httpm from 'typed-rest-client/HttpClient';
|
||||||
|
|
||||||
const IS_WINDOWS = process.platform === 'win32';
|
const IS_WINDOWS = process.platform === 'win32';
|
||||||
|
|
||||||
|
@ -35,9 +36,8 @@ export async function getJava(
|
||||||
core.debug(`Tool found in cache ${toolPath}`);
|
core.debug(`Tool found in cache ${toolPath}`);
|
||||||
} else {
|
} else {
|
||||||
if (!jdkFile) {
|
if (!jdkFile) {
|
||||||
throw new Error(
|
const downloadUrl: string = await getDownloadUrl(version);
|
||||||
`Failed to find Java ${version} in the cache. Please specify a valid jdk file to install from instead.`
|
jdkFile = await tc.downloadTool(downloadUrl);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
core.debug('Retrieving Jdk from local path');
|
core.debug('Retrieving Jdk from local path');
|
||||||
const compressedFileExtension = getFileEnding(jdkFile);
|
const compressedFileExtension = getFileEnding(jdkFile);
|
||||||
|
@ -143,3 +143,38 @@ async function unzipJavaDownload(
|
||||||
throw new Error(`Jdk argument ${jdkFile} is not a file`);
|
throw new Error(`Jdk argument ${jdkFile} is not a file`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getDownloadUrl(version: string) {
|
||||||
|
let filterString = '';
|
||||||
|
if (IS_WINDOWS) {
|
||||||
|
filterString = `jdk${version}-win_x64.zip`;
|
||||||
|
} else {
|
||||||
|
if (process.platform === 'darwin') {
|
||||||
|
filterString = `jdk${version}-macosx_x64.tar.gz`;
|
||||||
|
} else {
|
||||||
|
filterString = `jdk${version}-linux_x64.tar.gz`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let http: httpm.HttpClient = new httpm.HttpClient('setup-java');
|
||||||
|
let contents = await (await http.get(
|
||||||
|
'https://static.azul.com/zulu/bin/'
|
||||||
|
)).readBody();
|
||||||
|
let refs = contents.match(/<a href.*\">/gi) || [];
|
||||||
|
refs = refs.filter(val => {
|
||||||
|
if (val.indexOf(filterString) > -1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (refs.length == 0) {
|
||||||
|
throw new Error(
|
||||||
|
`No valid download found for version ${version}. Check https://static.azul.com/zulu/bin/ for a list of valid versions or download your own jdk file and add the jdkFile argument`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const downloadLocation = refs[0].slice(
|
||||||
|
'<a href="'.length,
|
||||||
|
refs[0].length - '">'.length
|
||||||
|
);
|
||||||
|
return `https://static.azul.com/zulu/bin/${downloadLocation}`;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue