From 371167db47946d5fd08de0ded5191b47f241116f Mon Sep 17 00:00:00 2001 From: Sascha Mann Date: Tue, 13 Aug 2019 14:52:06 +0200 Subject: [PATCH] Support build matrices and non-Linux OS --- lib/setup-julia.js | 80 +++++++++++++++++++++++++++++++++++++------ src/setup-julia.ts | 84 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 142 insertions(+), 22 deletions(-) diff --git a/lib/setup-julia.js b/lib/setup-julia.js index 7871af9..1bb81cb 100644 --- a/lib/setup-julia.js +++ b/lib/setup-julia.js @@ -20,21 +20,81 @@ const exec = __importStar(require("@actions/exec")); const tc = __importStar(require("@actions/tool-cache")); const os = __importStar(require("os")); const path = __importStar(require("path")); +// Store information about the environment +const osPlat = os.platform(); // possible values: win32 (Windows), linux (Linux), darwin (macOS) +console.log(`[DEBUG] platform: ${osPlat}`); +function getMajorMinorVersion(version) { + return version.split('.').slice(0, 2).join('.'); +} +function getDownloadURL(version) { + const baseURL = 'https://julialang-s3.julialang.org/bin'; + let platform, arch; + const versionDir = getMajorMinorVersion(version); + if (osPlat === 'win32') { // Windows + platform = 'winnt'; + arch = 'x64'; + } + else if (osPlat === 'darwin') { // macOS + platform = 'mac'; + arch = 'x64'; + } + else if (osPlat === 'linux') { // Linux + platform = 'linux'; + arch = 'x64'; + } + else { + throw `Platform ${osPlat} is not supported`; + } + return `${baseURL}/${platform}/${arch}/${versionDir}/${getFileName(version)}`; +} +function getFileName(version) { + let versionExt, ext; + if (osPlat === 'win32') { // Windows + versionExt = '-win64'; + ext = 'exe'; + } + else if (osPlat === 'darwin') { // macOS + versionExt = '-mac64'; + ext = 'dmg'; + } + else if (osPlat === 'linux') { // Linux + versionExt = '-linux-x86_64'; + ext = 'tar.gz'; + } + else { + throw `Platform ${osPlat} is not supported`; + } + return `julia-${version}${versionExt}.${ext}`; +} function run() { return __awaiter(this, void 0, void 0, function* () { try { const version = core.getInput('version'); console.log(`[DEBUG] selected Julia version: ${version}`); - // Store information about the environment - const osPlat = os.platform(); - const osArch = os.arch(); - // For now, just download Linux x64 binaries and add it to PATH - const juliaDownloadPath = yield tc.downloadTool('https://julialang-s3.julialang.org/bin/linux/x64/1.0/julia-1.0.4-linux-x86_64.tar.gz'); - const juliaExtractedFolder = yield tc.extractTar(juliaDownloadPath); - const juliaCachedPath = yield tc.cacheDir(juliaExtractedFolder, 'julia', '1.0.4', 'x64'); - const juliaPath = path.join(juliaCachedPath, 'julia-1.0.4'); - core.addPath(path.join(juliaPath, 'bin')); - // Test if it worked + // Download Julia + const downloadURL = getDownloadURL(version); + console.log(`[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')); + } + 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')); + } + // Test if Julia has been installed by showing versioninfo() yield exec.exec('julia', ['-e', 'using InteractiveUtils; versioninfo()']); } catch (error) { diff --git a/src/setup-julia.ts b/src/setup-julia.ts index 8124342..e25c974 100644 --- a/src/setup-julia.ts +++ b/src/setup-julia.ts @@ -5,25 +5,85 @@ import * as tc from '@actions/tool-cache' import * as os from 'os' import * as path from 'path' +// Store information about the environment +const osPlat = os.platform() // possible values: win32 (Windows), linux (Linux), darwin (macOS) +console.log(`[DEBUG] platform: ${osPlat}`) + +function getMajorMinorVersion(version: string): string { + return version.split('.').slice(0, 2).join('.') +} + +function getDownloadURL(version: string): string { + const baseURL = 'https://julialang-s3.julialang.org/bin' + let platform: string, arch: string + const versionDir = getMajorMinorVersion(version) + + if (osPlat === 'win32') { // Windows + platform = 'winnt' + arch = 'x64' + } else if (osPlat === 'darwin') { // macOS + platform = 'mac' + arch = 'x64' + } else if (osPlat === 'linux') { // Linux + platform = 'linux' + arch = 'x64' + } else { + throw `Platform ${osPlat} is not supported` + } + + return `${baseURL}/${platform}/${arch}/${versionDir}/${getFileName(version)}` +} + +function getFileName(version: string): string { + let versionExt: string, ext: string + + if (osPlat === 'win32') { // Windows + versionExt = '-win64' + ext = 'exe' + } else if (osPlat === 'darwin') { // macOS + versionExt = '-mac64' + ext = 'dmg' + } else if (osPlat === 'linux') { // Linux + versionExt = '-linux-x86_64' + ext = 'tar.gz' + } else { + throw `Platform ${osPlat} is not supported` + } + + return `julia-${version}${versionExt}.${ext}` +} + async function run() { try { const version = core.getInput('version') console.log(`[DEBUG] selected Julia version: ${version}`) - // Store information about the environment - const osPlat = os.platform() - const osArch = os.arch() + // Download Julia + const downloadURL = getDownloadURL(version) + console.log(`[DEBUG] download Julia from ${downloadURL}`) + const juliaDownloadPath = await tc.downloadTool(downloadURL) - // For now, just download Linux x64 binaries and add it to PATH - const juliaDownloadPath = await tc.downloadTool( - 'https://julialang-s3.julialang.org/bin/linux/x64/1.0/julia-1.0.4-linux-x86_64.tar.gz' - ) - const juliaExtractedFolder = await tc.extractTar(juliaDownloadPath) - const juliaCachedPath = await tc.cacheDir(juliaExtractedFolder, 'julia', '1.0.4', 'x64') - const juliaPath = path.join(juliaCachedPath, 'julia-1.0.4') - core.addPath(path.join(juliaPath, 'bin')) + // 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')) + } - // Test if it worked + // Test if Julia has been installed by showing versioninfo() await exec.exec('julia', ['-e', 'using InteractiveUtils; versioninfo()']) } catch (error) { core.setFailed(error.message)