mirror of
https://github.com/astral-sh/ruff-action.git
synced 2026-08-08 18:27:03 +00:00
Add option to skip Astral mirror downloads (#387)
## Summary - add `download-from-astral-mirror` input defaulting to `true` - skip mirror URL rewriting and download directly from GitHub Releases when disabled - document the input and add unit coverage Fixes #384 Refs: pi-session 019f31bc-bd1c-7276-9b4e-9734fa0aa367 ## Testing - npm run build - npm run check - npm run test:unit
This commit is contained in:
@@ -35,6 +35,7 @@ export async function downloadVersion(
|
||||
checksum: string | undefined,
|
||||
githubToken: string,
|
||||
manifestUrl?: string,
|
||||
downloadFromAstralMirror = true,
|
||||
): Promise<{ version: string; cachedToolDir: string }> {
|
||||
const artifact = await getArtifact(version, arch, platform, manifestUrl);
|
||||
|
||||
@@ -57,6 +58,7 @@ export async function downloadVersion(
|
||||
arch,
|
||||
version,
|
||||
getDownloadToken(artifact.downloadUrl, githubToken),
|
||||
downloadFromAstralMirror,
|
||||
);
|
||||
await validateChecksum(
|
||||
resolvedChecksum,
|
||||
@@ -83,6 +85,10 @@ export async function downloadVersion(
|
||||
return { cachedToolDir, version };
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewrite a GitHub Releases URL to the Astral mirror.
|
||||
* Returns `undefined` if the URL does not match the expected GitHub prefix.
|
||||
*/
|
||||
export function rewriteToMirror(url: string): string | undefined {
|
||||
if (!url.startsWith(GITHUB_RELEASES_PREFIX)) {
|
||||
return undefined;
|
||||
@@ -97,8 +103,11 @@ async function downloadArtifact(
|
||||
arch: Architecture,
|
||||
version: string,
|
||||
githubToken: string | undefined,
|
||||
downloadFromAstralMirror: boolean,
|
||||
): Promise<string> {
|
||||
const mirrorUrl = rewriteToMirror(downloadUrl);
|
||||
const mirrorUrl = downloadFromAstralMirror
|
||||
? rewriteToMirror(downloadUrl)
|
||||
: undefined;
|
||||
const resolvedDownloadUrl = mirrorUrl ?? downloadUrl;
|
||||
|
||||
try {
|
||||
|
||||
+10
-1
@@ -9,6 +9,7 @@ import {
|
||||
import {
|
||||
args,
|
||||
checkSum,
|
||||
downloadFromAstralMirror,
|
||||
githubToken,
|
||||
manifestFile,
|
||||
src,
|
||||
@@ -39,7 +40,13 @@ async function run(): Promise<void> {
|
||||
if (arch === undefined) {
|
||||
throw new Error(`Unsupported architecture: ${process.arch}`);
|
||||
}
|
||||
const setupResult = await setupRuff(platform, arch, checkSum, githubToken);
|
||||
const setupResult = await setupRuff(
|
||||
platform,
|
||||
arch,
|
||||
checkSum,
|
||||
githubToken,
|
||||
downloadFromAstralMirror,
|
||||
);
|
||||
|
||||
addRuffToPath(setupResult.ruffDir);
|
||||
setOutputFormat();
|
||||
@@ -60,6 +67,7 @@ async function setupRuff(
|
||||
arch: Architecture,
|
||||
checkSum: string | undefined,
|
||||
githubToken: string,
|
||||
downloadFromAstralMirror: boolean,
|
||||
): Promise<{ ruffDir: string; version: string }> {
|
||||
const resolvedVersion = await determineVersion();
|
||||
const manifestUrl = manifestFile || undefined;
|
||||
@@ -84,6 +92,7 @@ async function setupRuff(
|
||||
checkSum,
|
||||
githubToken,
|
||||
manifestUrl,
|
||||
downloadFromAstralMirror,
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
@@ -7,3 +7,14 @@ export const args = core.getInput("args");
|
||||
export const src = core.getInput("src");
|
||||
export const versionFile = core.getInput("version-file");
|
||||
export const manifestFile = core.getInput("manifest-file");
|
||||
export const downloadFromAstralMirror = getBooleanInput(
|
||||
"download-from-astral-mirror",
|
||||
true,
|
||||
);
|
||||
|
||||
function getBooleanInput(name: string, defaultValue: boolean): boolean {
|
||||
if (core.getInput(name) === "") {
|
||||
return defaultValue;
|
||||
}
|
||||
return core.getBooleanInput(name);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user