mirror of
https://github.com/julia-actions/setup-julia.git
synced 2026-02-12 02:56:54 +08:00
Refactor getJuliaVersion to make it testable
This commit is contained in:
6
lib/installer.js
generated
6
lib/installer.js
generated
@@ -53,15 +53,15 @@ function getJuliaReleases() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function getJuliaVersion(versionInput) {
|
exports.getJuliaReleases = getJuliaReleases;
|
||||||
|
function getJuliaVersion(availableReleases, versionInput) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
if (semver.valid(versionInput) == versionInput) {
|
if (semver.valid(versionInput) == versionInput) {
|
||||||
// versionInput is a valid version, use it directly
|
// versionInput is a valid version, use it directly
|
||||||
return versionInput;
|
return versionInput;
|
||||||
}
|
}
|
||||||
// Use the highest available version that matches versionInput
|
// Use the highest available version that matches versionInput
|
||||||
const releases = yield getJuliaReleases();
|
let version = semver.maxSatisfying(availableReleases, versionInput);
|
||||||
let version = semver.maxSatisfying(releases, versionInput);
|
|
||||||
if (version == null) {
|
if (version == null) {
|
||||||
throw `Could not find a Julia version that matches ${versionInput}`;
|
throw `Could not find a Julia version that matches ${versionInput}`;
|
||||||
}
|
}
|
||||||
|
|||||||
3
lib/setup-julia.js
generated
3
lib/setup-julia.js
generated
@@ -25,7 +25,8 @@ 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 = yield installer.getJuliaVersion(versionInput);
|
const availableReleases = yield installer.getJuliaReleases();
|
||||||
|
const version = yield installer.getJuliaVersion(availableReleases, 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;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import * as semver from 'semver'
|
|||||||
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[]> {
|
export async function getJuliaReleases(): Promise<string[]> {
|
||||||
// Wrap everything in a Promise so that it can be called with await.
|
// Wrap everything in a Promise so that it can be called with await.
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const options = {
|
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) {
|
if (semver.valid(versionInput) == versionInput) {
|
||||||
// versionInput is a valid version, use it directly
|
// versionInput is a valid version, use it directly
|
||||||
return versionInput
|
return versionInput
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use the highest available version that matches versionInput
|
// Use the highest available version that matches versionInput
|
||||||
const releases = await getJuliaReleases()
|
let version = semver.maxSatisfying(availableReleases, versionInput)
|
||||||
let version = semver.maxSatisfying(releases, versionInput)
|
|
||||||
if (version == null) {
|
if (version == null) {
|
||||||
throw `Could not find a Julia version that matches ${versionInput}`
|
throw `Could not find a Julia version that matches ${versionInput}`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ 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 installer.getJuliaVersion(versionInput)
|
const availableReleases = await installer.getJuliaReleases()
|
||||||
|
const version = await installer.getJuliaVersion(availableReleases, 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