From 92536f7ebf9a8b7383e8aeaac6f62cf2f38fb432 Mon Sep 17 00:00:00 2001 From: Jim Verheijde Date: Sat, 18 Mar 2023 23:28:35 +0100 Subject: [PATCH] Do not upload log artifact when no log is present - This fixes #207, older CUDA versions don't have an installer log at the hardcoded location of /var/log/cuda-installer.log so the artifact uploader would fail. - To fix this let's not upload any artifacts in the first place if there is no log file to upload. --- src/installer.ts | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/installer.ts b/src/installer.ts index 386b14e7..cf28a77a 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -1,5 +1,6 @@ import * as artifact from '@actions/artifact' import * as core from '@actions/core' +import * as glob from '@actions/glob' import {OSType, getOs} from './platform' import {SemVer} from 'semver' import {exec} from '@actions/exec' @@ -64,25 +65,31 @@ export async function install( const exitCode = await exec(command, installArgs, execOptions) core.debug(`Installer exit code: ${exitCode}`) } catch (error) { - core.debug(`Error during installation: ${error}`) + core.warning(`Error during installation: ${error}`) throw error } finally { // Always upload installation log regardless of error if ((await getOs()) === OSType.linux) { const artifactClient = artifact.create() const artifactName = 'install-log' - const files = ['/var/log/cuda-installer.log'] - const rootDirectory = '/var/log' - const artifactOptions = { - continueOnError: true + const patterns = ['/var/log/cuda-installer.log'] + const globber = await glob.create(patterns.join('\n')) + const files = await globber.glob() + if (files.length > 0) { + const rootDirectory = '/var/log' + const artifactOptions = { + continueOnError: true + } + const uploadResult = await artifactClient.uploadArtifact( + artifactName, + files, + rootDirectory, + artifactOptions + ) + core.debug(`Upload result: ${uploadResult}`) + } else { + core.debug(`No log file to upload`) } - const uploadResult = await artifactClient.uploadArtifact( - artifactName, - files, - rootDirectory, - artifactOptions - ) - core.debug(`Upload result: ${uploadResult}`) } } }