From 67efd41074bde9804bc497da524a1e7d1626b4db Mon Sep 17 00:00:00 2001 From: Kevin Stillhammer Date: Sat, 24 Aug 2024 00:14:50 +0200 Subject: [PATCH] Cache in tool cache --- dist/setup/index.js | Bin 3573222 -> 3573480 bytes src/download/download-latest.ts | 12 +++++++++--- src/download/download-version.ts | 2 +- src/setup-uv.ts | 23 ++++++++++++----------- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 8ac8c6a7e95eafbceb96eabfe196db60f12b37e6..b30598c32d91c48b2e5057157b9485d72dd4f4ad 100644 GIT binary patch delta 603 zcmaFXeT(r$?=8lL7RDB)7UmX~7Sq57TFfL7Wo#17R45&7UdR|7S$HD7WEd57R?r|7VQ?D7Tp%T zE&7pxX36<^#U%>KiOCtMDIxj!IWCz+3bqQBnW;G`3MI*UU>)rnO9I+QXFrn2Ns&Xk&8umy6-6#&gpN9^i??FveN~N^+l#9Y-3@W{vcO>ArG?o zlVu$hraw?;;hw%BRg`_YeKWhz^mBRopScjhHT`71{u31h9};{;U~fPI4;HG^H_qc$ zpDwqOhkg3*0{!>$)e2zeTLB$fT#}fRlL`%5s1K%J{J|=RY>{Y@e$Dg+QyAHW;W`o4 mP6vhgq}}2TpxWU8 delta 417 zcmaFSdyDZ|_btYT7RDB)7UmX~7Sq57TFfL7Wo#17R45&7UdR|7S$HD7WEd57R?r|7VQ?D7Tp%T zE&7pxf<>t%rA2uP)e0&3<#{>zi7DGJ2kJ`+^1!$Oi6t4+9|r2nY!67*-_0eEnO9tr zn3I#55|&z2oSC0DT`W&OXS!9s{yZ*()MPnF`RNbTS-7WfNEKzDZr{u> z@%kLoRSWf>z^!x1EK;ylC`v6Z%_-4?Sqc=Ko_Lr|eY)IA9`@Rd4HT(yH|-m5E}roArKn@u`v*v0I}(IuM)F)LI91qmj(a; diff --git a/src/download/download-latest.ts b/src/download/download-latest.ts index dcfd0a5..5690f77 100644 --- a/src/download/download-latest.ts +++ b/src/download/download-latest.ts @@ -4,14 +4,14 @@ import * as path from 'path' import * as exec from '@actions/exec' import {Architecture, Platform} from '../utils/platforms' import {validateChecksum} from './checksum/checksum' -import {OWNER, REPO} from '../utils/utils' +import {OWNER, REPO, TOOL_CACHE_NAME} from '../utils/utils' export async function downloadLatest( platform: Platform, arch: Architecture, checkSum: string | undefined, githubToken: string | undefined -): Promise<{downloadDir: string; version: string}> { +): Promise<{cachedToolDir: string; version: string}> { const binary = `uv-${arch}-${platform}` let downloadUrl = `https://github.com/${OWNER}/${REPO}/releases/latest/download/${binary}` if (platform === 'pc-windows-msvc') { @@ -38,8 +38,14 @@ export async function downloadLatest( } const version = await getVersion(uvExecutablePath) 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 { diff --git a/src/download/download-version.ts b/src/download/download-version.ts index 4ef9ffd..e136e49 100644 --- a/src/download/download-version.ts +++ b/src/download/download-version.ts @@ -44,5 +44,5 @@ export async function downloadVersion( } else { tc.extractTar(downloadPath) } - return downloadPath + return await tc.cacheDir(downloadPath, TOOL_CACHE_NAME, version, arch) } diff --git a/src/setup-uv.ts b/src/setup-uv.ts index 2bb4cdd..a986fc2 100644 --- a/src/setup-uv.ts +++ b/src/setup-uv.ts @@ -24,7 +24,7 @@ async function run(): Promise { if (arch === undefined) { throw new Error(`Unsupported architecture: ${process.arch}`) } - const installedVersion = await setupUv( + const setupResult = await setupUv( platform, arch, version, @@ -32,11 +32,15 @@ async function run(): Promise { githubToken ) + addUvToPath(setupResult.uvDir) + core.setOutput('uv-version', version) + core.info(`Successfully installed uv version ${version}`) + addMatchers() setCacheDir(cacheLocalPath) if (enableCache) { - await restoreCache(installedVersion) + await restoreCache(setupResult.version) } } catch (err) { core.setFailed((err as Error).message) @@ -50,22 +54,22 @@ async function setupUv( versionInput: string, checkSum: string | undefined, githubToken: string | undefined -): Promise { +): Promise<{uvDir: string; version: string}> { let installedPath: string | undefined - let downloadDir: string + let cachedToolDir: string let version: string if (versionInput === 'latest') { const result = await downloadLatest(platform, arch, checkSum, githubToken) version = result.version - downloadDir = result.downloadDir + cachedToolDir = result.cachedToolDir } else { version = versionInput installedPath = tryGetFromToolCache(arch, versionInput) if (installedPath) { core.info(`Found uv in tool-cache for ${versionInput}`) - return version + return {uvDir: installedPath, version} } - downloadDir = await downloadVersion( + cachedToolDir = await downloadVersion( platform, arch, versionInput, @@ -74,10 +78,7 @@ async function setupUv( ) } - addUvToPath(downloadDir) - core.setOutput('uv-version', version) - core.info(`Successfully installed uv version ${version}`) - return version + return {uvDir: cachedToolDir, version} } function addUvToPath(cachedPath: string): void {