Skip to content

Commit

Permalink
Set executable path if we don't cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimver committed Jan 14, 2024
1 parent 08c2996 commit b993835
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/downloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,20 @@ export async function download(
const url: URL = await getDownloadURL(method, version)
// Get intsaller filename extension depending on OS
const fileExtension: string = getFileExtension(osType)
const downloadDirectory = `cuda_download`
const destFileName = `${toolId}_${version}.${fileExtension}`
// Download executable
const downloadPath: string = await tc.downloadTool(
url.toString(),
destFileName
)
const destFilePath = `${downloadDirectory}/${destFileName}`
// Check if file already exists
if (!fileExists(destFilePath)) {
// Download executable
await tc.downloadTool(url.toString(), destFilePath)
} else {
core.debug(`File at ${destFilePath} already exists, skipping download`)
}
if (useLocalCache) {
// Cache download to local machine cache
const localCacheDirectory = await tc.cacheFile(
downloadPath,
destFilePath,
destFileName,
`${toolName}-${osType}`,
`${version}`
Expand All @@ -78,9 +82,9 @@ export async function download(
}
if (useGitHubCache) {
// Move file to GitHub cache directory
core.debug(`Copying ${destFileName} to ${cacheDirectory}`)
core.debug(`Copying ${destFilePath} to ${cacheDirectory}`)
await io.mkdirP(cacheDirectory)
await io.mv(destFileName, cacheDirectory)
await io.mv(destFilePath, cacheDirectory)
// Save cache directory to GitHub cache
const cacheId = await cache.saveCache([cacheDirectory], cacheKey)
if (cacheId !== -1) {
Expand All @@ -91,6 +95,7 @@ export async function download(
core.debug(`Tool was moved to cache directory ${cacheDirectory}`)
executableDirectory = cacheDirectory
}
executableDirectory = downloadDirectory
}
core.debug(`Executable path ${executableDirectory}`)
// String with full executable path
Expand Down Expand Up @@ -128,6 +133,15 @@ function getFileExtension(osType: OSType): string {
}
}

async function fileExists(filePath: string): Promise<boolean> {
try {
return !!(await fs.promises.stat(filePath))
} catch (e) {
core.debug(`Got error while checking if ${filePath} exists: ${e}`)
return false
}
}

async function getDownloadURL(method: string, version: SemVer): Promise<URL> {
const links: AbstractLinks = await getLinks()
switch (method) {
Expand Down

0 comments on commit b993835

Please sign in to comment.