mirror of
https://github.com/astral-sh/setup-uv.git
synced 2026-08-25 19:43:50 +00:00
Add latest-known version selector (#993)
## Summary - add `latest-known` as an explicit version selector - resolve it locally to the newest version in the bundled checksum table - preserve existing default and `latest` behavior - document custom-manifest checksum semantics and update published bundles ## Testing - `npm ci --ignore-scripts` - `npm run all` (99 tests passed) Closes #919 Refs: pi-session 019fed0e-6019-7504-911b-bd9955cbbd49
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import * as semver from "semver";
|
||||
import { KNOWN_CHECKSUMS } from "./known-checksums";
|
||||
|
||||
const VERSION_IN_CHECKSUM_KEY_PATTERN =
|
||||
/-(\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?)$/;
|
||||
|
||||
export function getLatestKnownVersion(): string {
|
||||
const versions = new Set<string>();
|
||||
|
||||
for (const key of Object.keys(KNOWN_CHECKSUMS)) {
|
||||
const version = key.match(VERSION_IN_CHECKSUM_KEY_PATTERN)?.[1];
|
||||
if (version !== undefined) {
|
||||
versions.add(version);
|
||||
}
|
||||
}
|
||||
|
||||
const latestVersion = [...versions].sort(semver.rcompare)[0];
|
||||
if (!latestVersion) {
|
||||
throw new Error("Could not determine latest known version from checksums.");
|
||||
}
|
||||
|
||||
return latestVersion;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as core from "@actions/core";
|
||||
import * as semver from "semver";
|
||||
import { KNOWN_CHECKSUMS } from "./download/checksum/known-checksums";
|
||||
import { getLatestKnownVersion } from "./download/checksum/known-version";
|
||||
import {
|
||||
type ChecksumEntry,
|
||||
updateChecksums,
|
||||
@@ -12,9 +12,6 @@ import {
|
||||
} from "./download/manifest";
|
||||
import * as log from "./utils/logging";
|
||||
|
||||
const VERSION_IN_CHECKSUM_KEY_PATTERN =
|
||||
/-(\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?)$/;
|
||||
|
||||
async function run(): Promise<void> {
|
||||
const checksumFilePath = process.argv.slice(2)[0];
|
||||
if (!checksumFilePath) {
|
||||
@@ -24,7 +21,7 @@ async function run(): Promise<void> {
|
||||
}
|
||||
|
||||
const latestVersion = await getLatestVersion();
|
||||
const latestKnownVersion = getLatestKnownVersionFromChecksums();
|
||||
const latestKnownVersion = getLatestKnownVersion();
|
||||
|
||||
if (semver.lte(latestVersion, latestKnownVersion)) {
|
||||
log.info(
|
||||
@@ -40,28 +37,6 @@ async function run(): Promise<void> {
|
||||
core.setOutput("latest-version", latestVersion);
|
||||
}
|
||||
|
||||
function getLatestKnownVersionFromChecksums(): string {
|
||||
const versions = new Set<string>();
|
||||
|
||||
for (const key of Object.keys(KNOWN_CHECKSUMS)) {
|
||||
const version = extractVersionFromChecksumKey(key);
|
||||
if (version !== undefined) {
|
||||
versions.add(version);
|
||||
}
|
||||
}
|
||||
|
||||
const latestVersion = [...versions].sort(semver.rcompare)[0];
|
||||
if (!latestVersion) {
|
||||
throw new Error("Could not determine latest known version from checksums.");
|
||||
}
|
||||
|
||||
return latestVersion;
|
||||
}
|
||||
|
||||
function extractVersionFromChecksumKey(key: string): string | undefined {
|
||||
return key.match(VERSION_IN_CHECKSUM_KEY_PATTERN)?.[1];
|
||||
}
|
||||
|
||||
function extractChecksumsFromManifest(
|
||||
versions: ManifestVersion[],
|
||||
): ChecksumEntry[] {
|
||||
|
||||
@@ -2,6 +2,7 @@ import * as core from "@actions/core";
|
||||
import * as tc from "@actions/tool-cache";
|
||||
import * as pep440 from "@renovatebot/pep440";
|
||||
import * as semver from "semver";
|
||||
import { getLatestKnownVersion } from "../download/checksum/known-version";
|
||||
import {
|
||||
getAllVersions,
|
||||
getFirstMatchingVersion,
|
||||
@@ -143,6 +144,10 @@ export async function resolveVersion(
|
||||
): Promise<string> {
|
||||
core.debug(`Resolving version: ${versionInput}`);
|
||||
|
||||
if (versionInput.trim() === "latest-known") {
|
||||
return getLatestKnownVersion();
|
||||
}
|
||||
|
||||
const context: ConcreteVersionResolutionContext = {
|
||||
manifestUrl,
|
||||
parsedSpecifier: parseVersionSpecifier(versionInput),
|
||||
|
||||
Reference in New Issue
Block a user