2024-09-05 08:06:45 -04:00
|
|
|
import * as core from "@actions/core";
|
|
|
|
import * as tc from "@actions/tool-cache";
|
|
|
|
import * as path from "path";
|
2024-09-07 14:13:50 +02:00
|
|
|
import { OWNER, REPO, TOOL_CACHE_NAME } from "../utils/constants";
|
2024-09-05 08:06:45 -04:00
|
|
|
import { Architecture, Platform } from "../utils/platforms";
|
|
|
|
import { validateChecksum } from "./checksum/checksum";
|
2024-08-23 23:58:26 +02:00
|
|
|
|
|
|
|
export function tryGetFromToolCache(
|
|
|
|
arch: Architecture,
|
2024-09-05 08:06:45 -04:00
|
|
|
version: string,
|
2024-08-23 23:58:26 +02:00
|
|
|
): string | undefined {
|
2024-09-05 08:06:45 -04:00
|
|
|
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,
|
2024-09-05 08:06:45 -04:00
|
|
|
githubToken: string | undefined,
|
2024-08-23 23:58:26 +02:00
|
|
|
): Promise<string> {
|
2024-09-05 08:06:45 -04:00
|
|
|
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 {
|
2024-09-05 08:06:45 -04:00
|
|
|
downloadUrl += ".tar.gz";
|
2024-08-23 23:58:26 +02:00
|
|
|
}
|
2024-09-05 08:06:45 -04: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,
|
2024-09-05 08:06:45 -04:00
|
|
|
githubToken,
|
|
|
|
);
|
|
|
|
await validateChecksum(checkSum, downloadPath, arch, platform, version);
|
2024-08-23 23:58:26 +02:00
|
|
|
|
2024-09-05 08:06:45 -04:00
|
|
|
let uvDir: string;
|
|
|
|
if (platform === "pc-windows-msvc") {
|
|
|
|
uvDir = await tc.extractZip(downloadPath);
|
2024-08-24 09:20:02 +02:00
|
|
|
// On windows extracting the zip does not create an intermediate directory
|
2024-08-23 23:58:26 +02:00
|
|
|
} else {
|
2024-09-05 08:06:45 -04:00
|
|
|
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
|
|
|
|
2024-09-05 08:06:45 -04:00
|
|
|
return await tc.cacheDir(uvDir, TOOL_CACHE_NAME, version, arch);
|
2024-08-23 23:58:26 +02:00
|
|
|
}
|