From a8a77e20fd973678d394816bf98c7b8deb4993d2 Mon Sep 17 00:00:00 2001 From: Sascha Mann Date: Sat, 17 Aug 2019 17:50:15 +0200 Subject: [PATCH] Use cached Julia if available --- lib/setup-julia.js | 57 +++++++++++++++++++++++++++---------------- src/setup-julia.ts | 60 +++++++++++++++++++++++++++++----------------- 2 files changed, 74 insertions(+), 43 deletions(-) diff --git a/lib/setup-julia.js b/lib/setup-julia.js index e0c94cb..52a24fa 100644 --- a/lib/setup-julia.js +++ b/lib/setup-julia.js @@ -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()']); } diff --git a/src/setup-julia.ts b/src/setup-julia.ts index a45a1b2..5436d3c 100644 --- a/src/setup-julia.ts +++ b/src/setup-julia.ts @@ -53,36 +53,52 @@ function getFileName(version: string): string { return `julia-${version}${versionExt}.${ext}` } +async function installJulia(version: string): Promise { + // Download Julia + const downloadURL = getDownloadURL(version) + core.debug(`downloading Julia from ${downloadURL}`) + const juliaDownloadPath = await tc.downloadTool(downloadURL) + + // Install it + switch (osPlat) { + case 'linux': + const juliaExtractedFolder = await tc.extractTar(juliaDownloadPath) + return path.join(juliaExtractedFolder, `julia-${version}`) + case 'win32': + const juliaInstallationPath = path.join('C:', 'Julia') + await exec.exec('powershell', ['-Command', `Start-Process -FilePath ${juliaDownloadPath} -ArgumentList "/S /D=${juliaInstallationPath}" -NoNewWindow -Wait`]) + return juliaInstallationPath + case 'darwin': + await exec.exec('hdiutil', ['attach', juliaDownloadPath]) + return `/Volumes/Julia-${version}/Julia-${getMajorMinorVersion(version)}.app/Contents/Resources/julia` + default: + throw `Platform ${osPlat} is not supported` + } +} + async function run() { 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 = await tc.downloadTool(downloadURL) + // Search in cache + let juliaPath: string; + juliaPath = tc.find('julia', version) - // Install Julia - if (osPlat === 'linux') { // Linux - const juliaExtractedFolder = await tc.extractTar(juliaDownloadPath) - const juliaCachedPath = await tc.cacheDir(juliaExtractedFolder, 'julia', version) - const juliaPath = path.join(juliaCachedPath, `julia-${version}`) - core.addPath(path.join(juliaPath, 'bin')) - - } else if (osPlat === 'win32') { // Windows - // Install Julia in C:\Julia - const juliaInstallationPath = path.join('C:', 'Julia') - await exec.exec('powershell', ['-Command', `Start-Process -FilePath ${juliaDownloadPath} -ArgumentList "/S /D=${juliaInstallationPath}" -NoNewWindow -Wait`]) - const juliaCachedPath = await tc.cacheDir(juliaInstallationPath, 'julia', version) - core.addPath(path.join(juliaCachedPath, 'bin')) - - } else if (osPlat === 'darwin') { // macOS - await exec.exec('hdiutil', ['attach', juliaDownloadPath]) - const juliaCachedPath = await tc.cacheDir(`/Volumes/Julia-${version}/Julia-${getMajorMinorVersion(version)}.app/Contents/Resources/julia`, 'julia', version) - core.addPath(path.join(juliaCachedPath, 'bin')) + if (!juliaPath) { + core.debug(`could not find Julia ${version} in cache`) + const juliaInstallationPath = await installJulia(version); + + // Add it to cache + juliaPath = await tc.cacheDir(juliaInstallationPath, 'julia', version) + core.debug(`added Julia to cache: ${juliaPath}`) + } 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() await exec.exec('julia', ['-e', 'using InteractiveUtils; versioninfo()']) } catch (error) {