1
0
Fork 0
mirror of https://github.com/actions/setup-java synced 2024-12-22 21:22:41 +00:00

Merge pull request #48 from ericsciple/users/ericsciple/m166retry

add retries and error handling
This commit is contained in:
Konrad Pabjan 2020-02-11 17:56:38 -05:00 committed by GitHub
commit f63b906f27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 428 additions and 398 deletions

View file

@ -9,12 +9,12 @@ jobs:
operating-system: [ubuntu-latest, windows-latest] operating-system: [ubuntu-latest, windows-latest]
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@master uses: actions/checkout@v2
- name: Set Node.js 10.x - name: Setup Node.js 12.x
uses: actions/setup-node@master uses: actions/setup-node@v1
with: with:
node-version: 10.x node-version: 12.x
- name: npm install - name: npm install
run: npm install run: npm install
@ -40,12 +40,12 @@ jobs:
run: | run: |
echo "127.0.0.0 registry.npm.js nodejs.org github.com api.github.com download.java.net static.azul.com" | sudo tee -a /etc/hosts echo "127.0.0.0 registry.npm.js nodejs.org github.com api.github.com download.java.net static.azul.com" | sudo tee -a /etc/hosts
- name: Checkout - name: Checkout
uses: actions/checkout@master uses: actions/checkout@v2
- name: Set Node.js 10.x - name: Setup Node.js 12.x
uses: actions/setup-node@master uses: actions/setup-node@v1
with: with:
node-version: 10.x node-version: 12.x
- name: npm install - name: npm install
run: npm install run: npm install

783
dist/index.js generated vendored
View file

@ -2856,84 +2856,84 @@ function coerce (version, options) {
/***/ (function(__unusedmodule, exports, __webpack_require__) { /***/ (function(__unusedmodule, exports, __webpack_require__) {
"use strict"; "use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) { return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next()); step((generator = generator.apply(thisArg, _arguments || [])).next());
}); });
}; };
var __importStar = (this && this.__importStar) || function (mod) { var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod; if (mod && mod.__esModule) return mod;
var result = {}; var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod; result["default"] = mod;
return result; return result;
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const fs = __importStar(__webpack_require__(747)); const fs = __importStar(__webpack_require__(747));
const os = __importStar(__webpack_require__(87)); const os = __importStar(__webpack_require__(87));
const path = __importStar(__webpack_require__(622)); const path = __importStar(__webpack_require__(622));
const core = __importStar(__webpack_require__(470)); const core = __importStar(__webpack_require__(470));
const io = __importStar(__webpack_require__(1)); const io = __importStar(__webpack_require__(1));
exports.M2_DIR = '.m2'; exports.M2_DIR = '.m2';
exports.SETTINGS_FILE = 'settings.xml'; exports.SETTINGS_FILE = 'settings.xml';
exports.DEFAULT_ID = 'github'; exports.DEFAULT_ID = 'github';
exports.DEFAULT_USERNAME = 'GITHUB_ACTOR'; exports.DEFAULT_USERNAME = 'GITHUB_ACTOR';
exports.DEFAULT_PASSWORD = 'GITHUB_TOKEN'; exports.DEFAULT_PASSWORD = 'GITHUB_TOKEN';
function configAuthentication(id = exports.DEFAULT_ID, username = exports.DEFAULT_USERNAME, password = exports.DEFAULT_PASSWORD) { function configAuthentication(id = exports.DEFAULT_ID, username = exports.DEFAULT_USERNAME, password = exports.DEFAULT_PASSWORD) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
console.log(`creating ${exports.SETTINGS_FILE} with server-id: ${id};`, `environment variables: username=\$${username} and password=\$${password}`); console.log(`creating ${exports.SETTINGS_FILE} with server-id: ${id};`, `environment variables: username=\$${username} and password=\$${password}`);
// when an alternate m2 location is specified use only that location (no .m2 directory) // when an alternate m2 location is specified use only that location (no .m2 directory)
// otherwise use the home/.m2/ path // otherwise use the home/.m2/ path
const directory = path.join(core.getInput('settings-path') || os.homedir(), core.getInput('settings-path') ? '' : exports.M2_DIR); const directory = path.join(core.getInput('settings-path') || os.homedir(), core.getInput('settings-path') ? '' : exports.M2_DIR);
yield io.mkdirP(directory); yield io.mkdirP(directory);
core.debug(`created directory ${directory}`); core.debug(`created directory ${directory}`);
yield write(directory, generate(id, username, password)); yield write(directory, generate(id, username, password));
}); });
} }
exports.configAuthentication = configAuthentication; exports.configAuthentication = configAuthentication;
function escapeXML(value) { function escapeXML(value) {
return value return value
.replace(/&/g, '&') .replace(/&/g, '&')
.replace(/</g, '&lt;') .replace(/</g, '&lt;')
.replace(/>/g, '&gt;') .replace(/>/g, '&gt;')
.replace(/"/g, '&quot;') .replace(/"/g, '&quot;')
.replace(/'/g, '&apos;'); .replace(/'/g, '&apos;');
} }
// only exported for testing purposes // only exported for testing purposes
function generate(id = exports.DEFAULT_ID, username = exports.DEFAULT_USERNAME, password = exports.DEFAULT_PASSWORD) { function generate(id = exports.DEFAULT_ID, username = exports.DEFAULT_USERNAME, password = exports.DEFAULT_PASSWORD) {
return ` return `
<settings> <settings>
<servers> <servers>
<server> <server>
<id>${escapeXML(id)}</id> <id>${escapeXML(id)}</id>
<username>\${env.${escapeXML(username)}}</username> <username>\${env.${escapeXML(username)}}</username>
<password>\${env.${escapeXML(password)}}</password> <password>\${env.${escapeXML(password)}}</password>
</server> </server>
</servers> </servers>
</settings> </settings>
`; `;
} }
exports.generate = generate; exports.generate = generate;
function write(directory, settings) { function write(directory, settings) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const location = path.join(directory, exports.SETTINGS_FILE); const location = path.join(directory, exports.SETTINGS_FILE);
if (fs.existsSync(location)) { if (fs.existsSync(location)) {
console.warn(`overwriting existing file ${location}`); console.warn(`overwriting existing file ${location}`);
} }
else { else {
console.log(`writing ${location}`); console.log(`writing ${location}`);
} }
return fs.writeFileSync(location, settings, { return fs.writeFileSync(location, settings, {
encoding: 'utf-8', encoding: 'utf-8',
flag: 'w' flag: 'w'
}); });
}); });
} }
/***/ }), /***/ }),
@ -4525,52 +4525,52 @@ module.exports = require("fs");
/***/ (function(__unusedmodule, exports, __webpack_require__) { /***/ (function(__unusedmodule, exports, __webpack_require__) {
"use strict"; "use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) { return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next()); step((generator = generator.apply(thisArg, _arguments || [])).next());
}); });
}; };
var __importStar = (this && this.__importStar) || function (mod) { var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod; if (mod && mod.__esModule) return mod;
var result = {}; var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod; result["default"] = mod;
return result; return result;
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(__webpack_require__(470)); const core = __importStar(__webpack_require__(470));
const installer = __importStar(__webpack_require__(923)); const installer = __importStar(__webpack_require__(923));
const auth = __importStar(__webpack_require__(331)); const auth = __importStar(__webpack_require__(331));
const path = __importStar(__webpack_require__(622)); const path = __importStar(__webpack_require__(622));
function run() { function run() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try { try {
let version = core.getInput('version'); let version = core.getInput('version');
if (!version) { if (!version) {
version = core.getInput('java-version', { required: true }); version = core.getInput('java-version', { required: true });
} }
const arch = core.getInput('architecture', { required: true }); const arch = core.getInput('architecture', { required: true });
const javaPackage = core.getInput('java-package', { required: true }); const javaPackage = core.getInput('java-package', { required: true });
const jdkFile = core.getInput('jdkFile', { required: false }) || ''; const jdkFile = core.getInput('jdkFile', { required: false }) || '';
yield installer.getJava(version, arch, jdkFile, javaPackage); yield installer.getJava(version, arch, jdkFile, javaPackage);
const matchersPath = path.join(__dirname, '..', '.github'); const matchersPath = path.join(__dirname, '..', '.github');
console.log(`##[add-matcher]${path.join(matchersPath, 'java.json')}`); console.log(`##[add-matcher]${path.join(matchersPath, 'java.json')}`);
const id = core.getInput('server-id', { required: false }) || undefined; const id = core.getInput('server-id', { required: false }) || undefined;
const username = core.getInput('server-username', { required: false }) || undefined; const username = core.getInput('server-username', { required: false }) || undefined;
const password = core.getInput('server-password', { required: false }) || undefined; const password = core.getInput('server-password', { required: false }) || undefined;
yield auth.configAuthentication(id, username, password); yield auth.configAuthentication(id, username, password);
} }
catch (error) { catch (error) {
core.setFailed(error.message); core.setFailed(error.message);
} }
}); });
} }
run(); run();
/***/ }), /***/ }),
@ -4622,265 +4622,282 @@ module.exports = require("url");
/***/ (function(__unusedmodule, exports, __webpack_require__) { /***/ (function(__unusedmodule, exports, __webpack_require__) {
"use strict"; "use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) { return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next()); step((generator = generator.apply(thisArg, _arguments || [])).next());
}); });
}; };
var __importStar = (this && this.__importStar) || function (mod) { var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod; if (mod && mod.__esModule) return mod;
var result = {}; var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod; result["default"] = mod;
return result; return result;
}; };
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
let tempDirectory = process.env['RUNNER_TEMP'] || ''; let tempDirectory = process.env['RUNNER_TEMP'] || '';
const core = __importStar(__webpack_require__(470)); const core = __importStar(__webpack_require__(470));
const io = __importStar(__webpack_require__(1)); const io = __importStar(__webpack_require__(1));
const exec = __importStar(__webpack_require__(986)); const exec = __importStar(__webpack_require__(986));
const tc = __importStar(__webpack_require__(533)); const httpm = __importStar(__webpack_require__(539));
const fs = __importStar(__webpack_require__(747)); const tc = __importStar(__webpack_require__(533));
const path = __importStar(__webpack_require__(622)); const fs = __importStar(__webpack_require__(747));
const semver = __importStar(__webpack_require__(280)); const path = __importStar(__webpack_require__(622));
const httpm = __importStar(__webpack_require__(539)); const semver = __importStar(__webpack_require__(280));
const IS_WINDOWS = process.platform === 'win32'; const IS_WINDOWS = process.platform === 'win32';
if (!tempDirectory) { if (!tempDirectory) {
let baseLocation; let baseLocation;
if (IS_WINDOWS) { if (IS_WINDOWS) {
// On windows use the USERPROFILE env variable // On windows use the USERPROFILE env variable
baseLocation = process.env['USERPROFILE'] || 'C:\\'; baseLocation = process.env['USERPROFILE'] || 'C:\\';
} }
else { else {
if (process.platform === 'darwin') { if (process.platform === 'darwin') {
baseLocation = '/Users'; baseLocation = '/Users';
} }
else { else {
baseLocation = '/home'; baseLocation = '/home';
} }
} }
tempDirectory = path.join(baseLocation, 'actions', 'temp'); tempDirectory = path.join(baseLocation, 'actions', 'temp');
} }
function getJava(version, arch, jdkFile, javaPackage) { function getJava(version, arch, jdkFile, javaPackage) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
let toolPath = tc.find(javaPackage, version); let toolPath = tc.find(javaPackage, version);
if (toolPath) { if (toolPath) {
core.debug(`Tool found in cache ${toolPath}`); core.debug(`Tool found in cache ${toolPath}`);
} }
else { else {
let compressedFileExtension = ''; let compressedFileExtension = '';
if (!jdkFile) { if (!jdkFile) {
core.debug('Downloading Jdk from Azul'); core.debug('Downloading JDK from Azul');
let http = new httpm.HttpClient('setup-java'); const http = new httpm.HttpClient('setup-java', undefined, {
let contents = yield (yield http.get('https://static.azul.com/zulu/bin/')).readBody(); allowRetries: true,
let refs = contents.match(/<a href.*\">/gi) || []; maxRetries: 3
const downloadInfo = getDownloadInfo(refs, version, javaPackage); });
jdkFile = yield tc.downloadTool(downloadInfo.url); const url = 'https://static.azul.com/zulu/bin/';
version = downloadInfo.version; const response = yield http.get(url);
compressedFileExtension = IS_WINDOWS ? '.zip' : '.tar.gz'; const statusCode = response.message.statusCode || 0;
} if (statusCode < 200 || statusCode > 299) {
else { let body = '';
core.debug('Retrieving Jdk from local path'); try {
} body = yield response.readBody();
compressedFileExtension = compressedFileExtension || getFileEnding(jdkFile); }
let tempDir = path.join(tempDirectory, 'temp_' + Math.floor(Math.random() * 2000000000)); catch (err) {
const jdkDir = yield unzipJavaDownload(jdkFile, compressedFileExtension, tempDir); core.debug(`Unable to read body: ${err.message}`);
core.debug(`jdk extracted to ${jdkDir}`); }
toolPath = yield tc.cacheDir(jdkDir, javaPackage, getCacheVersionString(version), arch); const message = `Unexpected HTTP status code '${response.message.statusCode}' when retrieving versions from '${url}'. ${body}`.trim();
} throw new Error(message);
let extendedJavaHome = 'JAVA_HOME_' + version + '_' + arch; }
core.exportVariable('JAVA_HOME', toolPath); const contents = yield response.readBody();
core.exportVariable(extendedJavaHome, toolPath); const refs = contents.match(/<a href.*\">/gi) || [];
core.addPath(path.join(toolPath, 'bin')); const downloadInfo = getDownloadInfo(refs, version, javaPackage);
}); jdkFile = yield tc.downloadTool(downloadInfo.url);
} version = downloadInfo.version;
exports.getJava = getJava; compressedFileExtension = IS_WINDOWS ? '.zip' : '.tar.gz';
function getCacheVersionString(version) { }
const versionArray = version.split('.'); else {
const major = versionArray[0]; core.debug('Retrieving Jdk from local path');
const minor = versionArray.length > 1 ? versionArray[1] : '0'; }
const patch = versionArray.length > 2 ? versionArray[2] : '0'; compressedFileExtension = compressedFileExtension || getFileEnding(jdkFile);
return `${major}.${minor}.${patch}`; let tempDir = path.join(tempDirectory, 'temp_' + Math.floor(Math.random() * 2000000000));
} const jdkDir = yield unzipJavaDownload(jdkFile, compressedFileExtension, tempDir);
function getFileEnding(file) { core.debug(`jdk extracted to ${jdkDir}`);
let fileEnding = ''; toolPath = yield tc.cacheDir(jdkDir, javaPackage, getCacheVersionString(version), arch);
if (file.endsWith('.tar')) { }
fileEnding = '.tar'; let extendedJavaHome = 'JAVA_HOME_' + version + '_' + arch;
} core.exportVariable('JAVA_HOME', toolPath);
else if (file.endsWith('.tar.gz')) { core.exportVariable(extendedJavaHome, toolPath);
fileEnding = '.tar.gz'; core.addPath(path.join(toolPath, 'bin'));
} });
else if (file.endsWith('.zip')) { }
fileEnding = '.zip'; exports.getJava = getJava;
} function getCacheVersionString(version) {
else if (file.endsWith('.7z')) { const versionArray = version.split('.');
fileEnding = '.7z'; const major = versionArray[0];
} const minor = versionArray.length > 1 ? versionArray[1] : '0';
else { const patch = versionArray.length > 2 ? versionArray[2] : '0';
throw new Error(`${file} has an unsupported file extension`); return `${major}.${minor}.${patch}`;
} }
return fileEnding; function getFileEnding(file) {
} let fileEnding = '';
function extractFiles(file, fileEnding, destinationFolder) { if (file.endsWith('.tar')) {
return __awaiter(this, void 0, void 0, function* () { fileEnding = '.tar';
const stats = fs.statSync(file); }
if (!stats) { else if (file.endsWith('.tar.gz')) {
throw new Error(`Failed to extract ${file} - it doesn't exist`); fileEnding = '.tar.gz';
} }
else if (stats.isDirectory()) { else if (file.endsWith('.zip')) {
throw new Error(`Failed to extract ${file} - it is a directory`); fileEnding = '.zip';
} }
if ('.tar' === fileEnding || '.tar.gz' === fileEnding) { else if (file.endsWith('.7z')) {
yield tc.extractTar(file, destinationFolder); fileEnding = '.7z';
} }
else if ('.zip' === fileEnding) { else {
yield tc.extractZip(file, destinationFolder); throw new Error(`${file} has an unsupported file extension`);
} }
else { return fileEnding;
// fall through and use sevenZip }
yield tc.extract7z(file, destinationFolder); function extractFiles(file, fileEnding, destinationFolder) {
} return __awaiter(this, void 0, void 0, function* () {
}); const stats = fs.statSync(file);
} if (!stats) {
// This method recursively finds all .pack files under fsPath and unpacks them with the unpack200 tool throw new Error(`Failed to extract ${file} - it doesn't exist`);
function unpackJars(fsPath, javaBinPath) { }
return __awaiter(this, void 0, void 0, function* () { else if (stats.isDirectory()) {
if (fs.existsSync(fsPath)) { throw new Error(`Failed to extract ${file} - it is a directory`);
if (fs.lstatSync(fsPath).isDirectory()) { }
for (const file in fs.readdirSync(fsPath)) { if ('.tar' === fileEnding || '.tar.gz' === fileEnding) {
const curPath = path.join(fsPath, file); yield tc.extractTar(file, destinationFolder);
yield unpackJars(curPath, javaBinPath); }
} else if ('.zip' === fileEnding) {
} yield tc.extractZip(file, destinationFolder);
else if (path.extname(fsPath).toLowerCase() === '.pack') { }
// Unpack the pack file synchonously else {
const p = path.parse(fsPath); // fall through and use sevenZip
const toolName = IS_WINDOWS ? 'unpack200.exe' : 'unpack200'; yield tc.extract7z(file, destinationFolder);
const args = IS_WINDOWS ? '-r -v -l ""' : ''; }
const name = path.join(p.dir, p.name); });
yield exec.exec(`"${path.join(javaBinPath, toolName)}"`, [ }
`${args} "${name}.pack" "${name}.jar"` // This method recursively finds all .pack files under fsPath and unpacks them with the unpack200 tool
]); function unpackJars(fsPath, javaBinPath) {
} return __awaiter(this, void 0, void 0, function* () {
} if (fs.existsSync(fsPath)) {
}); if (fs.lstatSync(fsPath).isDirectory()) {
} for (const file in fs.readdirSync(fsPath)) {
function unzipJavaDownload(repoRoot, fileEnding, destinationFolder, extension) { const curPath = path.join(fsPath, file);
return __awaiter(this, void 0, void 0, function* () { yield unpackJars(curPath, javaBinPath);
// Create the destination folder if it doesn't exist }
yield io.mkdirP(destinationFolder); }
const jdkFile = path.normalize(repoRoot); else if (path.extname(fsPath).toLowerCase() === '.pack') {
const stats = fs.statSync(jdkFile); // Unpack the pack file synchonously
if (stats.isFile()) { const p = path.parse(fsPath);
yield extractFiles(jdkFile, fileEnding, destinationFolder); const toolName = IS_WINDOWS ? 'unpack200.exe' : 'unpack200';
const jdkDirectory = path.join(destinationFolder, fs.readdirSync(destinationFolder)[0]); const args = IS_WINDOWS ? '-r -v -l ""' : '';
yield unpackJars(jdkDirectory, path.join(jdkDirectory, 'bin')); const name = path.join(p.dir, p.name);
return jdkDirectory; yield exec.exec(`"${path.join(javaBinPath, toolName)}"`, [
} `${args} "${name}.pack" "${name}.jar"`
else { ]);
throw new Error(`Jdk argument ${jdkFile} is not a file`); }
} }
}); });
} }
function getDownloadInfo(refs, version, javaPackage) { function unzipJavaDownload(repoRoot, fileEnding, destinationFolder, extension) {
version = normalizeVersion(version); return __awaiter(this, void 0, void 0, function* () {
let extension = ''; // Create the destination folder if it doesn't exist
if (IS_WINDOWS) { yield io.mkdirP(destinationFolder);
extension = `-win_x64.zip`; const jdkFile = path.normalize(repoRoot);
} const stats = fs.statSync(jdkFile);
else { if (stats.isFile()) {
if (process.platform === 'darwin') { yield extractFiles(jdkFile, fileEnding, destinationFolder);
extension = `-macosx_x64.tar.gz`; const jdkDirectory = path.join(destinationFolder, fs.readdirSync(destinationFolder)[0]);
} yield unpackJars(jdkDirectory, path.join(jdkDirectory, 'bin'));
else { return jdkDirectory;
extension = `-linux_x64.tar.gz`; }
} else {
} throw new Error(`Jdk argument ${jdkFile} is not a file`);
let pkgRegexp = new RegExp(''); }
let pkgTypeLength = 0; });
if (javaPackage === 'jdk') { }
pkgRegexp = /jdk.*-/gi; function getDownloadInfo(refs, version, javaPackage) {
pkgTypeLength = 'jdk'.length; version = normalizeVersion(version);
} let extension = '';
else if (javaPackage == 'jre') { if (IS_WINDOWS) {
pkgRegexp = /jre.*-/gi; extension = `-win_x64.zip`;
pkgTypeLength = 'jre'.length; }
} else {
else if (javaPackage == 'jdk+fx') { if (process.platform === 'darwin') {
pkgRegexp = /fx-jdk.*-/gi; extension = `-macosx_x64.tar.gz`;
pkgTypeLength = 'fx-jdk'.length; }
} else {
else { extension = `-linux_x64.tar.gz`;
throw new Error(`package argument ${javaPackage} is not in [jdk | jre | jdk+fx]`); }
} }
// Maps version to url let pkgRegexp = new RegExp('');
let versionMap = new Map(); let pkgTypeLength = 0;
// Filter by platform if (javaPackage === 'jdk') {
refs.forEach(ref => { pkgRegexp = /jdk.*-/gi;
if (!ref.endsWith(extension + '">')) { pkgTypeLength = 'jdk'.length;
return; }
} else if (javaPackage == 'jre') {
// If we haven't returned, means we're looking at the correct platform pkgRegexp = /jre.*-/gi;
let versions = ref.match(pkgRegexp) || []; pkgTypeLength = 'jre'.length;
if (versions.length > 1) { }
throw new Error(`Invalid ref received from https://static.azul.com/zulu/bin/: ${ref}`); else if (javaPackage == 'jdk+fx') {
} pkgRegexp = /fx-jdk.*-/gi;
if (versions.length == 0) { pkgTypeLength = 'fx-jdk'.length;
return; }
} else {
const refVersion = versions[0].slice(pkgTypeLength, versions[0].length - 1); throw new Error(`package argument ${javaPackage} is not in [jdk | jre | jdk+fx]`);
if (semver.satisfies(refVersion, version)) { }
versionMap.set(refVersion, 'https://static.azul.com/zulu/bin/' + // Maps version to url
ref.slice('<a href="'.length, ref.length - '">'.length)); let versionMap = new Map();
} // Filter by platform
}); refs.forEach(ref => {
// Choose the most recent satisfying version if (!ref.endsWith(extension + '">')) {
let curVersion = '0.0.0'; return;
let curUrl = ''; }
for (const entry of versionMap.entries()) { // If we haven't returned, means we're looking at the correct platform
const entryVersion = entry[0]; let versions = ref.match(pkgRegexp) || [];
const entryUrl = entry[1]; if (versions.length > 1) {
if (semver.gt(entryVersion, curVersion)) { throw new Error(`Invalid ref received from https://static.azul.com/zulu/bin/: ${ref}`);
curUrl = entryUrl; }
curVersion = entryVersion; if (versions.length == 0) {
} return;
} }
if (curUrl == '') { const refVersion = versions[0].slice(pkgTypeLength, versions[0].length - 1);
throw new Error(`No valid download found for version ${version} and package ${javaPackage}. Check https://static.azul.com/zulu/bin/ for a list of valid versions or download your own jdk file and add the jdkFile argument`); if (semver.satisfies(refVersion, version)) {
} versionMap.set(refVersion, 'https://static.azul.com/zulu/bin/' +
return { version: curVersion, url: curUrl }; ref.slice('<a href="'.length, ref.length - '">'.length));
} }
function normalizeVersion(version) { });
if (version.slice(0, 2) === '1.') { // Choose the most recent satisfying version
// Trim leading 1. for versions like 1.8 let curVersion = '0.0.0';
version = version.slice(2); let curUrl = '';
if (!version) { for (const entry of versionMap.entries()) {
throw new Error('1. is not a valid version'); const entryVersion = entry[0];
} const entryUrl = entry[1];
} if (semver.gt(entryVersion, curVersion)) {
if (version.endsWith('-ea')) { curUrl = entryUrl;
// convert e.g. 14-ea to 14.0.0-ea curVersion = entryVersion;
if (version.indexOf('.') == -1) { }
version = version.slice(0, version.length - 3) + '.0.0-ea'; }
} if (curUrl == '') {
// match anything in -ea.X (semver won't do .x matching on pre-release versions) throw new Error(`No valid download found for version ${version} and package ${javaPackage}. Check https://static.azul.com/zulu/bin/ for a list of valid versions or download your own jdk file and add the jdkFile argument`);
if (version[0] >= '0' && version[0] <= '9') { }
version = '>=' + version; return { version: curVersion, url: curUrl };
} }
} function normalizeVersion(version) {
else if (version.split('.').length < 3) { if (version.slice(0, 2) === '1.') {
// For non-ea versions, add trailing .x if it is missing // Trim leading 1. for versions like 1.8
if (version[version.length - 1] != 'x') { version = version.slice(2);
version = version + '.x'; if (!version) {
} throw new Error('1. is not a valid version');
} }
return version; }
} if (version.endsWith('-ea')) {
// convert e.g. 14-ea to 14.0.0-ea
if (version.indexOf('.') == -1) {
version = version.slice(0, version.length - 3) + '.0.0-ea';
}
// match anything in -ea.X (semver won't do .x matching on pre-release versions)
if (version[0] >= '0' && version[0] <= '9') {
version = '>=' + version;
}
}
else if (version.split('.').length < 3) {
// For non-ea versions, add trailing .x if it is missing
if (version[version.length - 1] != 'x') {
version = version + '.x';
}
}
return version;
}
/***/ }), /***/ }),

View file

@ -39,15 +39,28 @@ export async function getJava(
} else { } else {
let compressedFileExtension = ''; let compressedFileExtension = '';
if (!jdkFile) { if (!jdkFile) {
core.debug('Downloading Jdk from Azul'); core.debug('Downloading JDK from Azul');
let http: httpm.HttpClient = new httpm.HttpClient('setup-java'); const http = new httpm.HttpClient('setup-java', undefined, {
let contents = await ( allowRetries: true,
await http.get('https://static.azul.com/zulu/bin/') maxRetries: 3
).readBody(); });
let refs = contents.match(/<a href.*\">/gi) || []; const url = 'https://static.azul.com/zulu/bin/';
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 refs = contents.match(/<a href.*\">/gi) || [];
const downloadInfo = getDownloadInfo(refs, version, javaPackage); const downloadInfo = getDownloadInfo(refs, version, javaPackage);
jdkFile = await tc.downloadTool(downloadInfo.url); jdkFile = await tc.downloadTool(downloadInfo.url);
version = downloadInfo.version; version = downloadInfo.version;
compressedFileExtension = IS_WINDOWS ? '.zip' : '.tar.gz'; compressedFileExtension = IS_WINDOWS ? '.zip' : '.tar.gz';