From 802776bd6a092df69ee779cd7e7311cdf5ea3ff5 Mon Sep 17 00:00:00 2001 From: Sascha Mann Date: Sun, 5 Jul 2020 13:55:12 +0200 Subject: [PATCH] Throw error if version range doesn't match anything fixes #38 --- __tests__/main.test.ts | 7 +++++++ lib/installer.js | 34 ++++++++++++++++------------------ src/installer.ts | 2 +- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 089c760..5db125b 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -29,6 +29,13 @@ describe('installer tests', () => { expect(await installer.getJuliaVersion(testVersions, '^1.2.0-rc1')).toEqual('1.2.0') }) }) + describe('invalid version range (#38)', () => { + it('Throws an error if a version range does not match any available version', () => { + expect(() => { + installer.getJuliaVersion(['v1.5.0-rc1', 'v1.5.0-beta1', 'v1.4.2', 'v1.4.1', 'v1.4.0', 'v1.4.0-rc2', 'v1.4.0-rc1'], '1.6') + }).toThrowError() + }) + }) }) describe('node-semver behaviour', () => { describe('Windows installer change', () => { diff --git a/lib/installer.js b/lib/installer.js index b0c0b3d..4267fb6 100644 --- a/lib/installer.js +++ b/lib/installer.js @@ -27,24 +27,22 @@ core.debug(`platform: ${osPlat}`); // This is temporary until we have a better way of fetching releases (see #1, #4 for details) exports.juliaVersions = ['v1.5.0-rc1', 'v1.5.0-beta1', 'v1.4.2', 'v1.4.1', 'v1.4.0', 'v1.4.0-rc2', 'v1.4.0-rc1', 'v1.3.1', 'v1.3.0', 'v1.3.0-rc5', 'v1.3.0-rc4', 'v1.3.0-rc3', 'v1.3.0-rc2', 'v1.0.5', 'v1.2.0', 'v1.3.0-rc1', 'v1.2.0-rc3', 'v1.3.0-alpha', 'v1.2.0-rc2', 'v1.2.0-rc1', 'v1.1.1', 'v1.0.4', 'v1.1.0', 'v1.1.0-rc2', 'v1.1.0-rc1', 'v1.0.3', 'v1.0.2', 'v1.0.1', 'v1.0.0', 'v0.7.0', 'v1.0.0-rc1', 'v0.7.0-rc3', 'v0.7.0-rc2', 'v0.7.0-rc1', 'v0.7.0-beta2', 'v0.6.4', 'v0.7.0-beta', 'v0.7.0-alpha', 'v0.6.3', 'v0.6.2', 'v0.6.1', 'v0.6.0', 'v0.6.0-rc3', 'v0.6.0-rc2', 'v0.5.2', 'v0.6.0-rc1', 'v0.6.0-pre.beta', 'v0.5.1', 'v0.6.0-pre.alpha', 'v0.5.0', 'v0.4.7', 'v0.5.0-rc4', 'v0.5.0-rc3', 'v0.5.0-rc2', 'v0.5.0-rc1', 'v0.5.0-rc0', 'v0.4.6', 'v0.4.5', 'v0.4.4', 'v0.4.3', 'v0.4.2', 'v0.4.1', 'v0.3.12', 'v0.4.0', 'v0.4.0-rc4', 'v0.4.0-rc3', 'v0.4.0-rc2', 'v0.4.0-rc1', 'v0.3.11', 'v0.3.10', 'v0.3.9', 'v0.3.8', 'v0.3.7', 'v0.3.6', 'v0.3.5', 'v0.3.4', 'v0.3.3', 'v0.3.2', 'v0.3.1', 'v0.3.0', 'v0.3.0-rc4', 'v0.3.0-rc3', 'v0.3.0-rc2', 'v0.3.0-rc1', 'v0.2.0-rc1', 'v0.2.0-rc3', 'v0.2.0-rc4', 'v0.2.0', 'v0.2.0-rc2']; function getJuliaVersion(availableReleases, versionInput) { - return __awaiter(this, void 0, void 0, function* () { - if (semver.valid(versionInput) == versionInput) { - // versionInput is a valid version, use it directly - return versionInput; - } - // nightlies - if (versionInput == 'nightly') { - return 'nightly'; - } - // Use the highest available version that matches versionInput - let version = semver.maxSatisfying(availableReleases, 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; - }); + if (semver.valid(versionInput) == versionInput) { + // versionInput is a valid version, use it directly + return versionInput; + } + // nightlies + if (versionInput == 'nightly') { + return 'nightly'; + } + // Use the highest available version that matches versionInput + let version = semver.maxSatisfying(availableReleases, 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) { diff --git a/src/installer.ts b/src/installer.ts index 23d70c4..9bcc7e3 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -14,7 +14,7 @@ core.debug(`platform: ${osPlat}`) // This is temporary until we have a better way of fetching releases (see #1, #4 for details) export const juliaVersions = ['v1.5.0-rc1', 'v1.5.0-beta1', 'v1.4.2', 'v1.4.1', 'v1.4.0', 'v1.4.0-rc2', 'v1.4.0-rc1', 'v1.3.1', 'v1.3.0', 'v1.3.0-rc5', 'v1.3.0-rc4', 'v1.3.0-rc3', 'v1.3.0-rc2', 'v1.0.5', 'v1.2.0', 'v1.3.0-rc1', 'v1.2.0-rc3', 'v1.3.0-alpha', 'v1.2.0-rc2', 'v1.2.0-rc1', 'v1.1.1', 'v1.0.4', 'v1.1.0', 'v1.1.0-rc2', 'v1.1.0-rc1', 'v1.0.3', 'v1.0.2', 'v1.0.1', 'v1.0.0', 'v0.7.0', 'v1.0.0-rc1', 'v0.7.0-rc3', 'v0.7.0-rc2', 'v0.7.0-rc1', 'v0.7.0-beta2', 'v0.6.4', 'v0.7.0-beta', 'v0.7.0-alpha', 'v0.6.3', 'v0.6.2', 'v0.6.1', 'v0.6.0', 'v0.6.0-rc3', 'v0.6.0-rc2', 'v0.5.2', 'v0.6.0-rc1', 'v0.6.0-pre.beta', 'v0.5.1', 'v0.6.0-pre.alpha', 'v0.5.0', 'v0.4.7', 'v0.5.0-rc4', 'v0.5.0-rc3', 'v0.5.0-rc2', 'v0.5.0-rc1', 'v0.5.0-rc0', 'v0.4.6', 'v0.4.5', 'v0.4.4', 'v0.4.3', 'v0.4.2', 'v0.4.1', 'v0.3.12', 'v0.4.0', 'v0.4.0-rc4', 'v0.4.0-rc3', 'v0.4.0-rc2', 'v0.4.0-rc1', 'v0.3.11', 'v0.3.10', 'v0.3.9', 'v0.3.8', 'v0.3.7', 'v0.3.6', 'v0.3.5', 'v0.3.4', 'v0.3.3', 'v0.3.2', 'v0.3.1', 'v0.3.0', 'v0.3.0-rc4', 'v0.3.0-rc3', 'v0.3.0-rc2', 'v0.3.0-rc1', 'v0.2.0-rc1', 'v0.2.0-rc3', 'v0.2.0-rc4', 'v0.2.0', 'v0.2.0-rc2'] -export async function getJuliaVersion(availableReleases: string[], versionInput: string): Promise { +export function getJuliaVersion(availableReleases: string[], versionInput: string): string { if (semver.valid(versionInput) == versionInput) { // versionInput is a valid version, use it directly return versionInput