mirror of
https://github.com/julia-actions/setup-julia.git
synced 2026-02-12 02:56:54 +08:00
Move functions to separate file for easier unit testing
This commit is contained in:
143
lib/installer.js
generated
Normal file
143
lib/installer.js
generated
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
"use strict";
|
||||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
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 step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
|
if (mod && mod.__esModule) return mod;
|
||||||
|
var result = {};
|
||||||
|
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||||
|
result["default"] = mod;
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const core = __importStar(require("@actions/core"));
|
||||||
|
const exec = __importStar(require("@actions/exec"));
|
||||||
|
const tc = __importStar(require("@actions/tool-cache"));
|
||||||
|
const https = __importStar(require("https"));
|
||||||
|
const os = __importStar(require("os"));
|
||||||
|
const path = __importStar(require("path"));
|
||||||
|
const semver = __importStar(require("semver"));
|
||||||
|
// Store information about the environment
|
||||||
|
const osPlat = os.platform(); // possible values: win32 (Windows), linux (Linux), darwin (macOS)
|
||||||
|
core.debug(`platform: ${osPlat}`);
|
||||||
|
function getJuliaReleases() {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
// Wrap everything in a Promise so that it can be called with await.
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const options = {
|
||||||
|
hostname: 'api.github.com',
|
||||||
|
path: '/repos/julialang/julia/releases?per_page=100',
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/vnd.github.v3+json',
|
||||||
|
'User-Agent': `${process.env.GITHUB_ACTION} Action running in ${process.env.GITHUB_REPOSITORY}`
|
||||||
|
}
|
||||||
|
};
|
||||||
|
https.request(options, res => {
|
||||||
|
let data = '';
|
||||||
|
res.on('data', d => {
|
||||||
|
data += d;
|
||||||
|
});
|
||||||
|
res.on('end', () => {
|
||||||
|
core.debug(data);
|
||||||
|
resolve(JSON.parse(data).map((r) => r.tag_name));
|
||||||
|
});
|
||||||
|
}).on('error', err => {
|
||||||
|
reject(new Error(`Error while requesting Julia versions from GitHub:\n${err}`));
|
||||||
|
}).end();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function getJuliaVersion(versionInput) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
if (semver.valid(versionInput) == versionInput) {
|
||||||
|
// versionInput is a valid version, use it directly
|
||||||
|
return versionInput;
|
||||||
|
}
|
||||||
|
// Use the highest available version that matches versionInput
|
||||||
|
const releases = yield getJuliaReleases();
|
||||||
|
let version = semver.maxSatisfying(releases, versionInput);
|
||||||
|
if (version == null) {
|
||||||
|
throw `Could not find a Julia version that matches ${versionInput}`;
|
||||||
|
}
|
||||||
|
// GitHub tags start with v, remove it
|
||||||
|
version = version.replace(/^v/, '');
|
||||||
|
return version;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.getJuliaVersion = getJuliaVersion;
|
||||||
|
function getMajorMinorVersion(version) {
|
||||||
|
return version.split('.').slice(0, 2).join('.');
|
||||||
|
}
|
||||||
|
function getDownloadURL(version, arch) {
|
||||||
|
const baseURL = 'https://julialang-s3.julialang.org/bin';
|
||||||
|
let platform;
|
||||||
|
const versionDir = getMajorMinorVersion(version);
|
||||||
|
if (osPlat === 'win32') { // Windows
|
||||||
|
platform = 'winnt';
|
||||||
|
}
|
||||||
|
else if (osPlat === 'darwin') { // macOS
|
||||||
|
if (arch == 'x86') {
|
||||||
|
throw '32-bit Julia is not available on macOS';
|
||||||
|
}
|
||||||
|
platform = 'mac';
|
||||||
|
}
|
||||||
|
else if (osPlat === 'linux') { // Linux
|
||||||
|
platform = 'linux';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw `Platform ${osPlat} is not supported`;
|
||||||
|
}
|
||||||
|
return `${baseURL}/${platform}/${arch}/${versionDir}/${getFileName(version, arch)}`;
|
||||||
|
}
|
||||||
|
function getFileName(version, arch) {
|
||||||
|
let versionExt, ext;
|
||||||
|
if (osPlat === 'win32') { // Windows
|
||||||
|
versionExt = arch == 'x64' ? '-win64' : '-win32';
|
||||||
|
ext = 'exe';
|
||||||
|
}
|
||||||
|
else if (osPlat === 'darwin') { // macOS
|
||||||
|
if (arch == 'x86') {
|
||||||
|
throw '32-bit Julia is not available on macOS';
|
||||||
|
}
|
||||||
|
versionExt = '-mac64';
|
||||||
|
ext = 'dmg';
|
||||||
|
}
|
||||||
|
else if (osPlat === 'linux') { // Linux
|
||||||
|
versionExt = arch == 'x64' ? '-linux-x86_64' : '-linux-i686';
|
||||||
|
ext = 'tar.gz';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw `Platform ${osPlat} is not supported`;
|
||||||
|
}
|
||||||
|
return `julia-${version}${versionExt}.${ext}`;
|
||||||
|
}
|
||||||
|
function installJulia(version, arch) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
// Download Julia
|
||||||
|
const downloadURL = getDownloadURL(version, arch);
|
||||||
|
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`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.installJulia = installJulia;
|
||||||
125
lib/setup-julia.js
generated
125
lib/setup-julia.js
generated
@@ -18,140 +18,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||||||
const core = __importStar(require("@actions/core"));
|
const core = __importStar(require("@actions/core"));
|
||||||
const exec = __importStar(require("@actions/exec"));
|
const exec = __importStar(require("@actions/exec"));
|
||||||
const tc = __importStar(require("@actions/tool-cache"));
|
const tc = __importStar(require("@actions/tool-cache"));
|
||||||
const https = __importStar(require("https"));
|
|
||||||
const os = __importStar(require("os"));
|
|
||||||
const path = __importStar(require("path"));
|
const path = __importStar(require("path"));
|
||||||
const semver = __importStar(require("semver"));
|
const installer = __importStar(require("./installer"));
|
||||||
// Store information about the environment
|
|
||||||
const osPlat = os.platform(); // possible values: win32 (Windows), linux (Linux), darwin (macOS)
|
|
||||||
core.debug(`platform: ${osPlat}`);
|
|
||||||
function getJuliaReleases() {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
// Wrap everything in a Promise so that it can be called with await.
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const options = {
|
|
||||||
hostname: 'api.github.com',
|
|
||||||
path: '/repos/julialang/julia/releases?per_page=100',
|
|
||||||
method: 'GET',
|
|
||||||
headers: {
|
|
||||||
'Accept': 'application/vnd.github.v3+json',
|
|
||||||
'User-Agent': `${process.env.GITHUB_ACTION} Action running in ${process.env.GITHUB_REPOSITORY}`
|
|
||||||
}
|
|
||||||
};
|
|
||||||
https.request(options, res => {
|
|
||||||
let data = '';
|
|
||||||
res.on('data', d => {
|
|
||||||
data += d;
|
|
||||||
});
|
|
||||||
res.on('end', () => {
|
|
||||||
core.debug(data);
|
|
||||||
resolve(JSON.parse(data).map((r) => r.tag_name));
|
|
||||||
});
|
|
||||||
}).on('error', err => {
|
|
||||||
reject(new Error(`Error while requesting Julia versions from GitHub:\n${err}`));
|
|
||||||
}).end();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
function getJuliaVersion(versionInput) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
if (semver.valid(versionInput) == versionInput) {
|
|
||||||
// versionInput is a valid version, use it directly
|
|
||||||
return versionInput;
|
|
||||||
}
|
|
||||||
// Use the highest available version that matches versionInput
|
|
||||||
const releases = yield getJuliaReleases();
|
|
||||||
let version = semver.maxSatisfying(releases, versionInput);
|
|
||||||
if (version == null) {
|
|
||||||
throw `Could not find a Julia version that matches ${versionInput}`;
|
|
||||||
}
|
|
||||||
// GitHub tags start with v, remove it
|
|
||||||
version = version.replace(/^v/, '');
|
|
||||||
return version;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
function getMajorMinorVersion(version) {
|
|
||||||
return version.split('.').slice(0, 2).join('.');
|
|
||||||
}
|
|
||||||
function getDownloadURL(version, arch) {
|
|
||||||
const baseURL = 'https://julialang-s3.julialang.org/bin';
|
|
||||||
let platform;
|
|
||||||
const versionDir = getMajorMinorVersion(version);
|
|
||||||
if (osPlat === 'win32') { // Windows
|
|
||||||
platform = 'winnt';
|
|
||||||
}
|
|
||||||
else if (osPlat === 'darwin') { // macOS
|
|
||||||
if (arch == 'x86') {
|
|
||||||
throw '32-bit Julia is not available on macOS';
|
|
||||||
}
|
|
||||||
platform = 'mac';
|
|
||||||
}
|
|
||||||
else if (osPlat === 'linux') { // Linux
|
|
||||||
platform = 'linux';
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw `Platform ${osPlat} is not supported`;
|
|
||||||
}
|
|
||||||
return `${baseURL}/${platform}/${arch}/${versionDir}/${getFileName(version, arch)}`;
|
|
||||||
}
|
|
||||||
function getFileName(version, arch) {
|
|
||||||
let versionExt, ext;
|
|
||||||
if (osPlat === 'win32') { // Windows
|
|
||||||
versionExt = arch == 'x64' ? '-win64' : '-win32';
|
|
||||||
ext = 'exe';
|
|
||||||
}
|
|
||||||
else if (osPlat === 'darwin') { // macOS
|
|
||||||
if (arch == 'x86') {
|
|
||||||
throw '32-bit Julia is not available on macOS';
|
|
||||||
}
|
|
||||||
versionExt = '-mac64';
|
|
||||||
ext = 'dmg';
|
|
||||||
}
|
|
||||||
else if (osPlat === 'linux') { // Linux
|
|
||||||
versionExt = arch == 'x64' ? '-linux-x86_64' : '-linux-i686';
|
|
||||||
ext = 'tar.gz';
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw `Platform ${osPlat} is not supported`;
|
|
||||||
}
|
|
||||||
return `julia-${version}${versionExt}.${ext}`;
|
|
||||||
}
|
|
||||||
function installJulia(version, arch) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
// Download Julia
|
|
||||||
const downloadURL = getDownloadURL(version, arch);
|
|
||||||
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() {
|
function run() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
const versionInput = core.getInput('version');
|
const versionInput = core.getInput('version');
|
||||||
const arch = core.getInput('arch');
|
const arch = core.getInput('arch');
|
||||||
const version = yield getJuliaVersion(versionInput);
|
const version = yield installer.getJuliaVersion(versionInput);
|
||||||
core.debug(`selected Julia version: ${arch}/${version}`);
|
core.debug(`selected Julia version: ${arch}/${version}`);
|
||||||
// Search in cache
|
// Search in cache
|
||||||
let juliaPath;
|
let juliaPath;
|
||||||
juliaPath = tc.find('julia', version, arch);
|
juliaPath = tc.find('julia', version, arch);
|
||||||
if (!juliaPath) {
|
if (!juliaPath) {
|
||||||
core.debug(`could not find Julia ${version} in cache`);
|
core.debug(`could not find Julia ${version} in cache`);
|
||||||
const juliaInstallationPath = yield installJulia(version, arch);
|
const juliaInstallationPath = yield installer.installJulia(version, arch);
|
||||||
// Add it to cache
|
// Add it to cache
|
||||||
juliaPath = yield tc.cacheDir(juliaInstallationPath, 'julia', version, arch);
|
juliaPath = yield tc.cacheDir(juliaInstallationPath, 'julia', version, arch);
|
||||||
core.debug(`added Julia to cache: ${juliaPath}`);
|
core.debug(`added Julia to cache: ${juliaPath}`);
|
||||||
|
|||||||
132
src/installer.ts
Normal file
132
src/installer.ts
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
import * as core from '@actions/core'
|
||||||
|
import * as exec from '@actions/exec'
|
||||||
|
import * as tc from '@actions/tool-cache'
|
||||||
|
|
||||||
|
import * as https from 'https'
|
||||||
|
import * as os from 'os'
|
||||||
|
import * as path from 'path'
|
||||||
|
|
||||||
|
import * as semver from 'semver'
|
||||||
|
|
||||||
|
// Store information about the environment
|
||||||
|
const osPlat = os.platform() // possible values: win32 (Windows), linux (Linux), darwin (macOS)
|
||||||
|
core.debug(`platform: ${osPlat}`)
|
||||||
|
|
||||||
|
async function getJuliaReleases(): Promise<string[]> {
|
||||||
|
// Wrap everything in a Promise so that it can be called with await.
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const options = {
|
||||||
|
hostname: 'api.github.com',
|
||||||
|
path: '/repos/julialang/julia/releases?per_page=100',
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/vnd.github.v3+json', // locks GitHub API version to v3
|
||||||
|
'User-Agent': `${process.env.GITHUB_ACTION} Action running in ${process.env.GITHUB_REPOSITORY}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
https.request(options, res => {
|
||||||
|
let data = ''
|
||||||
|
|
||||||
|
res.on('data', d => {
|
||||||
|
data += d
|
||||||
|
})
|
||||||
|
|
||||||
|
res.on('end', () => {
|
||||||
|
core.debug(data)
|
||||||
|
resolve(JSON.parse(data).map((r) => r.tag_name as string))
|
||||||
|
})
|
||||||
|
}).on('error', err => {
|
||||||
|
reject(new Error(`Error while requesting Julia versions from GitHub:\n${err}`))
|
||||||
|
}).end()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getJuliaVersion(versionInput: string): Promise<string> {
|
||||||
|
if (semver.valid(versionInput) == versionInput) {
|
||||||
|
// versionInput is a valid version, use it directly
|
||||||
|
return versionInput
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use the highest available version that matches versionInput
|
||||||
|
const releases = await getJuliaReleases()
|
||||||
|
let version = semver.maxSatisfying(releases, versionInput)
|
||||||
|
if (version == null) {
|
||||||
|
throw `Could not find a Julia version that matches ${versionInput}`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GitHub tags start with v, remove it
|
||||||
|
version = version.replace(/^v/, '')
|
||||||
|
|
||||||
|
return version
|
||||||
|
}
|
||||||
|
|
||||||
|
function getMajorMinorVersion(version: string): string {
|
||||||
|
return version.split('.').slice(0, 2).join('.')
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDownloadURL(version: string, arch: string): string {
|
||||||
|
const baseURL = 'https://julialang-s3.julialang.org/bin'
|
||||||
|
let platform: string
|
||||||
|
const versionDir = getMajorMinorVersion(version)
|
||||||
|
|
||||||
|
if (osPlat === 'win32') { // Windows
|
||||||
|
platform = 'winnt'
|
||||||
|
} else if (osPlat === 'darwin') { // macOS
|
||||||
|
if (arch == 'x86') {
|
||||||
|
throw '32-bit Julia is not available on macOS'
|
||||||
|
}
|
||||||
|
platform = 'mac'
|
||||||
|
} else if (osPlat === 'linux') { // Linux
|
||||||
|
platform = 'linux'
|
||||||
|
} else {
|
||||||
|
throw `Platform ${osPlat} is not supported`
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${baseURL}/${platform}/${arch}/${versionDir}/${getFileName(version, arch)}`
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFileName(version: string, arch: string): string {
|
||||||
|
let versionExt: string, ext: string
|
||||||
|
|
||||||
|
if (osPlat === 'win32') { // Windows
|
||||||
|
versionExt = arch == 'x64' ? '-win64' : '-win32'
|
||||||
|
ext = 'exe'
|
||||||
|
} else if (osPlat === 'darwin') { // macOS
|
||||||
|
if (arch == 'x86') {
|
||||||
|
throw '32-bit Julia is not available on macOS'
|
||||||
|
}
|
||||||
|
versionExt = '-mac64'
|
||||||
|
ext = 'dmg'
|
||||||
|
} else if (osPlat === 'linux') { // Linux
|
||||||
|
versionExt = arch == 'x64' ? '-linux-x86_64' : '-linux-i686'
|
||||||
|
ext = 'tar.gz'
|
||||||
|
} else {
|
||||||
|
throw `Platform ${osPlat} is not supported`
|
||||||
|
}
|
||||||
|
|
||||||
|
return `julia-${version}${versionExt}.${ext}`
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function installJulia(version: string, arch: string): Promise<string> {
|
||||||
|
// Download Julia
|
||||||
|
const downloadURL = getDownloadURL(version, arch)
|
||||||
|
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`
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,140 +2,15 @@ import * as core from '@actions/core'
|
|||||||
import * as exec from '@actions/exec'
|
import * as exec from '@actions/exec'
|
||||||
import * as tc from '@actions/tool-cache'
|
import * as tc from '@actions/tool-cache'
|
||||||
|
|
||||||
import * as https from 'https'
|
|
||||||
import * as os from 'os'
|
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
|
|
||||||
import * as semver from 'semver'
|
import * as installer from './installer'
|
||||||
|
|
||||||
// Store information about the environment
|
|
||||||
const osPlat = os.platform() // possible values: win32 (Windows), linux (Linux), darwin (macOS)
|
|
||||||
core.debug(`platform: ${osPlat}`)
|
|
||||||
|
|
||||||
async function getJuliaReleases(): Promise<string[]> {
|
|
||||||
// Wrap everything in a Promise so that it can be called with await.
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const options = {
|
|
||||||
hostname: 'api.github.com',
|
|
||||||
path: '/repos/julialang/julia/releases?per_page=100',
|
|
||||||
method: 'GET',
|
|
||||||
headers: {
|
|
||||||
'Accept': 'application/vnd.github.v3+json', // locks GitHub API version to v3
|
|
||||||
'User-Agent': `${process.env.GITHUB_ACTION} Action running in ${process.env.GITHUB_REPOSITORY}`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
https.request(options, res => {
|
|
||||||
let data = ''
|
|
||||||
|
|
||||||
res.on('data', d => {
|
|
||||||
data += d
|
|
||||||
})
|
|
||||||
|
|
||||||
res.on('end', () => {
|
|
||||||
core.debug(data)
|
|
||||||
resolve(JSON.parse(data).map((r) => r.tag_name as string))
|
|
||||||
})
|
|
||||||
}).on('error', err => {
|
|
||||||
reject(new Error(`Error while requesting Julia versions from GitHub:\n${err}`))
|
|
||||||
}).end()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getJuliaVersion(versionInput: string): Promise<string> {
|
|
||||||
if (semver.valid(versionInput) == versionInput) {
|
|
||||||
// versionInput is a valid version, use it directly
|
|
||||||
return versionInput
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use the highest available version that matches versionInput
|
|
||||||
const releases = await getJuliaReleases()
|
|
||||||
let version = semver.maxSatisfying(releases, versionInput)
|
|
||||||
if (version == null) {
|
|
||||||
throw `Could not find a Julia version that matches ${versionInput}`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GitHub tags start with v, remove it
|
|
||||||
version = version.replace(/^v/, '')
|
|
||||||
|
|
||||||
return version
|
|
||||||
}
|
|
||||||
|
|
||||||
function getMajorMinorVersion(version: string): string {
|
|
||||||
return version.split('.').slice(0, 2).join('.')
|
|
||||||
}
|
|
||||||
|
|
||||||
function getDownloadURL(version: string, arch: string): string {
|
|
||||||
const baseURL = 'https://julialang-s3.julialang.org/bin'
|
|
||||||
let platform: string
|
|
||||||
const versionDir = getMajorMinorVersion(version)
|
|
||||||
|
|
||||||
if (osPlat === 'win32') { // Windows
|
|
||||||
platform = 'winnt'
|
|
||||||
} else if (osPlat === 'darwin') { // macOS
|
|
||||||
if (arch == 'x86') {
|
|
||||||
throw '32-bit Julia is not available on macOS'
|
|
||||||
}
|
|
||||||
platform = 'mac'
|
|
||||||
} else if (osPlat === 'linux') { // Linux
|
|
||||||
platform = 'linux'
|
|
||||||
} else {
|
|
||||||
throw `Platform ${osPlat} is not supported`
|
|
||||||
}
|
|
||||||
|
|
||||||
return `${baseURL}/${platform}/${arch}/${versionDir}/${getFileName(version, arch)}`
|
|
||||||
}
|
|
||||||
|
|
||||||
function getFileName(version: string, arch: string): string {
|
|
||||||
let versionExt: string, ext: string
|
|
||||||
|
|
||||||
if (osPlat === 'win32') { // Windows
|
|
||||||
versionExt = arch == 'x64' ? '-win64' : '-win32'
|
|
||||||
ext = 'exe'
|
|
||||||
} else if (osPlat === 'darwin') { // macOS
|
|
||||||
if (arch == 'x86') {
|
|
||||||
throw '32-bit Julia is not available on macOS'
|
|
||||||
}
|
|
||||||
versionExt = '-mac64'
|
|
||||||
ext = 'dmg'
|
|
||||||
} else if (osPlat === 'linux') { // Linux
|
|
||||||
versionExt = arch == 'x64' ? '-linux-x86_64' : '-linux-i686'
|
|
||||||
ext = 'tar.gz'
|
|
||||||
} else {
|
|
||||||
throw `Platform ${osPlat} is not supported`
|
|
||||||
}
|
|
||||||
|
|
||||||
return `julia-${version}${versionExt}.${ext}`
|
|
||||||
}
|
|
||||||
|
|
||||||
async function installJulia(version: string, arch: string): Promise<string> {
|
|
||||||
// Download Julia
|
|
||||||
const downloadURL = getDownloadURL(version, arch)
|
|
||||||
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() {
|
async function run() {
|
||||||
try {
|
try {
|
||||||
const versionInput = core.getInput('version')
|
const versionInput = core.getInput('version')
|
||||||
const arch = core.getInput('arch')
|
const arch = core.getInput('arch')
|
||||||
const version = await getJuliaVersion(versionInput)
|
const version = await installer.getJuliaVersion(versionInput)
|
||||||
core.debug(`selected Julia version: ${arch}/${version}`)
|
core.debug(`selected Julia version: ${arch}/${version}`)
|
||||||
|
|
||||||
// Search in cache
|
// Search in cache
|
||||||
@@ -144,7 +19,7 @@ async function run() {
|
|||||||
|
|
||||||
if (!juliaPath) {
|
if (!juliaPath) {
|
||||||
core.debug(`could not find Julia ${version} in cache`)
|
core.debug(`could not find Julia ${version} in cache`)
|
||||||
const juliaInstallationPath = await installJulia(version, arch);
|
const juliaInstallationPath = await installer.installJulia(version, arch);
|
||||||
|
|
||||||
// Add it to cache
|
// Add it to cache
|
||||||
juliaPath = await tc.cacheDir(juliaInstallationPath, 'julia', version, arch)
|
juliaPath = await tc.cacheDir(juliaInstallationPath, 'julia', version, arch)
|
||||||
|
|||||||
Reference in New Issue
Block a user