mirror of
https://github.com/actions/setup-java.git
synced 2025-04-20 18:06: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 fs = __importStar(require("fs"));
|
||||
const path = __importStar(require("path"));
|
||||
const httpm = __importStar(require("typed-rest-client/HttpClient"));
|
||||
const IS_WINDOWS = process.platform === 'win32';
|
||||
if (!tempDirectory) {
|
||||
let baseLocation;
|
||||
|
@ -47,7 +48,8 @@ function getJava(version, arch, jdkFile) {
|
|||
}
|
||||
else {
|
||||
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');
|
||||
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}`;
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue