Support build matrices and non-Linux OS

This commit is contained in:
Sascha Mann
2019-08-13 14:52:06 +02:00
parent f8e69caa03
commit 371167db47
2 changed files with 142 additions and 22 deletions

View File

@@ -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) {

View File

@@ -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)