mirror of
https://github.com/astral-sh/setup-uv.git
synced 2025-01-31 22:41:27 +08:00
Cache in tool cache
This commit is contained in:
parent
dccd08dfe5
commit
67efd41074
25
dist/setup/index.js
generated
vendored
25
dist/setup/index.js
generated
vendored
@ -85423,7 +85423,8 @@ function downloadLatest(platform, arch, checkSum, githubToken) {
|
|||||||
}
|
}
|
||||||
const version = yield getVersion(uvExecutablePath);
|
const version = yield getVersion(uvExecutablePath);
|
||||||
yield (0, checksum_1.validateChecksum)(checkSum, downloadPath, arch, platform, version);
|
yield (0, checksum_1.validateChecksum)(checkSum, downloadPath, arch, platform, version);
|
||||||
return { downloadDir, version };
|
const cachedToolDir = yield tc.cacheDir(downloadPath, utils_1.TOOL_CACHE_NAME, version, arch);
|
||||||
|
return { cachedToolDir, version };
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.downloadLatest = downloadLatest;
|
exports.downloadLatest = downloadLatest;
|
||||||
@ -85525,7 +85526,7 @@ function downloadVersion(platform, arch, version, checkSum, githubToken) {
|
|||||||
else {
|
else {
|
||||||
tc.extractTar(downloadPath);
|
tc.extractTar(downloadPath);
|
||||||
}
|
}
|
||||||
return downloadPath;
|
return yield tc.cacheDir(downloadPath, utils_1.TOOL_CACHE_NAME, version, arch);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.downloadVersion = downloadVersion;
|
exports.downloadVersion = downloadVersion;
|
||||||
@ -85589,11 +85590,14 @@ function run() {
|
|||||||
if (arch === undefined) {
|
if (arch === undefined) {
|
||||||
throw new Error(`Unsupported architecture: ${process.arch}`);
|
throw new Error(`Unsupported architecture: ${process.arch}`);
|
||||||
}
|
}
|
||||||
const installedVersion = yield setupUv(platform, arch, inputs_1.version, inputs_1.checkSum, inputs_1.githubToken);
|
const setupResult = yield setupUv(platform, arch, inputs_1.version, inputs_1.checkSum, inputs_1.githubToken);
|
||||||
|
addUvToPath(setupResult.uvDir);
|
||||||
|
core.setOutput('uv-version', inputs_1.version);
|
||||||
|
core.info(`Successfully installed uv version ${inputs_1.version}`);
|
||||||
addMatchers();
|
addMatchers();
|
||||||
setCacheDir(inputs_1.cacheLocalPath);
|
setCacheDir(inputs_1.cacheLocalPath);
|
||||||
if (inputs_1.enableCache) {
|
if (inputs_1.enableCache) {
|
||||||
yield (0, restore_cache_1.restoreCache)(installedVersion);
|
yield (0, restore_cache_1.restoreCache)(setupResult.version);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
@ -85605,26 +85609,23 @@ function run() {
|
|||||||
function setupUv(platform, arch, versionInput, checkSum, githubToken) {
|
function setupUv(platform, arch, versionInput, checkSum, githubToken) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
let installedPath;
|
let installedPath;
|
||||||
let downloadDir;
|
let cachedToolDir;
|
||||||
let version;
|
let version;
|
||||||
if (versionInput === 'latest') {
|
if (versionInput === 'latest') {
|
||||||
const result = yield (0, download_latest_1.downloadLatest)(platform, arch, checkSum, githubToken);
|
const result = yield (0, download_latest_1.downloadLatest)(platform, arch, checkSum, githubToken);
|
||||||
version = result.version;
|
version = result.version;
|
||||||
downloadDir = result.downloadDir;
|
cachedToolDir = result.cachedToolDir;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
version = versionInput;
|
version = versionInput;
|
||||||
installedPath = (0, download_version_1.tryGetFromToolCache)(arch, versionInput);
|
installedPath = (0, download_version_1.tryGetFromToolCache)(arch, versionInput);
|
||||||
if (installedPath) {
|
if (installedPath) {
|
||||||
core.info(`Found uv in tool-cache for ${versionInput}`);
|
core.info(`Found uv in tool-cache for ${versionInput}`);
|
||||||
return version;
|
return { uvDir: installedPath, version };
|
||||||
}
|
}
|
||||||
downloadDir = yield (0, download_version_1.downloadVersion)(platform, arch, versionInput, checkSum, githubToken);
|
cachedToolDir = yield (0, download_version_1.downloadVersion)(platform, arch, versionInput, checkSum, githubToken);
|
||||||
}
|
}
|
||||||
addUvToPath(downloadDir);
|
return { uvDir: cachedToolDir, version };
|
||||||
core.setOutput('uv-version', version);
|
|
||||||
core.info(`Successfully installed uv version ${version}`);
|
|
||||||
return version;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function addUvToPath(cachedPath) {
|
function addUvToPath(cachedPath) {
|
||||||
|
@ -4,14 +4,14 @@ import * as path from 'path'
|
|||||||
import * as exec from '@actions/exec'
|
import * as exec from '@actions/exec'
|
||||||
import {Architecture, Platform} from '../utils/platforms'
|
import {Architecture, Platform} from '../utils/platforms'
|
||||||
import {validateChecksum} from './checksum/checksum'
|
import {validateChecksum} from './checksum/checksum'
|
||||||
import {OWNER, REPO} from '../utils/utils'
|
import {OWNER, REPO, TOOL_CACHE_NAME} from '../utils/utils'
|
||||||
|
|
||||||
export async function downloadLatest(
|
export async function downloadLatest(
|
||||||
platform: Platform,
|
platform: Platform,
|
||||||
arch: Architecture,
|
arch: Architecture,
|
||||||
checkSum: string | undefined,
|
checkSum: string | undefined,
|
||||||
githubToken: string | undefined
|
githubToken: string | undefined
|
||||||
): Promise<{downloadDir: string; version: string}> {
|
): Promise<{cachedToolDir: string; version: string}> {
|
||||||
const binary = `uv-${arch}-${platform}`
|
const binary = `uv-${arch}-${platform}`
|
||||||
let downloadUrl = `https://github.com/${OWNER}/${REPO}/releases/latest/download/${binary}`
|
let downloadUrl = `https://github.com/${OWNER}/${REPO}/releases/latest/download/${binary}`
|
||||||
if (platform === 'pc-windows-msvc') {
|
if (platform === 'pc-windows-msvc') {
|
||||||
@ -38,8 +38,14 @@ export async function downloadLatest(
|
|||||||
}
|
}
|
||||||
const version = await getVersion(uvExecutablePath)
|
const version = await getVersion(uvExecutablePath)
|
||||||
await validateChecksum(checkSum, downloadPath, arch, platform, version)
|
await validateChecksum(checkSum, downloadPath, arch, platform, version)
|
||||||
|
const cachedToolDir = await tc.cacheDir(
|
||||||
|
downloadPath,
|
||||||
|
TOOL_CACHE_NAME,
|
||||||
|
version,
|
||||||
|
arch
|
||||||
|
)
|
||||||
|
|
||||||
return {downloadDir, version}
|
return {cachedToolDir, version}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getVersion(uvExecutablePath: string): Promise<string> {
|
async function getVersion(uvExecutablePath: string): Promise<string> {
|
||||||
|
@ -44,5 +44,5 @@ export async function downloadVersion(
|
|||||||
} else {
|
} else {
|
||||||
tc.extractTar(downloadPath)
|
tc.extractTar(downloadPath)
|
||||||
}
|
}
|
||||||
return downloadPath
|
return await tc.cacheDir(downloadPath, TOOL_CACHE_NAME, version, arch)
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ async function run(): Promise<void> {
|
|||||||
if (arch === undefined) {
|
if (arch === undefined) {
|
||||||
throw new Error(`Unsupported architecture: ${process.arch}`)
|
throw new Error(`Unsupported architecture: ${process.arch}`)
|
||||||
}
|
}
|
||||||
const installedVersion = await setupUv(
|
const setupResult = await setupUv(
|
||||||
platform,
|
platform,
|
||||||
arch,
|
arch,
|
||||||
version,
|
version,
|
||||||
@ -32,11 +32,15 @@ async function run(): Promise<void> {
|
|||||||
githubToken
|
githubToken
|
||||||
)
|
)
|
||||||
|
|
||||||
|
addUvToPath(setupResult.uvDir)
|
||||||
|
core.setOutput('uv-version', version)
|
||||||
|
core.info(`Successfully installed uv version ${version}`)
|
||||||
|
|
||||||
addMatchers()
|
addMatchers()
|
||||||
setCacheDir(cacheLocalPath)
|
setCacheDir(cacheLocalPath)
|
||||||
|
|
||||||
if (enableCache) {
|
if (enableCache) {
|
||||||
await restoreCache(installedVersion)
|
await restoreCache(setupResult.version)
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
core.setFailed((err as Error).message)
|
core.setFailed((err as Error).message)
|
||||||
@ -50,22 +54,22 @@ async function setupUv(
|
|||||||
versionInput: string,
|
versionInput: string,
|
||||||
checkSum: string | undefined,
|
checkSum: string | undefined,
|
||||||
githubToken: string | undefined
|
githubToken: string | undefined
|
||||||
): Promise<string> {
|
): Promise<{uvDir: string; version: string}> {
|
||||||
let installedPath: string | undefined
|
let installedPath: string | undefined
|
||||||
let downloadDir: string
|
let cachedToolDir: string
|
||||||
let version: string
|
let version: string
|
||||||
if (versionInput === 'latest') {
|
if (versionInput === 'latest') {
|
||||||
const result = await downloadLatest(platform, arch, checkSum, githubToken)
|
const result = await downloadLatest(platform, arch, checkSum, githubToken)
|
||||||
version = result.version
|
version = result.version
|
||||||
downloadDir = result.downloadDir
|
cachedToolDir = result.cachedToolDir
|
||||||
} else {
|
} else {
|
||||||
version = versionInput
|
version = versionInput
|
||||||
installedPath = tryGetFromToolCache(arch, versionInput)
|
installedPath = tryGetFromToolCache(arch, versionInput)
|
||||||
if (installedPath) {
|
if (installedPath) {
|
||||||
core.info(`Found uv in tool-cache for ${versionInput}`)
|
core.info(`Found uv in tool-cache for ${versionInput}`)
|
||||||
return version
|
return {uvDir: installedPath, version}
|
||||||
}
|
}
|
||||||
downloadDir = await downloadVersion(
|
cachedToolDir = await downloadVersion(
|
||||||
platform,
|
platform,
|
||||||
arch,
|
arch,
|
||||||
versionInput,
|
versionInput,
|
||||||
@ -74,10 +78,7 @@ async function setupUv(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
addUvToPath(downloadDir)
|
return {uvDir: cachedToolDir, version}
|
||||||
core.setOutput('uv-version', version)
|
|
||||||
core.info(`Successfully installed uv version ${version}`)
|
|
||||||
return version
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function addUvToPath(cachedPath: string): void {
|
function addUvToPath(cachedPath: string): void {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user