From 399982b36805ac9d772a419dc9f95fb5a8eb5c55 Mon Sep 17 00:00:00 2001 From: Jacob Gillespie Date: Wed, 14 Jul 2021 15:25:45 +0100 Subject: [PATCH] Move existence check to cache-save --- src/cache-save.ts | 8 ++++++++ src/cache-utils.ts | 7 ------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/cache-save.ts b/src/cache-save.ts index 11f830b..9fb0b29 100644 --- a/src/cache-save.ts +++ b/src/cache-save.ts @@ -1,5 +1,6 @@ import * as core from '@actions/core'; import * as cache from '@actions/cache'; +import fs from 'fs'; import {State} from './constants'; import {getCacheDirectoryPath, getPackageManagerInfo} from './cache-utils'; @@ -26,6 +27,13 @@ const cachePackages = async (packageManager: string) => { packageManagerInfo, packageManager ); + + if (!fs.existsSync(cachePath)) { + throw new Error( + `Cache folder path is retrieved for ${packageManager} but doesn't exist on disk: ${cachePath}` + ); + } + if (primaryKey === state) { core.info( `Cache hit occurred on the primary key ${primaryKey}, not saving cache.` diff --git a/src/cache-utils.ts b/src/cache-utils.ts index cfe8c5b..f39fe8a 100644 --- a/src/cache-utils.ts +++ b/src/cache-utils.ts @@ -1,6 +1,5 @@ import * as core from '@actions/core'; import * as exec from '@actions/exec'; -import fs from 'fs'; import os from 'os'; import path from 'path'; @@ -98,11 +97,5 @@ export const getCacheDirectoryPath = async ( core.debug(`${packageManager} path is ${stdOut}`); - if (!fs.existsSync(stdOut)) { - throw new Error( - `Cache folder path is retrieved for ${packageManager} but doesn't exist on disk: ${stdOut}` - ); - } - return stdOut; };