Skip to content

Commit

Permalink
Merge pull request #109 from spowelljr/stopCacheErrors
Browse files Browse the repository at this point in the history
Skip caching if dir doesn't exist
  • Loading branch information
medyagh authored Mar 22, 2023
2 parents 36ea757 + e4085e4 commit d38ff83
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
17 changes: 11 additions & 6 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ exports.saveCaches = exports.getMinikubeVersion = exports.restoreCaches = void 0
const cache_1 = __nccwpck_require__(7799);
const core_1 = __nccwpck_require__(2186);
const exec_1 = __nccwpck_require__(1514);
const fs_1 = __nccwpck_require__(7147);
const os_1 = __nccwpck_require__(2037);
const path_1 = __nccwpck_require__(1017);
const restoreCaches = () => __awaiter(void 0, void 0, void 0, function* () {
Expand Down Expand Up @@ -54,11 +55,11 @@ const saveCaches = (cacheHits) => __awaiter(void 0, void 0, void 0, function* ()
return;
}
const minikubeVersion = yield (0, exports.getMinikubeVersion)();
const isoCache = saveCache('iso', cacheHits.iso, minikubeVersion);
const kicCache = saveCache('kic', cacheHits.kic, minikubeVersion);
yield saveCache('preloaded-tarball', cacheHits.preload, minikubeVersion);
yield isoCache;
yield kicCache;
yield Promise.all([
saveCache('iso', cacheHits.iso, minikubeVersion),
saveCache('kic', cacheHits.kic, minikubeVersion),
saveCache('preloaded-tarball', cacheHits.preload, minikubeVersion),
]);
});
exports.saveCaches = saveCaches;
const restoreCache = (name, minikubeVersion) => __awaiter(void 0, void 0, void 0, function* () {
Expand All @@ -68,8 +69,12 @@ const saveCache = (name, cacheHit, minikubeVersion) => __awaiter(void 0, void 0,
if (cacheHit) {
return;
}
const cachePaths = getCachePaths(name);
if (!(0, fs_1.existsSync)(cachePaths[0])) {
return;
}
try {
yield (0, cache_1.saveCache)(getCachePaths(name), getCacheKey(name, minikubeVersion));
yield (0, cache_1.saveCache)(cachePaths, getCacheKey(name, minikubeVersion));
}
catch (error) {
console.log(name + error);
Expand Down
20 changes: 11 additions & 9 deletions src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
} from '@actions/cache'
import {getInput as getInputAction} from '@actions/core'
import {exec} from '@actions/exec'
import {existsSync} from 'fs'
import {arch, homedir} from 'os'
import {join} from 'path'

Expand Down Expand Up @@ -45,11 +46,11 @@ export const saveCaches = async (cacheHits: CacheHits): Promise<void> => {
return
}
const minikubeVersion = await getMinikubeVersion()
const isoCache = saveCache('iso', cacheHits.iso, minikubeVersion)
const kicCache = saveCache('kic', cacheHits.kic, minikubeVersion)
await saveCache('preloaded-tarball', cacheHits.preload, minikubeVersion)
await isoCache
await kicCache
await Promise.all([
saveCache('iso', cacheHits.iso, minikubeVersion),
saveCache('kic', cacheHits.kic, minikubeVersion),
saveCache('preloaded-tarball', cacheHits.preload, minikubeVersion),
])
}

const restoreCache = async (
Expand All @@ -70,11 +71,12 @@ const saveCache = async (
if (cacheHit) {
return
}
const cachePaths = getCachePaths(name)
if (!existsSync(cachePaths[0])) {
return
}
try {
await saveCacheAction(
getCachePaths(name),
getCacheKey(name, minikubeVersion)
)
await saveCacheAction(cachePaths, getCacheKey(name, minikubeVersion))
} catch (error) {
console.log(name + error)
}
Expand Down

0 comments on commit d38ff83

Please sign in to comment.