Skip to content

Commit

Permalink
avoid losing hash when missing output files
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts committed Mar 30, 2022
1 parent 63917b6 commit 4baa527
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions scripts/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,21 +215,22 @@ export async function checkForCache(
cacheExists: false,
hash: '',
};

for (const buildFile of generatedFiles) {
if ((await exists(`${folder}/${buildFile}`)) === false) {
spinner.info(`cache not found for ${job}`);
return cache;
}
}
const generatedFilesExists = (
await Promise.all(
generatedFiles.map((generatedFile) =>
exists(`${folder}/${generatedFile}`).then((res) => res)
)
)
).every((exist) => exist);

for (const fileToCache of filesToCache) {
const fileHash = (await hashElement(`${folder}/${fileToCache}`)).hash;

cache.hash = `${cache.hash}-${fileHash}`;
}

if (await exists(cacheFile)) {
// We only skip if both the cache and the generated file exists
if (generatedFilesExists && (await exists(cacheFile))) {
const storedHash = (await fsp.readFile(cacheFile)).toString();
if (storedHash === cache.hash) {
spinner.succeed(`job skipped, cache found for ${job}`);
Expand Down

0 comments on commit 4baa527

Please sign in to comment.