mirror of
https://github.com/julia-actions/setup-julia.git
synced 2026-02-12 11:06:53 +08:00
Support version ranges as input version
This commit is contained in:
47
lib/setup-julia.js
generated
47
lib/setup-julia.js
generated
@@ -18,11 +18,55 @@ 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 os = __importStar(require("os"));
|
||||||
const path = __importStar(require("path"));
|
const path = __importStar(require("path"));
|
||||||
|
const semver = __importStar(require("semver"));
|
||||||
// Store information about the environment
|
// Store information about the environment
|
||||||
const osPlat = os.platform(); // possible values: win32 (Windows), linux (Linux), darwin (macOS)
|
const osPlat = os.platform(); // possible values: win32 (Windows), linux (Linux), darwin (macOS)
|
||||||
core.debug(`platform: ${osPlat}`);
|
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', () => {
|
||||||
|
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();
|
||||||
|
const version = semver.maxSatisfying(releases, versionInput);
|
||||||
|
if (version == null) {
|
||||||
|
throw `Could not find a Julia version that matches ${versionInput}`;
|
||||||
|
}
|
||||||
|
return version;
|
||||||
|
});
|
||||||
|
}
|
||||||
function getMajorMinorVersion(version) {
|
function getMajorMinorVersion(version) {
|
||||||
return version.split('.').slice(0, 2).join('.');
|
return version.split('.').slice(0, 2).join('.');
|
||||||
}
|
}
|
||||||
@@ -95,8 +139,9 @@ function installJulia(version, arch) {
|
|||||||
function run() {
|
function run() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
const version = core.getInput('version');
|
const versionInput = core.getInput('version');
|
||||||
const arch = core.getInput('arch');
|
const arch = core.getInput('arch');
|
||||||
|
const version = yield 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;
|
||||||
|
|||||||
@@ -23,11 +23,11 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.0.0",
|
"@actions/core": "^1.0.0",
|
||||||
"@actions/io": "^1.0.0",
|
|
||||||
"@actions/exec": "^1.0.0",
|
"@actions/exec": "^1.0.0",
|
||||||
"@actions/github": "^1.0.0",
|
"@actions/github": "^1.0.0",
|
||||||
|
"@actions/io": "^1.0.0",
|
||||||
"@actions/tool-cache": "^1.0.0",
|
"@actions/tool-cache": "^1.0.0",
|
||||||
"semver": "^6.1.1"
|
"semver": "^6.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^24.0.13",
|
"@types/jest": "^24.0.13",
|
||||||
|
|||||||
@@ -2,13 +2,61 @@ 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 os from 'os'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
|
|
||||||
|
import * as semver from 'semver'
|
||||||
|
|
||||||
// Store information about the environment
|
// Store information about the environment
|
||||||
const osPlat = os.platform() // possible values: win32 (Windows), linux (Linux), darwin (macOS)
|
const osPlat = os.platform() // possible values: win32 (Windows), linux (Linux), darwin (macOS)
|
||||||
core.debug(`platform: ${osPlat}`)
|
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', () => {
|
||||||
|
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()
|
||||||
|
const version = semver.maxSatisfying(releases, versionInput)
|
||||||
|
if (version == null) {
|
||||||
|
throw `Could not find a Julia version that matches ${versionInput}`
|
||||||
|
}
|
||||||
|
|
||||||
|
return version
|
||||||
|
}
|
||||||
|
|
||||||
function getMajorMinorVersion(version: string): string {
|
function getMajorMinorVersion(version: string): string {
|
||||||
return version.split('.').slice(0, 2).join('.')
|
return version.split('.').slice(0, 2).join('.')
|
||||||
}
|
}
|
||||||
@@ -81,8 +129,9 @@ async function installJulia(version: string, arch: string): Promise<string> {
|
|||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
try {
|
try {
|
||||||
const version = core.getInput('version')
|
const versionInput = core.getInput('version')
|
||||||
const arch = core.getInput('arch')
|
const arch = core.getInput('arch')
|
||||||
|
const version = await getJuliaVersion(versionInput)
|
||||||
core.debug(`selected Julia version: ${arch}/${version}`)
|
core.debug(`selected Julia version: ${arch}/${version}`)
|
||||||
|
|
||||||
// Search in cache
|
// Search in cache
|
||||||
|
|||||||
Reference in New Issue
Block a user