Skip to content

Commit d38ff83

Browse files
authored
Merge pull request #109 from spowelljr/stopCacheErrors
Skip caching if dir doesn't exist
2 parents 36ea757 + e4085e4 commit d38ff83

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

dist/index.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ exports.saveCaches = exports.getMinikubeVersion = exports.restoreCaches = void 0
2020
const cache_1 = __nccwpck_require__(7799);
2121
const core_1 = __nccwpck_require__(2186);
2222
const exec_1 = __nccwpck_require__(1514);
23+
const fs_1 = __nccwpck_require__(7147);
2324
const os_1 = __nccwpck_require__(2037);
2425
const path_1 = __nccwpck_require__(1017);
2526
const restoreCaches = () => __awaiter(void 0, void 0, void 0, function* () {
@@ -54,11 +55,11 @@ const saveCaches = (cacheHits) => __awaiter(void 0, void 0, void 0, function* ()
5455
return;
5556
}
5657
const minikubeVersion = yield (0, exports.getMinikubeVersion)();
57-
const isoCache = saveCache('iso', cacheHits.iso, minikubeVersion);
58-
const kicCache = saveCache('kic', cacheHits.kic, minikubeVersion);
59-
yield saveCache('preloaded-tarball', cacheHits.preload, minikubeVersion);
60-
yield isoCache;
61-
yield kicCache;
58+
yield Promise.all([
59+
saveCache('iso', cacheHits.iso, minikubeVersion),
60+
saveCache('kic', cacheHits.kic, minikubeVersion),
61+
saveCache('preloaded-tarball', cacheHits.preload, minikubeVersion),
62+
]);
6263
});
6364
exports.saveCaches = saveCaches;
6465
const restoreCache = (name, minikubeVersion) => __awaiter(void 0, void 0, void 0, function* () {
@@ -68,8 +69,12 @@ const saveCache = (name, cacheHit, minikubeVersion) => __awaiter(void 0, void 0,
6869
if (cacheHit) {
6970
return;
7071
}
72+
const cachePaths = getCachePaths(name);
73+
if (!(0, fs_1.existsSync)(cachePaths[0])) {
74+
return;
75+
}
7176
try {
72-
yield (0, cache_1.saveCache)(getCachePaths(name), getCacheKey(name, minikubeVersion));
77+
yield (0, cache_1.saveCache)(cachePaths, getCacheKey(name, minikubeVersion));
7378
}
7479
catch (error) {
7580
console.log(name + error);

src/cache.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
} from '@actions/cache'
55
import {getInput as getInputAction} from '@actions/core'
66
import {exec} from '@actions/exec'
7+
import {existsSync} from 'fs'
78
import {arch, homedir} from 'os'
89
import {join} from 'path'
910

@@ -45,11 +46,11 @@ export const saveCaches = async (cacheHits: CacheHits): Promise<void> => {
4546
return
4647
}
4748
const minikubeVersion = await getMinikubeVersion()
48-
const isoCache = saveCache('iso', cacheHits.iso, minikubeVersion)
49-
const kicCache = saveCache('kic', cacheHits.kic, minikubeVersion)
50-
await saveCache('preloaded-tarball', cacheHits.preload, minikubeVersion)
51-
await isoCache
52-
await kicCache
49+
await Promise.all([
50+
saveCache('iso', cacheHits.iso, minikubeVersion),
51+
saveCache('kic', cacheHits.kic, minikubeVersion),
52+
saveCache('preloaded-tarball', cacheHits.preload, minikubeVersion),
53+
])
5354
}
5455

5556
const restoreCache = async (
@@ -70,11 +71,12 @@ const saveCache = async (
7071
if (cacheHit) {
7172
return
7273
}
74+
const cachePaths = getCachePaths(name)
75+
if (!existsSync(cachePaths[0])) {
76+
return
77+
}
7378
try {
74-
await saveCacheAction(
75-
getCachePaths(name),
76-
getCacheKey(name, minikubeVersion)
77-
)
79+
await saveCacheAction(cachePaths, getCacheKey(name, minikubeVersion))
7880
} catch (error) {
7981
console.log(name + error)
8082
}

0 commit comments

Comments
 (0)