setup-uv/src/download/download-version.ts

52 lines
1.7 KiB
TypeScript
Raw Normal View History

import * as core from "@actions/core";
import * as tc from "@actions/tool-cache";
import * as path from "path";
import { OWNER, REPO, TOOL_CACHE_NAME } from "../utils/constants";
import { Architecture, Platform } from "../utils/platforms";
import { validateChecksum } from "./checksum/checksum";
2024-08-23 23:58:26 +02:00
export function tryGetFromToolCache(
arch: Architecture,
version: string,
2024-08-23 23:58:26 +02:00
): string | undefined {
core.debug(`Trying to get uv from tool cache for ${version}...`);
const cachedVersions = tc.findAllVersions(TOOL_CACHE_NAME, arch);
core.debug(`Cached versions: ${cachedVersions}`);
return tc.find(TOOL_CACHE_NAME, version, arch);
2024-08-23 23:58:26 +02:00
}
export async function downloadVersion(
platform: Platform,
arch: Architecture,
version: string,
checkSum: string | undefined,
githubToken: string | undefined,
2024-08-23 23:58:26 +02:00
): Promise<string> {
const artifact = `uv-${arch}-${platform}`;
let downloadUrl = `https://github.com/${OWNER}/${REPO}/releases/download/${version}/${artifact}`;
if (platform === "pc-windows-msvc") {
downloadUrl += ".zip";
2024-08-23 23:58:26 +02:00
} else {
downloadUrl += ".tar.gz";
2024-08-23 23:58:26 +02:00
}
core.info(`Downloading uv from "${downloadUrl}" ...`);
2024-08-23 23:58:26 +02:00
const downloadPath = await tc.downloadTool(
downloadUrl,
2024-08-24 00:27:50 +02:00
undefined,
githubToken,
);
await validateChecksum(checkSum, downloadPath, arch, platform, version);
2024-08-23 23:58:26 +02:00
let uvDir: string;
if (platform === "pc-windows-msvc") {
uvDir = await tc.extractZip(downloadPath);
// On windows extracting the zip does not create an intermediate directory
2024-08-23 23:58:26 +02:00
} else {
const extractedDir = await tc.extractTar(downloadPath);
uvDir = path.join(extractedDir, artifact);
2024-08-23 23:58:26 +02:00
}
2024-08-24 00:40:34 +02:00
return await tc.cacheDir(uvDir, TOOL_CACHE_NAME, version, arch);
2024-08-23 23:58:26 +02:00
}