Add resolution-strategy input to support oldest compatible version selection (#631)
Some checks failed
CodeQL / Analyze (TypeScript) (push) Failing after 2s
test / lint (push) Failing after 2s
test / test-default-version (ubuntu-latest) (push) Failing after 2s
test / test-specific-version (map[expected-version:0.1.0 resolution-strategy:lowest version-input:>=0.1.0,<0.2]) (push) Failing after 1s
test / test-uv-no-modify-path (push) Failing after 1s
test / test-specific-version (map[expected-version:0.1.45 resolution-strategy:highest version-input:>=0.1,<0.2]) (push) Failing after 1s
test / test-specific-version (map[expected-version:0.3.0 version-input:0.3.0]) (push) Failing after 1s
test / test-specific-version (map[expected-version:0.3.2 version-input:0.3.2]) (push) Failing after 2s
test / test-specific-version (map[expected-version:0.3.5 version-input:0.3.x]) (push) Failing after 1s
test / test-specific-version (map[expected-version:0.3.5 version-input:0.3]) (push) Failing after 1s
test / test-specific-version (map[expected-version:0.4.25 resolution-strategy:lowest version-input:>=0.4.25,<0.5]) (push) Failing after 1s
test / test-specific-version (map[expected-version:0.4.30 version-input:>=0.4.25,<0.5]) (push) Failing after 1s
test / test-latest-version (>=0.8) (push) Failing after 2s
test / test-latest-version (latest) (push) Failing after 1s
test / test-from-working-directory-version (map[expected-version:0.5.14 working-directory:__tests__/fixtures/pyproject-toml-project]) (push) Failing after 1s
test / test-from-working-directory-version (map[expected-version:0.5.15 working-directory:__tests__/fixtures/uv-toml-project]) (push) Failing after 2s
test / test-version-file-version (map[expected-version:0.5.15 version-file:__tests__/fixtures/.tool-versions]) (push) Failing after 2s
test / test-version-file-version (map[expected-version:0.6.17 version-file:__tests__/fixtures/uv-in-requirements-txt-project/requirements.txt]) (push) Failing after 1s
test / test-version-file-version (map[expected-version:0.8.3 version-file:__tests__/fixtures/uv-in-requirements-hash-txt-project/requirements.txt]) (push) Failing after 1s
test / test-malformed-pyproject-file-fallback (push) Failing after 1s
test / test-checksum (map[checksum:4d9279ad5ca596b1e2d703901d508430eb07564dc4d8837de9e2fca9c90f8ecd os:ubuntu-latest]) (push) Failing after 1s
test / test-with-explicit-token (push) Failing after 1s
test / test-uvx (push) Failing after 1s
test / test-tool-install (ubuntu-latest) (push) Failing after 1s
test / test-python-version (ubuntu-latest) (push) Failing after 1s
test / test-activate-environment (ubuntu-latest) (push) Failing after 1s
test / test-setup-cache (auto, ubuntu-latest) (push) Failing after 1s
test / test-setup-cache (false, ubuntu-latest) (push) Failing after 1s
test / test-setup-cache (true, ubuntu-latest) (push) Failing after 1s
test / test-musl (push) Failing after 5s
test / test-restore-cache-requirements-txt (push) Has been skipped
test / test-setup-cache-requirements-txt (push) Failing after 1s
test / test-setup-cache-dependency-glob (push) Failing after 2s
test / test-restore-cache-dependency-glob (push) Has been skipped
test / test-setup-cache-save-cache-false (push) Failing after 4s
test / test-restore-cache-save-cache-false (push) Has been skipped
test / test-setup-cache-restore-cache-false (push) Failing after 4s
test / test-restore-cache-restore-cache-false (push) Has been skipped
test / test-cache-local (map[expected-cache-dir:/home/runner/work/_temp/setup-uv-cache os:ubuntu-latest]) (push) Failing after 5s
test / test-cache-local-cache-disabled (push) Failing after 5s
test / test-no-python-version (push) Failing after 4s
test / test-custom-manifest-file (push) Failing after 4s
test / test-absolute-path (push) Failing after 3s
test / test-relative-path (push) Failing after 3s
test / test-cache-prune-force (push) Failing after 3s
test / test-cache-dir-from-file (push) Failing after 4s
test / test-cache-python-installs (push) Failing after 4s
test / test-restore-python-installs (push) Has been skipped
test / test-python-install-dir (map[expected-python-dir:/home/runner/work/_temp/uv-python-dir os:ubuntu-latest]) (push) Failing after 5s
Release Drafter / ✏️ Draft release (push) Has been cancelled
test / test-tool-install (macos-latest) (push) Has been cancelled
test / test-tool-install (windows-latest) (push) Has been cancelled
test / test-tilde-expansion-tool-dirs (push) Has been cancelled
test / test-python-version (macos-latest) (push) Has been cancelled
test / test-default-version (macos-14) (push) Has been cancelled
test / test-default-version (macos-latest) (push) Has been cancelled
test / test-default-version (windows-latest) (push) Has been cancelled
test / test-checksum (map[checksum:a70cbfbf3bb5c08b2f84963b4f12c94e08fbb2468ba418a3bfe1066fbe9e7218 os:macos-latest]) (push) Has been cancelled
test / test-tool-install (macos-14) (push) Has been cancelled
test / test-python-version (windows-latest) (push) Has been cancelled
test / test-activate-environment (macos-latest) (push) Has been cancelled
test / test-activate-environment (windows-latest) (push) Has been cancelled
test / test-setup-cache (auto, selfhosted-ubuntu-arm64) (push) Has been cancelled
test / test-setup-cache (auto, windows-latest) (push) Has been cancelled
test / test-setup-cache (false, selfhosted-ubuntu-arm64) (push) Has been cancelled
test / test-setup-cache (false, windows-latest) (push) Has been cancelled
test / test-setup-cache (true, selfhosted-ubuntu-arm64) (push) Has been cancelled
test / test-setup-cache (true, windows-latest) (push) Has been cancelled
test / test-cache-local (map[expected-cache-dir:/home/ubuntu/.cache/uv os:selfhosted-ubuntu-arm64]) (push) Has been cancelled
test / test-cache-local (map[expected-cache-dir:D:\a\_temp\setup-uv-cache os:windows-latest]) (push) Has been cancelled
test / test-setup-cache-local (push) Has been cancelled
test / test-tilde-expansion-cache-local-path (push) Has been cancelled
test / test-tilde-expansion-cache-dependency-glob (push) Has been cancelled
test / test-python-install-dir (map[expected-python-dir:/home/ubuntu/.local/share/uv/python os:selfhosted-ubuntu-arm64]) (push) Has been cancelled
test / test-restore-cache (false, selfhosted-ubuntu-arm64) (push) Has been cancelled
test / test-restore-cache (auto, selfhosted-ubuntu-arm64) (push) Has been cancelled
test / cleanup-tilde-expansion-tests (push) Has been cancelled
test / all-tests-passed (push) Has been cancelled
test / test-python-install-dir (map[expected-python-dir:D:\a\_temp\uv-python-dir os:windows-latest]) (push) Has been cancelled
test / test-restore-cache (false, ubuntu-latest) (push) Has been cancelled
test / test-restore-cache (false, windows-latest) (push) Has been cancelled
test / test-restore-cache (true, selfhosted-ubuntu-arm64) (push) Has been cancelled
test / test-restore-cache (true, ubuntu-latest) (push) Has been cancelled
test / test-restore-cache (true, windows-latest) (push) Has been cancelled
test / test-restore-cache (auto, ubuntu-latest) (push) Has been cancelled
test / test-restore-cache (auto, windows-latest) (push) Has been cancelled
test / test-restore-cache-local (push) Has been cancelled
Update known versions / build (push) Has been cancelled

Adds a new `resolution-strategy` input that allows users to choose
between installing the highest (default) or lowest compatible version
when resolving version ranges.
This commit is contained in:
Copilot
2025-10-11 21:02:04 +02:00
committed by GitHub
parent a5129e99f4
commit 9c6b5e9fb5
8 changed files with 136 additions and 11 deletions

View File

@@ -4,6 +4,7 @@ import * as core from "@actions/core";
import * as tc from "@actions/tool-cache";
import type { Endpoints } from "@octokit/types";
import * as pep440 from "@renovatebot/pep440";
import * as semver from "semver";
import { OWNER, REPO, TOOL_CACHE_NAME } from "../utils/constants";
import { Octokit } from "../utils/octokit";
import type { Architecture, Platform } from "../utils/platforms";
@@ -134,6 +135,7 @@ export async function resolveVersion(
versionInput: string,
manifestFile: string | undefined,
githubToken: string,
resolutionStrategy: "highest" | "lowest" = "highest",
): Promise<string> {
core.debug(`Resolving version: ${versionInput}`);
let version: string;
@@ -164,7 +166,10 @@ export async function resolveVersion(
}
const availableVersions = await getAvailableVersions(githubToken);
core.debug(`Available versions: ${availableVersions}`);
const resolvedVersion = maxSatisfying(availableVersions, version);
const resolvedVersion =
resolutionStrategy === "lowest"
? minSatisfying(availableVersions, version)
: maxSatisfying(availableVersions, version);
if (resolvedVersion === undefined) {
throw new Error(`No version found for ${version}`);
}
@@ -264,3 +269,24 @@ function maxSatisfying(
}
return undefined;
}
function minSatisfying(
versions: string[],
version: string,
): string | undefined {
// For semver, we need to use a different approach since tc.evaluateVersions only returns max
// Let's use semver directly for min satisfying
const minSemver = semver.minSatisfying(versions, version);
if (minSemver !== null) {
core.debug(`Found a version that satisfies the semver range: ${minSemver}`);
return minSemver;
}
const minPep440 = pep440.minSatisfying(versions, version);
if (minPep440 !== null) {
core.debug(
`Found a version that satisfies the pep440 specifier: ${minPep440}`,
);
return minPep440;
}
return undefined;
}

View File

@@ -21,6 +21,7 @@ import {
manifestFile,
pythonDir,
pythonVersion,
resolutionStrategy,
toolBinDir,
toolDir,
versionFile as versionFileInput,
@@ -120,7 +121,12 @@ async function determineVersion(
manifestFile: string | undefined,
): Promise<string> {
if (versionInput !== "") {
return await resolveVersion(versionInput, manifestFile, githubToken);
return await resolveVersion(
versionInput,
manifestFile,
githubToken,
resolutionStrategy,
);
}
if (versionFileInput !== "") {
const versionFromFile = getUvVersionFromFile(versionFileInput);
@@ -129,7 +135,12 @@ async function determineVersion(
`Could not determine uv version from file: ${versionFileInput}`,
);
}
return await resolveVersion(versionFromFile, manifestFile, githubToken);
return await resolveVersion(
versionFromFile,
manifestFile,
githubToken,
resolutionStrategy,
);
}
const versionFromUvToml = getUvVersionFromFile(
`${workingDirectory}${path.sep}uv.toml`,
@@ -146,6 +157,7 @@ async function determineVersion(
versionFromUvToml || versionFromPyproject || "latest",
manifestFile,
githubToken,
resolutionStrategy,
);
}

View File

@@ -27,6 +27,7 @@ export const githubToken = core.getInput("github-token");
export const manifestFile = getManifestFile();
export const addProblemMatchers =
core.getInput("add-problem-matchers") === "true";
export const resolutionStrategy = getResolutionStrategy();
function getVersionFile(): string {
const versionFileInput = core.getInput("version-file");
@@ -186,3 +187,16 @@ function getManifestFile(): string | undefined {
}
return undefined;
}
function getResolutionStrategy(): "highest" | "lowest" {
const resolutionStrategyInput = core.getInput("resolution-strategy");
if (resolutionStrategyInput === "lowest") {
return "lowest";
}
if (resolutionStrategyInput === "highest" || resolutionStrategyInput === "") {
return "highest";
}
throw new Error(
`Invalid resolution-strategy: ${resolutionStrategyInput}. Must be 'highest' or 'lowest'.`,
);
}