Refactor getJuliaVersion to make it testable

This commit is contained in:
Sascha Mann
2019-10-04 00:21:58 +02:00
parent dc7dce0a2d
commit 16c0aaf600
4 changed files with 10 additions and 9 deletions

View File

@@ -12,7 +12,7 @@ import * as semver from 'semver'
const osPlat = os.platform() // possible values: win32 (Windows), linux (Linux), darwin (macOS)
core.debug(`platform: ${osPlat}`)
async function getJuliaReleases(): Promise<string[]> {
export 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 = {
@@ -42,15 +42,14 @@ async function getJuliaReleases(): Promise<string[]> {
})
}
export async function getJuliaVersion(versionInput: string): Promise<string> {
export async function getJuliaVersion(availableReleases: string[], 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)
let version = semver.maxSatisfying(availableReleases, versionInput)
if (version == null) {
throw `Could not find a Julia version that matches ${versionInput}`
}

View File

@@ -10,7 +10,8 @@ async function run() {
try {
const versionInput = core.getInput('version')
const arch = core.getInput('arch')
const version = await installer.getJuliaVersion(versionInput)
const availableReleases = await installer.getJuliaReleases()
const version = await installer.getJuliaVersion(availableReleases, versionInput)
core.debug(`selected Julia version: ${arch}/${version}`)
// Search in cache