mirror of
https://github.com/astral-sh/setup-uv.git
synced 2025-05-18 07:04:45 +00:00
Change Prettier settings (#36)
## Summary I know this is a little tedious but I'd prefer to use the same settings as in Ruff.
This commit is contained in:
parent
1785c7bde0
commit
182c9c7e92
32 changed files with 5536 additions and 5497 deletions
|
@ -1,55 +1,55 @@
|
|||
import * as fs from 'fs'
|
||||
import * as crypto from 'crypto'
|
||||
import * as fs from "fs";
|
||||
import * as crypto from "crypto";
|
||||
|
||||
import * as core from '@actions/core'
|
||||
import {KNOWN_CHECKSUMS} from './known-checksums'
|
||||
import {Architecture, Platform} from '../../utils/platforms'
|
||||
import * as core from "@actions/core";
|
||||
import { KNOWN_CHECKSUMS } from "./known-checksums";
|
||||
import { Architecture, Platform } from "../../utils/platforms";
|
||||
|
||||
export async function validateChecksum(
|
||||
checkSum: string | undefined,
|
||||
downloadPath: string,
|
||||
arch: Architecture,
|
||||
platform: Platform,
|
||||
version: string
|
||||
version: string,
|
||||
): Promise<void> {
|
||||
let isValid = true
|
||||
if (checkSum !== undefined && checkSum !== '') {
|
||||
isValid = await validateFileCheckSum(downloadPath, checkSum)
|
||||
let isValid = true;
|
||||
if (checkSum !== undefined && checkSum !== "") {
|
||||
isValid = await validateFileCheckSum(downloadPath, checkSum);
|
||||
} else {
|
||||
core.debug(`Checksum not provided. Checking known checksums.`)
|
||||
const key = `${arch}-${platform}-${version}`
|
||||
core.debug(`Checksum not provided. Checking known checksums.`);
|
||||
const key = `${arch}-${platform}-${version}`;
|
||||
if (key in KNOWN_CHECKSUMS) {
|
||||
const knownChecksum = KNOWN_CHECKSUMS[`${arch}-${platform}-${version}`]
|
||||
core.debug(`Checking checksum for ${arch}-${platform}-${version}.`)
|
||||
isValid = await validateFileCheckSum(downloadPath, knownChecksum)
|
||||
const knownChecksum = KNOWN_CHECKSUMS[`${arch}-${platform}-${version}`];
|
||||
core.debug(`Checking checksum for ${arch}-${platform}-${version}.`);
|
||||
isValid = await validateFileCheckSum(downloadPath, knownChecksum);
|
||||
} else {
|
||||
core.debug(`No known checksum found for ${key}.`)
|
||||
core.debug(`No known checksum found for ${key}.`);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isValid) {
|
||||
throw new Error(`Checksum for ${downloadPath} did not match ${checkSum}.`)
|
||||
throw new Error(`Checksum for ${downloadPath} did not match ${checkSum}.`);
|
||||
}
|
||||
core.debug(`Checksum for ${downloadPath} is valid.`)
|
||||
core.debug(`Checksum for ${downloadPath} is valid.`);
|
||||
}
|
||||
|
||||
async function validateFileCheckSum(
|
||||
filePath: string,
|
||||
expected: string
|
||||
expected: string,
|
||||
): Promise<boolean> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const hash = crypto.createHash('sha256')
|
||||
const stream = fs.createReadStream(filePath)
|
||||
stream.on('error', err => reject(err))
|
||||
stream.on('data', chunk => hash.update(chunk))
|
||||
stream.on('end', () => {
|
||||
const actual = hash.digest('hex')
|
||||
resolve(actual === expected)
|
||||
})
|
||||
})
|
||||
const hash = crypto.createHash("sha256");
|
||||
const stream = fs.createReadStream(filePath);
|
||||
stream.on("error", (err) => reject(err));
|
||||
stream.on("data", (chunk) => hash.update(chunk));
|
||||
stream.on("end", () => {
|
||||
const actual = hash.digest("hex");
|
||||
resolve(actual === expected);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function isknownVersion(version: string): boolean {
|
||||
const pattern = new RegExp(`^.*-.*-${version}$`)
|
||||
return Object.keys(KNOWN_CHECKSUMS).some(key => pattern.test(key))
|
||||
const pattern = new RegExp(`^.*-.*-${version}$`);
|
||||
return Object.keys(KNOWN_CHECKSUMS).some((key) => pattern.test(key));
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,39 +1,39 @@
|
|||
import {promises as fs} from 'fs'
|
||||
import * as tc from '@actions/tool-cache'
|
||||
import { promises as fs } from "fs";
|
||||
import * as tc from "@actions/tool-cache";
|
||||
export async function updateChecksums(
|
||||
filePath: string,
|
||||
downloadUrls: string[]
|
||||
downloadUrls: string[],
|
||||
): Promise<void> {
|
||||
await fs.rm(filePath)
|
||||
await fs.rm(filePath);
|
||||
await fs.appendFile(
|
||||
filePath,
|
||||
'// AUTOGENERATED_DO_NOT_EDIT\nexport const KNOWN_CHECKSUMS: {[key: string]: string} = {\n'
|
||||
)
|
||||
let firstLine = true
|
||||
"// AUTOGENERATED_DO_NOT_EDIT\nexport const KNOWN_CHECKSUMS: {[key: string]: string} = {\n",
|
||||
);
|
||||
let firstLine = true;
|
||||
for (const downloadUrl of downloadUrls) {
|
||||
const content = await downloadAssetContent(downloadUrl)
|
||||
const checksum = content.split(' ')[0].trim()
|
||||
const key = getKey(downloadUrl)
|
||||
const content = await downloadAssetContent(downloadUrl);
|
||||
const checksum = content.split(" ")[0].trim();
|
||||
const key = getKey(downloadUrl);
|
||||
if (!firstLine) {
|
||||
await fs.appendFile(filePath, ',\n')
|
||||
await fs.appendFile(filePath, ",\n");
|
||||
}
|
||||
await fs.appendFile(filePath, ` '${key}':\n '${checksum}'`)
|
||||
firstLine = false
|
||||
await fs.appendFile(filePath, ` '${key}':\n '${checksum}'`);
|
||||
firstLine = false;
|
||||
}
|
||||
await fs.appendFile(filePath, '}\n')
|
||||
await fs.appendFile(filePath, "}\n");
|
||||
}
|
||||
|
||||
function getKey(downloadUrl: string): string {
|
||||
// https://github.com/astral-sh/uv/releases/download/0.3.2/uv-aarch64-apple-darwin.tar.gz.sha256
|
||||
const parts = downloadUrl.split('/')
|
||||
const fileName = parts[parts.length - 1]
|
||||
const name = fileName.split('.')[0].split('uv-')[1]
|
||||
const version = parts[parts.length - 2]
|
||||
return `${name}-${version}`
|
||||
const parts = downloadUrl.split("/");
|
||||
const fileName = parts[parts.length - 1];
|
||||
const name = fileName.split(".")[0].split("uv-")[1];
|
||||
const version = parts[parts.length - 2];
|
||||
return `${name}-${version}`;
|
||||
}
|
||||
|
||||
async function downloadAssetContent(downloadUrl: string): Promise<string> {
|
||||
const downloadPath = await tc.downloadTool(downloadUrl)
|
||||
const content = await fs.readFile(downloadPath, 'utf8')
|
||||
return content
|
||||
const downloadPath = await tc.downloadTool(downloadUrl);
|
||||
const content = await fs.readFile(downloadPath, "utf8");
|
||||
return content;
|
||||
}
|
||||
|
|
|
@ -1,47 +1,52 @@
|
|||
import * as core from '@actions/core'
|
||||
import * as tc from '@actions/tool-cache'
|
||||
import * as exec from '@actions/exec'
|
||||
import * as path from 'path'
|
||||
import {Architecture, Platform} from '../utils/platforms'
|
||||
import {validateChecksum} from './checksum/checksum'
|
||||
import {OWNER, REPO, TOOL_CACHE_NAME} from '../utils/utils'
|
||||
import * as core from "@actions/core";
|
||||
import * as tc from "@actions/tool-cache";
|
||||
import * as exec from "@actions/exec";
|
||||
import * as path from "path";
|
||||
import { Architecture, Platform } from "../utils/platforms";
|
||||
import { validateChecksum } from "./checksum/checksum";
|
||||
import { OWNER, REPO, TOOL_CACHE_NAME } from "../utils/utils";
|
||||
|
||||
export async function downloadLatest(
|
||||
platform: Platform,
|
||||
arch: Architecture,
|
||||
checkSum: string | undefined,
|
||||
githubToken: string | undefined
|
||||
): Promise<{cachedToolDir: string; version: string}> {
|
||||
const artifact = `uv-${arch}-${platform}`
|
||||
let downloadUrl = `https://github.com/${OWNER}/${REPO}/releases/latest/download/${artifact}`
|
||||
if (platform === 'pc-windows-msvc') {
|
||||
downloadUrl += '.zip'
|
||||
githubToken: string | undefined,
|
||||
): Promise<{ cachedToolDir: string; version: string }> {
|
||||
const artifact = `uv-${arch}-${platform}`;
|
||||
let downloadUrl = `https://github.com/${OWNER}/${REPO}/releases/latest/download/${artifact}`;
|
||||
if (platform === "pc-windows-msvc") {
|
||||
downloadUrl += ".zip";
|
||||
} else {
|
||||
downloadUrl += '.tar.gz'
|
||||
downloadUrl += ".tar.gz";
|
||||
}
|
||||
core.info(`Downloading uv from "${downloadUrl}" ...`)
|
||||
core.info(`Downloading uv from "${downloadUrl}" ...`);
|
||||
|
||||
const downloadPath = await tc.downloadTool(
|
||||
downloadUrl,
|
||||
undefined,
|
||||
githubToken
|
||||
)
|
||||
let uvExecutablePath: string
|
||||
let uvDir: string
|
||||
if (platform === 'pc-windows-msvc') {
|
||||
uvDir = await tc.extractZip(downloadPath)
|
||||
githubToken,
|
||||
);
|
||||
let uvExecutablePath: string;
|
||||
let uvDir: string;
|
||||
if (platform === "pc-windows-msvc") {
|
||||
uvDir = await tc.extractZip(downloadPath);
|
||||
// On windows extracting the zip does not create an intermediate directory
|
||||
uvExecutablePath = path.join(uvDir, 'uv.exe')
|
||||
uvExecutablePath = path.join(uvDir, "uv.exe");
|
||||
} else {
|
||||
const extractedDir = await tc.extractTar(downloadPath)
|
||||
uvDir = path.join(extractedDir, artifact)
|
||||
uvExecutablePath = path.join(uvDir, 'uv')
|
||||
const extractedDir = await tc.extractTar(downloadPath);
|
||||
uvDir = path.join(extractedDir, artifact);
|
||||
uvExecutablePath = path.join(uvDir, "uv");
|
||||
}
|
||||
const version = await getVersion(uvExecutablePath)
|
||||
await validateChecksum(checkSum, downloadPath, arch, platform, version)
|
||||
const cachedToolDir = await tc.cacheDir(uvDir, TOOL_CACHE_NAME, version, arch)
|
||||
const version = await getVersion(uvExecutablePath);
|
||||
await validateChecksum(checkSum, downloadPath, arch, platform, version);
|
||||
const cachedToolDir = await tc.cacheDir(
|
||||
uvDir,
|
||||
TOOL_CACHE_NAME,
|
||||
version,
|
||||
arch,
|
||||
);
|
||||
|
||||
return {cachedToolDir, version}
|
||||
return { cachedToolDir, version };
|
||||
}
|
||||
|
||||
async function getVersion(uvExecutablePath: string): Promise<string> {
|
||||
|
@ -50,17 +55,17 @@ async function getVersion(uvExecutablePath: string): Promise<string> {
|
|||
// uv 0.3.1 (be17d132a 2024-08-21)
|
||||
|
||||
const options: exec.ExecOptions = {
|
||||
silent: !core.isDebug()
|
||||
}
|
||||
const execArgs = ['--version']
|
||||
silent: !core.isDebug(),
|
||||
};
|
||||
const execArgs = ["--version"];
|
||||
|
||||
let output = ''
|
||||
let output = "";
|
||||
options.listeners = {
|
||||
stdout: (data: Buffer) => {
|
||||
output += data.toString()
|
||||
}
|
||||
}
|
||||
await exec.exec(uvExecutablePath, execArgs, options)
|
||||
const parts = output.split(' ')
|
||||
return parts[1]
|
||||
output += data.toString();
|
||||
},
|
||||
};
|
||||
await exec.exec(uvExecutablePath, execArgs, options);
|
||||
const parts = output.split(" ");
|
||||
return parts[1];
|
||||
}
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
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/utils'
|
||||
import {Architecture, Platform} from '../utils/platforms'
|
||||
import {validateChecksum} from './checksum/checksum'
|
||||
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/utils";
|
||||
import { Architecture, Platform } from "../utils/platforms";
|
||||
import { validateChecksum } from "./checksum/checksum";
|
||||
|
||||
export function tryGetFromToolCache(
|
||||
arch: Architecture,
|
||||
version: string
|
||||
version: string,
|
||||
): 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)
|
||||
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);
|
||||
}
|
||||
|
||||
export async function downloadVersion(
|
||||
|
@ -20,32 +20,32 @@ export async function downloadVersion(
|
|||
arch: Architecture,
|
||||
version: string,
|
||||
checkSum: string | undefined,
|
||||
githubToken: string | undefined
|
||||
githubToken: string | undefined,
|
||||
): 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'
|
||||
const artifact = `uv-${arch}-${platform}`;
|
||||
let downloadUrl = `https://github.com/${OWNER}/${REPO}/releases/download/${version}/${artifact}`;
|
||||
if (platform === "pc-windows-msvc") {
|
||||
downloadUrl += ".zip";
|
||||
} else {
|
||||
downloadUrl += '.tar.gz'
|
||||
downloadUrl += ".tar.gz";
|
||||
}
|
||||
core.info(`Downloading uv from "${downloadUrl}" ...`)
|
||||
core.info(`Downloading uv from "${downloadUrl}" ...`);
|
||||
|
||||
const downloadPath = await tc.downloadTool(
|
||||
downloadUrl,
|
||||
undefined,
|
||||
githubToken
|
||||
)
|
||||
await validateChecksum(checkSum, downloadPath, arch, platform, version)
|
||||
githubToken,
|
||||
);
|
||||
await validateChecksum(checkSum, downloadPath, arch, platform, version);
|
||||
|
||||
let uvDir: string
|
||||
if (platform === 'pc-windows-msvc') {
|
||||
uvDir = await tc.extractZip(downloadPath)
|
||||
let uvDir: string;
|
||||
if (platform === "pc-windows-msvc") {
|
||||
uvDir = await tc.extractZip(downloadPath);
|
||||
// On windows extracting the zip does not create an intermediate directory
|
||||
} else {
|
||||
const extractedDir = await tc.extractTar(downloadPath)
|
||||
uvDir = path.join(extractedDir, artifact)
|
||||
const extractedDir = await tc.extractTar(downloadPath);
|
||||
uvDir = path.join(extractedDir, artifact);
|
||||
}
|
||||
|
||||
return await tc.cacheDir(uvDir, TOOL_CACHE_NAME, version, arch)
|
||||
return await tc.cacheDir(uvDir, TOOL_CACHE_NAME, version, arch);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue