2024-08-23 23:58:26 +02:00
|
|
|
import * as core from '@actions/core'
|
|
|
|
import * as tc from '@actions/tool-cache'
|
|
|
|
import * as exec from '@actions/exec'
|
2024-08-24 00:27:50 +02:00
|
|
|
import * as path from 'path'
|
2024-08-23 23:58:26 +02:00
|
|
|
import {Architecture, Platform} from '../utils/platforms'
|
|
|
|
import {validateChecksum} from './checksum/checksum'
|
2024-08-24 00:14:50 +02:00
|
|
|
import {OWNER, REPO, TOOL_CACHE_NAME} from '../utils/utils'
|
2024-08-23 23:58:26 +02:00
|
|
|
|
|
|
|
export async function downloadLatest(
|
|
|
|
platform: Platform,
|
|
|
|
arch: Architecture,
|
|
|
|
checkSum: string | undefined,
|
|
|
|
githubToken: string | undefined
|
2024-08-24 00:14:50 +02:00
|
|
|
): Promise<{cachedToolDir: string; version: string}> {
|
2024-08-24 00:45:44 +02:00
|
|
|
const artifact = `uv-${arch}-${platform}`
|
|
|
|
let downloadUrl = `https://github.com/${OWNER}/${REPO}/releases/latest/download/${artifact}`
|
2024-08-23 23:58:26 +02:00
|
|
|
if (platform === 'pc-windows-msvc') {
|
|
|
|
downloadUrl += '.zip'
|
|
|
|
} else {
|
|
|
|
downloadUrl += '.tar.gz'
|
|
|
|
}
|
|
|
|
core.info(`Downloading uv from "${downloadUrl}" ...`)
|
|
|
|
|
|
|
|
const downloadPath = await tc.downloadTool(
|
|
|
|
downloadUrl,
|
2024-08-24 00:27:50 +02:00
|
|
|
undefined,
|
2024-08-23 23:58:26 +02:00
|
|
|
githubToken
|
|
|
|
)
|
|
|
|
let uvExecutablePath: string
|
2024-08-24 00:45:44 +02:00
|
|
|
let uvDir: string
|
2024-08-23 23:58:26 +02:00
|
|
|
if (platform === 'pc-windows-msvc') {
|
2024-08-24 00:45:44 +02:00
|
|
|
const extractedDir = await tc.extractZip(downloadPath)
|
|
|
|
uvDir = path.join(extractedDir, artifact)
|
|
|
|
uvExecutablePath = path.join(uvDir, 'uv.exe')
|
2024-08-23 23:58:26 +02:00
|
|
|
} else {
|
2024-08-24 00:45:44 +02:00
|
|
|
const extractedDir = await tc.extractTar(downloadPath)
|
|
|
|
uvDir = path.join(extractedDir, artifact)
|
2024-08-24 09:01:13 +02:00
|
|
|
uvExecutablePath = path.join(uvDir, 'uv')
|
2024-08-23 23:58:26 +02:00
|
|
|
}
|
|
|
|
const version = await getVersion(uvExecutablePath)
|
2024-08-24 00:40:34 +02:00
|
|
|
await validateChecksum(checkSum, downloadPath, arch, platform, version)
|
2024-08-24 00:45:44 +02:00
|
|
|
const cachedToolDir = await tc.cacheDir(uvDir, TOOL_CACHE_NAME, version, arch)
|
2024-08-23 23:58:26 +02:00
|
|
|
|
2024-08-24 00:14:50 +02:00
|
|
|
return {cachedToolDir, version}
|
2024-08-23 23:58:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async function getVersion(uvExecutablePath: string): Promise<string> {
|
|
|
|
// Parse the output of `uv --version` to get the version
|
|
|
|
// The output looks like
|
|
|
|
// uv 0.3.1 (be17d132a 2024-08-21)
|
|
|
|
|
|
|
|
const options: exec.ExecOptions = {
|
|
|
|
silent: !core.isDebug()
|
|
|
|
}
|
|
|
|
const execArgs = ['--version']
|
|
|
|
|
|
|
|
let output = ''
|
|
|
|
options.listeners = {
|
|
|
|
stdout: (data: Buffer) => {
|
|
|
|
output += data.toString()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
await exec.exec(uvExecutablePath, execArgs, options)
|
|
|
|
const parts = output.split(' ')
|
|
|
|
return parts[1]
|
|
|
|
}
|