From ee0758220c9077fff2176111be3370bb364fcad6 Mon Sep 17 00:00:00 2001 From: Jim Verheijde Date: Sun, 14 Jan 2024 12:54:51 +0100 Subject: [PATCH] Set executable path if we don't cache --- src/downloader.ts | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/downloader.ts b/src/downloader.ts index f78ef45c..7ad78f66 100644 --- a/src/downloader.ts +++ b/src/downloader.ts @@ -57,16 +57,21 @@ 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 (!(await fileExists(destFilePath))) { + core.debug(`File at ${destFilePath} does not exist, downloading`) + // 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}` @@ -78,9 +83,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) { @@ -91,6 +96,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 @@ -128,6 +134,17 @@ function getFileExtension(osType: OSType): string { } } +async function fileExists(filePath: string): Promise { + try { + const stats = await fs.promises.stat(filePath) + core.debug(`Got the following stats for ${filePath}: ${stats}`) + return !!stats + } catch (e) { + core.debug(`Got error while checking if ${filePath} exists: ${e}`) + return false + } +} + async function getDownloadURL(method: string, version: SemVer): Promise { const links: AbstractLinks = await getLinks() switch (method) {