Support version ranges as input version

This commit is contained in:
Sascha Mann
2019-09-25 20:23:23 +02:00
parent 53af7ff088
commit 955535b050
3 changed files with 98 additions and 4 deletions

47
lib/setup-julia.js generated
View File

@@ -18,11 +18,55 @@ 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', () => {
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) {
return version.split('.').slice(0, 2).join('.');
}
@@ -95,8 +139,9 @@ function installJulia(version, arch) {
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
const version = core.getInput('version');
const versionInput = core.getInput('version');
const arch = core.getInput('arch');
const version = yield getJuliaVersion(versionInput);
core.debug(`selected Julia version: ${arch}/${version}`);
// Search in cache
let juliaPath;