mirror of
https://github.com/astral-sh/setup-uv.git
synced 2026-11-05 01:35:32 +00:00
Use Astral mirror for version manifests with GitHub fallback (#1119)
Amp-Thread-ID: https://ampcode.com/threads/T-01a1822a-68da-7125-9e7d-16e038ab0840 Closes: #1118 Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import { createInterface } from "node:readline";
|
||||
import { Readable } from "node:stream";
|
||||
import * as core from "@actions/core";
|
||||
import { VERSIONS_MANIFEST_URL } from "../utils/constants";
|
||||
import {
|
||||
GITHUB_VERSIONS_MANIFEST_URL,
|
||||
VERSIONS_MANIFEST_URL,
|
||||
} from "../utils/constants";
|
||||
import { fetch } from "../utils/fetch";
|
||||
import * as log from "../utils/logging";
|
||||
import { selectDefaultVariant } from "./variant-selection";
|
||||
@@ -167,6 +170,20 @@ export function clearManifestCache(manifestUrl?: string): void {
|
||||
}
|
||||
|
||||
async function fetchManifestResponse(manifestUrl: string) {
|
||||
try {
|
||||
return await fetchManifestResponseFromUrl(manifestUrl);
|
||||
} catch (error) {
|
||||
if (manifestUrl !== VERSIONS_MANIFEST_URL) {
|
||||
throw error;
|
||||
}
|
||||
log.info(
|
||||
`Failed to fetch manifest from Astral mirror, falling back to GitHub: ${(error as Error).message}`,
|
||||
);
|
||||
return await fetchManifestResponseFromUrl(GITHUB_VERSIONS_MANIFEST_URL);
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchManifestResponseFromUrl(manifestUrl: string) {
|
||||
let response: Awaited<ReturnType<typeof fetch>> | undefined;
|
||||
for (let attempt = 1; attempt <= MANIFEST_FETCH_ATTEMPTS; attempt++) {
|
||||
log.info(`Fetching manifest data from ${manifestUrl} ...`);
|
||||
|
||||
@@ -2,6 +2,8 @@ export const TOOL_CACHE_NAME = "uv";
|
||||
export const STATE_UV_PATH = "uv-path";
|
||||
export const STATE_UV_VERSION = "uv-version";
|
||||
export const VERSIONS_MANIFEST_URL =
|
||||
"https://releases.astral.sh/github/versions/main/v1/uv.ndjson";
|
||||
export const GITHUB_VERSIONS_MANIFEST_URL =
|
||||
"https://raw.githubusercontent.com/astral-sh/versions/main/v1/uv.ndjson";
|
||||
|
||||
/** GitHub Releases URL prefix for uv artifacts. */
|
||||
|
||||
Reference in New Issue
Block a user