Skip to content

Commit 399982b

Browse files
Move existence check to cache-save
1 parent d278e78 commit 399982b

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/cache-save.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as core from '@actions/core';
22
import * as cache from '@actions/cache';
3+
import fs from 'fs';
34
import {State} from './constants';
45
import {getCacheDirectoryPath, getPackageManagerInfo} from './cache-utils';
56

@@ -26,6 +27,13 @@ const cachePackages = async (packageManager: string) => {
2627
packageManagerInfo,
2728
packageManager
2829
);
30+
31+
if (!fs.existsSync(cachePath)) {
32+
throw new Error(
33+
`Cache folder path is retrieved for ${packageManager} but doesn't exist on disk: ${cachePath}`
34+
);
35+
}
36+
2937
if (primaryKey === state) {
3038
core.info(
3139
`Cache hit occurred on the primary key ${primaryKey}, not saving cache.`

src/cache-utils.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as core from '@actions/core';
22
import * as exec from '@actions/exec';
3-
import fs from 'fs';
43
import os from 'os';
54
import path from 'path';
65

@@ -98,11 +97,5 @@ export const getCacheDirectoryPath = async (
9897

9998
core.debug(`${packageManager} path is ${stdOut}`);
10099

101-
if (!fs.existsSync(stdOut)) {
102-
throw new Error(
103-
`Cache folder path is retrieved for ${packageManager} but doesn't exist on disk: ${stdOut}`
104-
);
105-
}
106-
107100
return stdOut;
108101
};

0 commit comments

Comments
 (0)