Use cached Julia if available

This commit is contained in:
Sascha Mann
2019-08-17 17:50:15 +02:00
parent 58832d0813
commit a8a77e20fd
2 changed files with 74 additions and 43 deletions

View File

@@ -66,34 +66,49 @@ function getFileName(version) {
}
return `julia-${version}${versionExt}.${ext}`;
}
function installJulia(version) {
return __awaiter(this, void 0, void 0, function* () {
// Download Julia
const downloadURL = getDownloadURL(version);
core.debug(`downloading Julia from ${downloadURL}`);
const juliaDownloadPath = yield tc.downloadTool(downloadURL);
// Install it
switch (osPlat) {
case 'linux':
const juliaExtractedFolder = yield tc.extractTar(juliaDownloadPath);
return path.join(juliaExtractedFolder, `julia-${version}`);
case 'win32':
const juliaInstallationPath = path.join('C:', 'Julia');
yield exec.exec('powershell', ['-Command', `Start-Process -FilePath ${juliaDownloadPath} -ArgumentList "/S /D=${juliaInstallationPath}" -NoNewWindow -Wait`]);
return juliaInstallationPath;
case 'darwin':
yield exec.exec('hdiutil', ['attach', juliaDownloadPath]);
return `/Volumes/Julia-${version}/Julia-${getMajorMinorVersion(version)}.app/Contents/Resources/julia`;
default:
throw `Platform ${osPlat} is not supported`;
}
});
}
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
const version = core.getInput('version');
core.debug(`selected Julia version: ${version}`);
// Download Julia
const downloadURL = getDownloadURL(version);
core.debug(`download Julia from ${downloadURL}`);
const juliaDownloadPath = yield tc.downloadTool(downloadURL);
// Install Julia
if (osPlat === 'linux') { // Linux
const juliaExtractedFolder = yield tc.extractTar(juliaDownloadPath);
const juliaCachedPath = yield tc.cacheDir(juliaExtractedFolder, 'julia', version);
const juliaPath = path.join(juliaCachedPath, `julia-${version}`);
core.addPath(path.join(juliaPath, 'bin'));
// Search in cache
let juliaPath;
juliaPath = tc.find('julia', version);
if (!juliaPath) {
core.debug(`could not find Julia ${version} in cache`);
const juliaInstallationPath = yield installJulia(version);
// Add it to cache
juliaPath = yield tc.cacheDir(juliaInstallationPath, 'julia', version);
core.debug(`added Julia to cache: ${juliaPath}`);
}
else if (osPlat === 'win32') { // Windows
// Install Julia in C:\Julia
const juliaInstallationPath = path.join('C:', 'Julia');
yield exec.exec('powershell', ['-Command', `Start-Process -FilePath ${juliaDownloadPath} -ArgumentList "/S /D=${juliaInstallationPath}" -NoNewWindow -Wait`]);
const juliaCachedPath = yield tc.cacheDir(juliaInstallationPath, 'julia', version);
core.addPath(path.join(juliaCachedPath, 'bin'));
}
else if (osPlat === 'darwin') { // macOS
yield exec.exec('hdiutil', ['attach', juliaDownloadPath]);
const juliaCachedPath = yield tc.cacheDir(`/Volumes/Julia-${version}/Julia-${getMajorMinorVersion(version)}.app/Contents/Resources/julia`, 'julia', version);
core.addPath(path.join(juliaCachedPath, 'bin'));
else {
core.debug(`using cached version of Julia: ${juliaPath}`);
}
// Add it to PATH
core.addPath(path.join(juliaPath, 'bin'));
// Test if Julia has been installed by showing versioninfo()
yield exec.exec('julia', ['-e', 'using InteractiveUtils; versioninfo()']);
}