diff --git a/__tests__/download/download-version.test.ts b/__tests__/download/download-version.test.ts index b2352dc..25c02d3 100644 --- a/__tests__/download/download-version.test.ts +++ b/__tests__/download/download-version.test.ts @@ -146,6 +146,28 @@ describe("download-version", () => { expect(mockGetAllVersions).not.toHaveBeenCalled(); }); + it("resolves ~= with PEP 440 compatible release semantics", async () => { + mockGetFirstMatchingVersion.mockImplementation( + (predicate: (version: string) => boolean) => + ["1.0.0", "0.10.2", "0.9.26"].find(predicate), + ); + + const version = await resolveVersion("~=0.9", undefined); + + expect(version).toBe("0.10.2"); + }); + + it("resolves ~= with PEP 440 compatible release semantics from manifest-file", async () => { + mockGetAllVersions.mockResolvedValue(["1.0.0", "0.10.2", "0.9.26"]); + + const version = await resolveVersion( + "~=0.9", + "https://example.com/custom.ndjson", + ); + + expect(version).toBe("0.10.2"); + }); + it("treats == exact pins as explicit versions", async () => { const version = await resolveVersion("==0.9.26", undefined); diff --git a/dist/setup/index.cjs b/dist/setup/index.cjs index b76c0c6..0b7cf0c 100644 --- a/dist/setup/index.cjs +++ b/dist/setup/index.cjs @@ -101937,7 +101937,7 @@ async function resolveVersion(versionInput, manifestUrl, resolutionStrategy = "h throw new Error(`No version found for ${versionInput}`); } async function findHighestSatisfyingVersion(versionSpecifier) { - const semverRange = semver5.validRange(versionSpecifier); + const semverRange = isCompatibleReleaseSpecifier(versionSpecifier) ? null : semver5.validRange(versionSpecifier); if (semverRange !== null) { const semverMatch = await getFirstMatchingVersion( (version3) => semver5.satisfies(version3, semverRange) @@ -101959,8 +101959,11 @@ async function findHighestSatisfyingVersion(versionSpecifier) { } return pep440Match; } +function isCompatibleReleaseSpecifier(versionSpecifier) { + return versionSpecifier.includes("~="); +} function maxSatisfying2(versions, version3) { - const maxSemver = evaluateVersions(versions, version3); + const maxSemver = isCompatibleReleaseSpecifier(version3) ? "" : evaluateVersions(versions, version3); if (maxSemver !== "") { debug(`Found a version that satisfies the semver range: ${maxSemver}`); return maxSemver; @@ -101975,7 +101978,7 @@ function maxSatisfying2(versions, version3) { return void 0; } function minSatisfying3(versions, version3) { - const minSemver = semver5.minSatisfying(versions, version3); + const minSemver = isCompatibleReleaseSpecifier(version3) ? null : semver5.minSatisfying(versions, version3); if (minSemver !== null) { debug(`Found a version that satisfies the semver range: ${minSemver}`); return minSemver; diff --git a/src/version/resolve.ts b/src/version/resolve.ts index ea54af7..1153c9d 100644 --- a/src/version/resolve.ts +++ b/src/version/resolve.ts @@ -169,7 +169,9 @@ async function findHighestSatisfyingVersion( ): Promise { // This fast path assumes uv releases are semver-monotonic: newer manifest // entries always have higher versions, with no lower-version backports. - const semverRange = semver.validRange(versionSpecifier); + const semverRange = isCompatibleReleaseSpecifier(versionSpecifier) + ? null + : semver.validRange(versionSpecifier); if (semverRange !== null) { const semverMatch = await getFirstMatchingVersion((version) => semver.satisfies(version, semverRange), @@ -193,11 +195,20 @@ async function findHighestSatisfyingVersion( return pep440Match; } +// `~=` is the PEP 440 compatible release operator. semver accepts it as a +// tilde range with a narrower upper bound (`~=0.5` as `<0.6.0` instead of +// `<1.0`), so it must only be evaluated as PEP 440. +function isCompatibleReleaseSpecifier(versionSpecifier: string): boolean { + return versionSpecifier.includes("~="); +} + function maxSatisfying( versions: string[], version: string, ): string | undefined { - const maxSemver = tc.evaluateVersions(versions, version); + const maxSemver = isCompatibleReleaseSpecifier(version) + ? "" + : tc.evaluateVersions(versions, version); if (maxSemver !== "") { core.debug(`Found a version that satisfies the semver range: ${maxSemver}`); return maxSemver; @@ -218,7 +229,9 @@ function minSatisfying( versions: string[], version: string, ): string | undefined { - const minSemver = semver.minSatisfying(versions, version); + const minSemver = isCompatibleReleaseSpecifier(version) + ? null + : semver.minSatisfying(versions, version); if (minSemver !== null) { core.debug(`Found a version that satisfies the semver range: ${minSemver}`); return minSemver;