feat: added use-mirror parameter

This commit is contained in:
Joe Crowley 2026-04-08 17:18:04 +08:00
parent 7b222e12b6
commit c4b2130c2c
9 changed files with 57 additions and 3 deletions

View file

@ -119,6 +119,9 @@ Have a look under [Advanced Configuration](#advanced-configuration) for detailed
# Add problem matchers # Add problem matchers
add-problem-matchers: "true" add-problem-matchers: "true"
# Attempt to retrieve from the Astral mirror first or use Github releases
use-mirror: "true"
``` ```
### Outputs ### Outputs

View file

@ -121,6 +121,7 @@ describe("download-version", () => {
"0.9.26", "0.9.26",
undefined, undefined,
"token", "token",
true,
), ),
).rejects.toThrow("manifest unavailable"); ).rejects.toThrow("manifest unavailable");
@ -138,6 +139,7 @@ describe("download-version", () => {
"0.9.26", "0.9.26",
undefined, undefined,
"token", "token",
true,
), ),
).rejects.toThrow( ).rejects.toThrow(
"Could not find artifact for version 0.9.26, arch x86_64, platform unknown-linux-gnu in https://raw.githubusercontent.com/astral-sh/versions/main/v1/uv.ndjson .", "Could not find artifact for version 0.9.26, arch x86_64, platform unknown-linux-gnu in https://raw.githubusercontent.com/astral-sh/versions/main/v1/uv.ndjson .",
@ -160,6 +162,7 @@ describe("download-version", () => {
"0.9.26", "0.9.26",
undefined, undefined,
"token", "token",
true,
); );
expect(mockValidateChecksum).toHaveBeenCalledWith( expect(mockValidateChecksum).toHaveBeenCalledWith(
@ -185,6 +188,7 @@ describe("download-version", () => {
"0.9.26", "0.9.26",
undefined, undefined,
"token", "token",
true,
); );
expect(mockDownloadTool).toHaveBeenCalledWith( expect(mockDownloadTool).toHaveBeenCalledWith(
@ -194,6 +198,30 @@ describe("download-version", () => {
); );
}); });
it("doesn't rewrite GitHub Releases URLs to the Astral mirror if not use-mirror set", async () => {
mockGetArtifact.mockResolvedValue({
archiveFormat: "tar.gz",
checksum: "abc123",
downloadUrl:
"https://github.com/astral-sh/uv/releases/download/0.9.26/uv-x86_64-unknown-linux-gnu.tar.gz",
});
await downloadVersion(
"unknown-linux-gnu",
"x86_64",
"0.9.26",
undefined,
"token",
false,
);
expect(mockDownloadTool).toHaveBeenCalledWith(
"https://github.com/astral-sh/uv/releases/download/0.9.26/uv-x86_64-unknown-linux-gnu.tar.gz",
undefined,
"token",
);
});
it("does not rewrite non-GitHub URLs", async () => { it("does not rewrite non-GitHub URLs", async () => {
mockGetArtifact.mockResolvedValue({ mockGetArtifact.mockResolvedValue({
archiveFormat: "tar.gz", archiveFormat: "tar.gz",
@ -207,6 +235,7 @@ describe("download-version", () => {
"0.9.26", "0.9.26",
undefined, undefined,
"token", "token",
true,
); );
expect(mockDownloadTool).toHaveBeenCalledWith( expect(mockDownloadTool).toHaveBeenCalledWith(
@ -234,6 +263,7 @@ describe("download-version", () => {
"0.9.26", "0.9.26",
undefined, undefined,
"token", "token",
true,
); );
expect(mockDownloadTool).toHaveBeenCalledTimes(2); expect(mockDownloadTool).toHaveBeenCalledTimes(2);
@ -270,6 +300,7 @@ describe("download-version", () => {
"0.9.26", "0.9.26",
undefined, undefined,
"token", "token",
true,
), ),
).rejects.toThrow("download failed"); ).rejects.toThrow("download failed");
@ -289,6 +320,7 @@ describe("download-version", () => {
"0.9.26", "0.9.26",
"", "",
"token", "token",
true,
"https://example.com/custom.ndjson", "https://example.com/custom.ndjson",
); );
@ -314,6 +346,7 @@ describe("download-version", () => {
"0.9.26", "0.9.26",
"user-checksum", "user-checksum",
"token", "token",
true,
"https://example.com/custom.ndjson", "https://example.com/custom.ndjson",
); );

View file

@ -57,6 +57,8 @@ inputs:
allowed-values: allowed-values:
- highest - highest
- lowest - lowest
use-mirror:
type: boolean
outputs: outputs:
uv-version: uv-version:

View file

@ -83,6 +83,10 @@ inputs:
resolution-strategy: resolution-strategy:
description: "Resolution strategy to use when resolving version ranges. 'highest' uses the latest compatible version, 'lowest' uses the oldest compatible version." description: "Resolution strategy to use when resolving version ranges. 'highest' uses the latest compatible version, 'lowest' uses the oldest compatible version."
default: "highest" default: "highest"
use-mirror:
description: "Whether to attempt to download from Astral mirror first or use the Github releases artifacts."
default: true
outputs: outputs:
uv-version: uv-version:
description: "The installed uv version. Useful when using latest." description: "The installed uv version. Useful when using latest."

2
dist/save-cache/index.cjs generated vendored
View file

@ -62985,6 +62985,7 @@ function loadInputs() {
const manifestFile = getManifestFile(); const manifestFile = getManifestFile();
const addProblemMatchers = getInput("add-problem-matchers") === "true"; const addProblemMatchers = getInput("add-problem-matchers") === "true";
const resolutionStrategy = getResolutionStrategy(); const resolutionStrategy = getResolutionStrategy();
const useMirror = getInput("use-mirror") === "true";
return { return {
activateEnvironment, activateEnvironment,
addProblemMatchers, addProblemMatchers,
@ -63006,6 +63007,7 @@ function loadInputs() {
saveCache: saveCache4, saveCache: saveCache4,
toolBinDir, toolBinDir,
toolDir, toolDir,
useMirror,
venvPath, venvPath,
version: version3, version: version3,
versionFile, versionFile,

7
dist/setup/index.cjs generated vendored
View file

@ -95702,7 +95702,7 @@ function tryGetFromToolCache(arch3, version3) {
const installedPath = find(TOOL_CACHE_NAME, resolvedVersion, arch3); const installedPath = find(TOOL_CACHE_NAME, resolvedVersion, arch3);
return { installedPath, version: resolvedVersion }; return { installedPath, version: resolvedVersion };
} }
async function downloadVersion(platform2, arch3, version3, checksum, githubToken, manifestUrl) { async function downloadVersion(platform2, arch3, version3, checksum, githubToken, useMirror, manifestUrl) {
const artifact = await getArtifact(version3, arch3, platform2, manifestUrl); const artifact = await getArtifact(version3, arch3, platform2, manifestUrl);
if (!artifact) { if (!artifact) {
throw new Error( throw new Error(
@ -95710,7 +95710,7 @@ async function downloadVersion(platform2, arch3, version3, checksum, githubToken
); );
} }
const resolvedChecksum = manifestUrl === void 0 ? checksum : resolveChecksum(checksum, artifact.checksum); const resolvedChecksum = manifestUrl === void 0 ? checksum : resolveChecksum(checksum, artifact.checksum);
const mirrorUrl = rewriteToMirror(artifact.downloadUrl); const mirrorUrl = useMirror ? rewriteToMirror(artifact.downloadUrl) : void 0;
const downloadUrl = mirrorUrl ?? artifact.downloadUrl; const downloadUrl = mirrorUrl ?? artifact.downloadUrl;
const downloadToken = mirrorUrl !== void 0 ? void 0 : githubToken; const downloadToken = mirrorUrl !== void 0 ? void 0 : githubToken;
try { try {
@ -96591,6 +96591,7 @@ function loadInputs() {
const manifestFile = getManifestFile(); const manifestFile = getManifestFile();
const addProblemMatchers = getInput("add-problem-matchers") === "true"; const addProblemMatchers = getInput("add-problem-matchers") === "true";
const resolutionStrategy = getResolutionStrategy(); const resolutionStrategy = getResolutionStrategy();
const useMirror = getInput("use-mirror") === "true";
return { return {
activateEnvironment: activateEnvironment2, activateEnvironment: activateEnvironment2,
addProblemMatchers, addProblemMatchers,
@ -96612,6 +96613,7 @@ function loadInputs() {
saveCache: saveCache2, saveCache: saveCache2,
toolBinDir, toolBinDir,
toolDir, toolDir,
useMirror,
venvPath, venvPath,
version: version3, version: version3,
versionFile, versionFile,
@ -96985,6 +96987,7 @@ async function setupUv(inputs, platform2, arch3) {
resolvedVersion, resolvedVersion,
inputs.checksum, inputs.checksum,
inputs.githubToken, inputs.githubToken,
inputs.useMirror,
inputs.manifestFile inputs.manifestFile
); );
return { return {

View file

@ -35,6 +35,7 @@ export async function downloadVersion(
version: string, version: string,
checksum: string | undefined, checksum: string | undefined,
githubToken: string, githubToken: string,
useMirror: boolean,
manifestUrl?: string, manifestUrl?: string,
): Promise<{ version: string; cachedToolDir: string }> { ): Promise<{ version: string; cachedToolDir: string }> {
const artifact = await getArtifact(version, arch, platform, manifestUrl); const artifact = await getArtifact(version, arch, platform, manifestUrl);
@ -52,7 +53,9 @@ export async function downloadVersion(
? checksum ? checksum
: resolveChecksum(checksum, artifact.checksum); : resolveChecksum(checksum, artifact.checksum);
const mirrorUrl = rewriteToMirror(artifact.downloadUrl); const mirrorUrl = useMirror
? rewriteToMirror(artifact.downloadUrl)
: undefined;
const downloadUrl = mirrorUrl ?? artifact.downloadUrl; const downloadUrl = mirrorUrl ?? artifact.downloadUrl;
// Don't send the GitHub token to the Astral mirror. // Don't send the GitHub token to the Astral mirror.
const downloadToken = mirrorUrl !== undefined ? undefined : githubToken; const downloadToken = mirrorUrl !== undefined ? undefined : githubToken;

View file

@ -128,6 +128,7 @@ async function setupUv(
resolvedVersion, resolvedVersion,
inputs.checksum, inputs.checksum,
inputs.githubToken, inputs.githubToken,
inputs.useMirror,
inputs.manifestFile, inputs.manifestFile,
); );

View file

@ -41,6 +41,7 @@ export interface SetupInputs {
manifestFile?: string; manifestFile?: string;
addProblemMatchers: boolean; addProblemMatchers: boolean;
resolutionStrategy: ResolutionStrategy; resolutionStrategy: ResolutionStrategy;
useMirror: boolean;
} }
export function loadInputs(): SetupInputs { export function loadInputs(): SetupInputs {
@ -73,6 +74,7 @@ export function loadInputs(): SetupInputs {
const manifestFile = getManifestFile(); const manifestFile = getManifestFile();
const addProblemMatchers = core.getInput("add-problem-matchers") === "true"; const addProblemMatchers = core.getInput("add-problem-matchers") === "true";
const resolutionStrategy = getResolutionStrategy(); const resolutionStrategy = getResolutionStrategy();
const useMirror = core.getInput("use-mirror") === "true";
return { return {
activateEnvironment, activateEnvironment,
@ -95,6 +97,7 @@ export function loadInputs(): SetupInputs {
saveCache, saveCache,
toolBinDir, toolBinDir,
toolDir, toolDir,
useMirror,
venvPath, venvPath,
version, version,
versionFile, versionFile,