Skip to content

Commit

Permalink
fix: fix checking of up to date bin min versions
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Oct 31, 2024
1 parent f85ad55 commit 7da0fde
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion dist/legacy/setup-cpp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/legacy/setup-cpp.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/modern/setup-cpp.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/modern/setup-cpp.mjs.map

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/python/python.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
11 changes: 10 additions & 1 deletion src/utils/setup/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { isUrlOnline } from "is-url-online"
import semverCoerce from "semver/functions/coerce"
import semverCompare from "semver/functions/compare"
import semverValid from "semver/functions/valid"
import semverSatisfies from "semver/functions/satisfies"

/**
* Gets the specific versions supported by this action compatible with the supplied (specific or minimum) version in
Expand Down Expand Up @@ -112,7 +113,15 @@ export async function isBinUptoDate(
) {
const givenVersion = await getBinVersion(givenFile, versionRegex)
if (givenVersion !== undefined && targetVersion !== "") {
return semverCompare(givenVersion, targetVersion) !== -1
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
Expand Down

0 comments on commit 7da0fde

Please sign in to comment.