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

41
dist/setup/index.js generated vendored
View File

@@ -129114,6 +129114,7 @@ const path = __importStar(__nccwpck_require__(76760));
const core = __importStar(__nccwpck_require__(37484));
const tc = __importStar(__nccwpck_require__(33472));
const pep440 = __importStar(__nccwpck_require__(63297));
const semver = __importStar(__nccwpck_require__(39318));
const constants_1 = __nccwpck_require__(56156);
const octokit_1 = __nccwpck_require__(73352);
const checksum_1 = __nccwpck_require__(17772);
@@ -129165,7 +129166,7 @@ async function downloadVersion(downloadUrl, artifactName, platform, arch, versio
function getExtension(platform) {
return platform === "pc-windows-msvc" ? ".zip" : ".tar.gz";
}
async function resolveVersion(versionInput, manifestFile, githubToken) {
async function resolveVersion(versionInput, manifestFile, githubToken, resolutionStrategy = "highest") {
core.debug(`Resolving version: ${versionInput}`);
let version;
const isSimpleMinimumVersionSpecifier = versionInput.includes(">") && !versionInput.includes(",");
@@ -129195,7 +129196,9 @@ async function resolveVersion(versionInput, manifestFile, githubToken) {
}
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}`);
}
@@ -129275,6 +129278,21 @@ function maxSatisfying(versions, version) {
}
return undefined;
}
function minSatisfying(versions, version) {
// 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;
}
/***/ }),
@@ -129583,21 +129601,21 @@ async function setupUv(platform, arch, checkSum, githubToken) {
}
async function determineVersion(manifestFile) {
if (inputs_1.version !== "") {
return await (0, download_version_1.resolveVersion)(inputs_1.version, manifestFile, inputs_1.githubToken);
return await (0, download_version_1.resolveVersion)(inputs_1.version, manifestFile, inputs_1.githubToken, inputs_1.resolutionStrategy);
}
if (inputs_1.versionFile !== "") {
const versionFromFile = (0, resolve_1.getUvVersionFromFile)(inputs_1.versionFile);
if (versionFromFile === undefined) {
throw new Error(`Could not determine uv version from file: ${inputs_1.versionFile}`);
}
return await (0, download_version_1.resolveVersion)(versionFromFile, manifestFile, inputs_1.githubToken);
return await (0, download_version_1.resolveVersion)(versionFromFile, manifestFile, inputs_1.githubToken, inputs_1.resolutionStrategy);
}
const versionFromUvToml = (0, resolve_1.getUvVersionFromFile)(`${inputs_1.workingDirectory}${path.sep}uv.toml`);
const versionFromPyproject = (0, resolve_1.getUvVersionFromFile)(`${inputs_1.workingDirectory}${path.sep}pyproject.toml`);
if (versionFromUvToml === undefined && versionFromPyproject === undefined) {
core.info("Could not determine uv version from uv.toml or pyproject.toml. Falling back to latest.");
}
return await (0, download_version_1.resolveVersion)(versionFromUvToml || versionFromPyproject || "latest", manifestFile, inputs_1.githubToken);
return await (0, download_version_1.resolveVersion)(versionFromUvToml || versionFromPyproject || "latest", manifestFile, inputs_1.githubToken, inputs_1.resolutionStrategy);
}
function addUvToPathAndOutput(cachedPath) {
core.setOutput("uv-path", `${cachedPath}${path.sep}uv`);
@@ -129853,7 +129871,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.addProblemMatchers = exports.manifestFile = exports.githubToken = exports.pythonDir = exports.toolDir = exports.toolBinDir = exports.ignoreEmptyWorkdir = exports.ignoreNothingToCache = exports.cachePython = exports.pruneCache = exports.cacheDependencyGlob = exports.cacheLocalPath = exports.cacheSuffix = exports.saveCache = exports.restoreCache = exports.enableCache = exports.checkSum = exports.activateEnvironment = exports.pythonVersion = exports.versionFile = exports.version = exports.workingDirectory = void 0;
exports.resolutionStrategy = exports.addProblemMatchers = exports.manifestFile = exports.githubToken = exports.pythonDir = exports.toolDir = exports.toolBinDir = exports.ignoreEmptyWorkdir = exports.ignoreNothingToCache = exports.cachePython = exports.pruneCache = exports.cacheDependencyGlob = exports.cacheLocalPath = exports.cacheSuffix = exports.saveCache = exports.restoreCache = exports.enableCache = exports.checkSum = exports.activateEnvironment = exports.pythonVersion = exports.versionFile = exports.version = exports.workingDirectory = void 0;
exports.getUvPythonDir = getUvPythonDir;
const node_path_1 = __importDefault(__nccwpck_require__(76760));
const core = __importStar(__nccwpck_require__(37484));
@@ -129880,6 +129898,7 @@ exports.pythonDir = getUvPythonDir();
exports.githubToken = core.getInput("github-token");
exports.manifestFile = getManifestFile();
exports.addProblemMatchers = core.getInput("add-problem-matchers") === "true";
exports.resolutionStrategy = getResolutionStrategy();
function getVersionFile() {
const versionFileInput = core.getInput("version-file");
if (versionFileInput !== "") {
@@ -130016,6 +130035,16 @@ function getManifestFile() {
}
return undefined;
}
function getResolutionStrategy() {
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'.`);
}
/***/ }),