Try and fetch manifest from astral-sh/setup-uv@main first

This commit is contained in:
Zsolt Dollenstein
2026-01-22 11:03:38 +00:00
parent 9cfd029643
commit 450788bda3
5 changed files with 5329 additions and 5152 deletions

5120
dist/save-cache/index.js generated vendored

File diff suppressed because it is too large Load Diff

5210
dist/setup/index.js generated vendored

File diff suppressed because it is too large Load Diff

22
dist/update-known-versions/index.js generated vendored
View File

@@ -32482,8 +32482,10 @@ var __importStar = (this && this.__importStar) || (function () {
};
})();
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.REMOTE_MANIFEST_URL = void 0;
exports.getLatestKnownVersion = getLatestKnownVersion;
exports.getDownloadUrl = getDownloadUrl;
exports.getAvailableVersionsFromManifest = getAvailableVersionsFromManifest;
exports.updateVersionManifest = updateVersionManifest;
const node_fs_1 = __nccwpck_require__(3024);
const node_path_1 = __nccwpck_require__(6760);
@@ -32491,6 +32493,9 @@ const core = __importStar(__nccwpck_require__(7484));
const semver = __importStar(__nccwpck_require__(9318));
const fetch_1 = __nccwpck_require__(3385);
const localManifestFile = (0, node_path_1.join)(__dirname, "..", "..", "version-manifest.json");
exports.REMOTE_MANIFEST_URL = "https://raw.githubusercontent.com/astral-sh/setup-uv/main/version-manifest.json";
// Cache for manifest entries to avoid re-fetching
const manifestCache = new Map();
async function getLatestKnownVersion(manifestUrl) {
const manifestEntries = await getManifestEntries(manifestUrl);
return manifestEntries.reduce((a, b) => semver.gt(a.version, b.version) ? a : b).version;
@@ -32502,7 +32507,18 @@ async function getDownloadUrl(manifestUrl, version, arch, platform) {
entry.platform === platform);
return entry ? entry.downloadUrl : undefined;
}
async function getAvailableVersionsFromManifest(manifestUrl) {
const manifestEntries = await getManifestEntries(manifestUrl);
return [...new Set(manifestEntries.map((entry) => entry.version))];
}
async function getManifestEntries(manifestUrl) {
const cacheKey = manifestUrl ?? "local";
// Return cached entries if available
const cached = manifestCache.get(cacheKey);
if (cached !== undefined) {
core.debug(`Using cached manifest entries for: ${cacheKey}`);
return cached;
}
let data;
if (manifestUrl !== undefined) {
core.info(`Fetching manifest-file from: ${manifestUrl}`);
@@ -32513,11 +32529,13 @@ async function getManifestEntries(manifestUrl) {
data = await response.text();
}
else {
core.info("manifest-file not provided, reading from local file.");
core.debug("Reading manifest from local bundled file.");
const fileContent = await node_fs_1.promises.readFile(localManifestFile);
data = fileContent.toString();
}
return JSON.parse(data);
const entries = JSON.parse(data);
manifestCache.set(cacheKey, entries);
return entries;
}
async function updateVersionManifest(manifestUrl, downloadUrls) {
const manifest = [];

View File

@@ -10,8 +10,10 @@ import { Octokit } from "../utils/octokit";
import type { Architecture, Platform } from "../utils/platforms";
import { validateChecksum } from "./checksum/checksum";
import {
getAvailableVersionsFromManifest,
getDownloadUrl,
getLatestKnownVersion as getLatestVersionInManifest,
REMOTE_MANIFEST_URL,
} from "./version-manifest";
type Release =
@@ -61,27 +63,36 @@ export async function downloadVersionFromManifest(
checkSum: string | undefined,
githubToken: string,
): Promise<{ version: string; cachedToolDir: string }> {
const downloadUrl = await getDownloadUrl(
manifestUrl,
version,
arch,
platform,
);
if (!downloadUrl) {
core.info(
`manifest-file does not contain version ${version}, arch ${arch}, platform ${platform}. Falling back to GitHub releases.`,
);
return await downloadVersionFromGithub(
platform,
arch,
version,
checkSum,
githubToken,
);
// If no user-provided manifest, try remote manifest first (will use cache if already fetched)
// then fall back to bundled manifest
const manifestSources =
manifestUrl !== undefined
? [manifestUrl]
: [REMOTE_MANIFEST_URL, undefined];
for (const source of manifestSources) {
try {
const downloadUrl = await getDownloadUrl(source, version, arch, platform);
if (downloadUrl) {
return await downloadVersion(
downloadUrl,
`uv-${arch}-${platform}`,
platform,
arch,
version,
checkSum,
githubToken,
);
}
} catch (err) {
core.debug(`Failed to get download URL from manifest ${source}: ${err}`);
}
}
return await downloadVersion(
downloadUrl,
`uv-${arch}-${platform}`,
core.info(
`Manifest does not contain version ${version}, arch ${arch}, platform ${platform}. Falling back to GitHub releases.`,
);
return await downloadVersionFromGithub(
platform,
arch,
version,
@@ -188,6 +199,32 @@ export async function resolveVersion(
}
async function getAvailableVersions(githubToken: string): Promise<string[]> {
// 1. Try remote manifest first (no rate limits, always current)
try {
core.info("Getting available versions from remote manifest...");
const versions =
await getAvailableVersionsFromManifest(REMOTE_MANIFEST_URL);
core.debug(`Found ${versions.length} versions from remote manifest`);
return versions;
} catch (err) {
core.debug(`Remote manifest lookup failed: ${err}`);
}
// 2. Try GitHub API (rate limited but up-to-date)
try {
return await getAvailableVersionsFromGitHubApi(githubToken);
} catch (err) {
core.debug(`GitHub API lookup failed: ${err}`);
}
// 3. Fall back to bundled manifest (no network, may be stale)
core.info("Getting available versions from bundled manifest...");
return await getAvailableVersionsFromManifest(undefined);
}
async function getAvailableVersionsFromGitHubApi(
githubToken: string,
): Promise<string[]> {
core.info("Getting available versions from GitHub API...");
try {
const octokit = new Octokit({
@@ -224,7 +261,32 @@ async function getReleaseTagNames(octokit: Octokit): Promise<string[]> {
}
async function getLatestVersion(githubToken: string) {
core.info("Getting latest version from GitHub API...");
// 1. Try remote manifest first (no rate limits, always current)
try {
core.info("Getting latest version from remote manifest...");
const version = await getLatestVersionInManifest(REMOTE_MANIFEST_URL);
core.debug(`Latest version from remote manifest: ${version}`);
return version;
} catch (err) {
core.debug(`Remote manifest lookup failed: ${err}`);
}
// 2. Try GitHub API (rate limited but up-to-date)
try {
core.info("Getting latest version from GitHub API...");
return await getLatestVersionFromGitHubApi(githubToken);
} catch (err) {
core.debug(`GitHub API lookup failed: ${err}`);
}
// 3. Fall back to bundled manifest (no network, may be stale)
core.info("Getting latest version from bundled manifest...");
return await getLatestVersionInManifest(undefined);
}
async function getLatestVersionFromGitHubApi(
githubToken: string,
): Promise<string> {
const octokit = new Octokit({
auth: githubToken,
});

View File

@@ -5,6 +5,11 @@ import * as semver from "semver";
import { fetch } from "../utils/fetch";
const localManifestFile = join(__dirname, "..", "..", "version-manifest.json");
export const REMOTE_MANIFEST_URL =
"https://raw.githubusercontent.com/astral-sh/setup-uv/main/version-manifest.json";
// Cache for manifest entries to avoid re-fetching
const manifestCache = new Map<string, ManifestEntry[]>();
interface ManifestEntry {
version: string;
@@ -39,9 +44,25 @@ export async function getDownloadUrl(
return entry ? entry.downloadUrl : undefined;
}
export async function getAvailableVersionsFromManifest(
manifestUrl: string | undefined,
): Promise<string[]> {
const manifestEntries = await getManifestEntries(manifestUrl);
return [...new Set(manifestEntries.map((entry) => entry.version))];
}
async function getManifestEntries(
manifestUrl: string | undefined,
): Promise<ManifestEntry[]> {
const cacheKey = manifestUrl ?? "local";
// Return cached entries if available
const cached = manifestCache.get(cacheKey);
if (cached !== undefined) {
core.debug(`Using cached manifest entries for: ${cacheKey}`);
return cached;
}
let data: string;
if (manifestUrl !== undefined) {
core.info(`Fetching manifest-file from: ${manifestUrl}`);
@@ -58,7 +79,9 @@ async function getManifestEntries(
data = fileContent.toString();
}
return JSON.parse(data);
const entries: ManifestEntry[] = JSON.parse(data);
manifestCache.set(cacheKey, entries);
return entries;
}
export async function updateVersionManifest(