Skip to content

Commit

Permalink
Cache in tool cache
Browse files Browse the repository at this point in the history
  • Loading branch information
eifinger committed Aug 23, 2024
1 parent dccd08d commit 67efd41
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 27 deletions.
25 changes: 13 additions & 12 deletions dist/setup/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions src/download/download-latest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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<string> {
Expand Down
2 changes: 1 addition & 1 deletion src/download/download-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ export async function downloadVersion(
} else {
tc.extractTar(downloadPath)
}
return downloadPath
return await tc.cacheDir(downloadPath, TOOL_CACHE_NAME, version, arch)
}
23 changes: 12 additions & 11 deletions src/setup-uv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,23 @@ async function run(): Promise<void> {
if (arch === undefined) {
throw new Error(`Unsupported architecture: ${process.arch}`)
}
const installedVersion = await setupUv(
const setupResult = await setupUv(
platform,
arch,
version,
checkSum,
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)
Expand All @@ -50,22 +54,22 @@ async function setupUv(
versionInput: string,
checkSum: string | undefined,
githubToken: string | undefined
): Promise<string> {
): 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,
Expand All @@ -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 {
Expand Down

0 comments on commit 67efd41

Please sign in to comment.