fix: fix checking of up to date bin min versions

This commit is contained in:
Amin Yahyaabadi 2024-10-30 23:37:26 -07:00
parent f85ad55d63
commit 9f44eb2c24
6 changed files with 19 additions and 10 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -28,13 +28,10 @@ import { unique } from "../utils/std/index.js"
import { getVersionDefault, isMinVersion } from "../versions/versions.js"
export async function setupPython(
givenVersion: string,
version: string,
setupDir: string,
arch: string,
): Promise<InstallationInfo & { bin: string }> {
// if a version range specified, use the default version, and later check the range
const version = isMinVersion(givenVersion) ? "" : givenVersion
const installInfo = await findOrSetupPython(version, setupDir, arch)
assert(installInfo.bin !== undefined)
const foundPython = installInfo.bin
@ -92,7 +89,10 @@ async function setupWheel(foundPython: string) {
}
}
async function findOrSetupPython(version: string, setupDir: string, arch: string): Promise<InstallationInfo> {
async function findOrSetupPython(givenVersion: string, setupDir: string, arch: string): Promise<InstallationInfo> {
// if a version range specified, use the default version, and later check the range
const version = isMinVersion(givenVersion) ? "" : givenVersion
let installInfo: InstallationInfo | undefined
let foundPython = await findPython(setupDir)

View File

@ -3,6 +3,7 @@ import { info } from "ci-log"
import { isUrlOnline } from "is-url-online"
import semverCoerce from "semver/functions/coerce"
import semverCompare from "semver/functions/compare"
import semverSatisfies from "semver/functions/satisfies"
import semverValid from "semver/functions/valid"
/**
@ -112,7 +113,15 @@ export async function isBinUptoDate(
) {
const givenVersion = await getBinVersion(givenFile, versionRegex)
if (givenVersion !== undefined && targetVersion !== "") {
try {
// if -1, it means the given version is newer than the target version
// this requires the target version to be a valid semver range
return semverCompare(givenVersion, targetVersion) !== -1
} catch {
// check if the given version satisfies the target version
// this works even if the target version is not a valid semver range (e.g. >=1.2.3)
return semverSatisfies(givenVersion, targetVersion)
}
} else {
// assume given version is old
return false