Skip to content

Commit

Permalink
Cache correct dir
Browse files Browse the repository at this point in the history
  • Loading branch information
eifinger committed Aug 23, 2024
1 parent eb355a2 commit fd3ca5d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 41 deletions.
30 changes: 13 additions & 17 deletions dist/setup/index.js

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

21 changes: 9 additions & 12 deletions src/download/download-latest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export async function downloadLatest(
checkSum: string | undefined,
githubToken: string | undefined
): Promise<{cachedToolDir: string; version: string}> {
const binary = `uv-${arch}-${platform}`
let downloadUrl = `https://github.com/${OWNER}/${REPO}/releases/latest/download/${binary}`
const artifact = `uv-${arch}-${platform}`
let downloadUrl = `https://github.com/${OWNER}/${REPO}/releases/latest/download/${artifact}`
if (platform === 'pc-windows-msvc') {
downloadUrl += '.zip'
} else {
Expand All @@ -27,22 +27,19 @@ export async function downloadLatest(
githubToken
)
let uvExecutablePath: string
let extractedDir: string
let uvDir: string
if (platform === 'pc-windows-msvc') {
extractedDir = await tc.extractZip(downloadPath)
uvExecutablePath = path.join(extractedDir, 'uv.exe')
const extractedDir = await tc.extractZip(downloadPath)
uvDir = path.join(extractedDir, artifact)
uvExecutablePath = path.join(uvDir, 'uv.exe')
} else {
extractedDir = await tc.extractTar(downloadPath)
const extractedDir = await tc.extractTar(downloadPath)
uvDir = path.join(extractedDir, artifact)
uvExecutablePath = path.join(extractedDir, 'uv')
}
const version = await getVersion(uvExecutablePath)
await validateChecksum(checkSum, downloadPath, arch, platform, version)
const cachedToolDir = await tc.cacheDir(
extractedDir,
TOOL_CACHE_NAME,
version,
arch
)
const cachedToolDir = await tc.cacheDir(uvDir, TOOL_CACHE_NAME, version, arch)

return {cachedToolDir, version}
}
Expand Down
21 changes: 9 additions & 12 deletions src/download/download-version.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
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 fs from 'fs'
import * as util from 'util'

const readdir = util.promisify(fs.readdir)

export function tryGetFromToolCache(
arch: Architecture,
version: string
Expand All @@ -26,8 +22,8 @@ export async function downloadVersion(
checkSum: string | undefined,
githubToken: string | undefined
): Promise<string> {
const binary = `uv-${arch}-${platform}`
let downloadUrl = `https://github.com/${OWNER}/${REPO}/releases/download/${version}/${binary}`
const artifact = `uv-${arch}-${platform}`
let downloadUrl = `https://github.com/${OWNER}/${REPO}/releases/download/${version}/${artifact}`
if (platform === 'pc-windows-msvc') {
downloadUrl += '.zip'
} else {
Expand All @@ -48,10 +44,11 @@ export async function downloadVersion(
} else {
extractedDir = await tc.extractTar(downloadPath)
}
core.info(`Extracted uv to "${extractedDir}"`)
// list the contents of extracted dir
const files = await readdir(extractedDir)
core.info(`Contents of extracted directory: ${files.join(', ')}`)

return await tc.cacheDir(extractedDir, TOOL_CACHE_NAME, version, arch)
return await tc.cacheDir(
path.join(extractedDir, artifact),
TOOL_CACHE_NAME,
version,
arch
)
}

0 comments on commit fd3ca5d

Please sign in to comment.