Add support for pep440 version specifiers (#150)

Fixes: #147
This commit is contained in:
Kevin Stillhammer
2025-05-26 20:20:17 +02:00
committed by GitHub
parent da0c801a2d
commit 9b2efb7fd8
6 changed files with 856 additions and 7 deletions
+22 -2
View File
@@ -3,6 +3,7 @@ import * as tc from "@actions/tool-cache";
import * as path from "node:path";
import { promises as fs } from "node:fs";
import * as semver from "semver";
import * as pep440 from "@renovatebot/pep440";
import { OWNER, REPO, TOOL_CACHE_NAME } from "../utils/constants";
import type { Architecture, Platform } from "../utils/platforms";
import { validateChecksum } from "./checksum/checksum";
@@ -124,8 +125,8 @@ export async function resolveVersion(
return version;
}
const availableVersions = await getAvailableVersions(githubToken);
const resolvedVersion = tc.evaluateVersions(availableVersions, version);
if (resolvedVersion === "") {
const resolvedVersion = maxSatisfying(availableVersions, version);
if (resolvedVersion === undefined) {
throw new Error(`No version found for ${version}`);
}
core.debug(`Resolved version: ${resolvedVersion}`);
@@ -195,3 +196,22 @@ async function getLatestRelease(
});
return latestRelease;
}
function maxSatisfying(
versions: string[],
version: string,
): string | undefined {
const maxSemver = tc.evaluateVersions(versions, version);
if (maxSemver !== "") {
core.debug(`Found a version that satisfies the semver range: ${maxSemver}`);
return maxSemver;
}
const maxPep440 = pep440.maxSatisfying(versions, version);
if (maxPep440 !== null) {
core.debug(
`Found a version that satisfies the pep440 specifier: ${maxPep440}`,
);
return maxPep440;
}
return undefined;
}