From 8711f93f51dee8a7f4bfe79cbdbff263ce15dc65 Mon Sep 17 00:00:00 2001 From: Rob Cowsill <42620235+rcowsill@users.noreply.github.com> Date: Sat, 5 Dec 2020 18:37:44 +0000 Subject: [PATCH] Save only when new images were created Ignore restored images when checking for new images. Restored images are still always added to the new cache. This is so that unchanged images aren't lost when other images are rebuilt. --- post.ts | 10 ++++------ src/ImageDetector.ts | 5 ----- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/post.ts b/post.ts index e6162d99..a3a977d2 100644 --- a/post.ts +++ b/post.ts @@ -21,17 +21,15 @@ const main = async () => { assertType(restoredImages) const imageDetector = new ImageDetector() - if (await imageDetector.checkIfImageHasAdded(restoredImages)) { - core.info(`Key ${restoredKey} already exists, not saving cache.`) - return - } - const imagesToSave = await imageDetector.getImagesShouldSave(alreadyExistingImages) - if (imagesToSave.length < 1) { + const existingAndRestoredImages = alreadyExistingImages.concat(restoredImages) + const newImages = await imageDetector.getImagesShouldSave(existingAndRestoredImages) + if (newImages.length < 1) { core.info(`There is no image to save.`) return } + const imagesToSave = await imageDetector.getImagesShouldSave(alreadyExistingImages) const layerCache = new LayerCache(imagesToSave) layerCache.concurrency = parseInt(core.getInput(`concurrency`, { required: true }), 10) diff --git a/src/ImageDetector.ts b/src/ImageDetector.ts index 24d42b01..905881ac 100644 --- a/src/ImageDetector.ts +++ b/src/ImageDetector.ts @@ -17,9 +17,4 @@ export class ImageDetector { alreadRegisteredImages.forEach(image => resultSet.delete(image)) return Array.from(resultSet) } - - async checkIfImageHasAdded(restoredImages: string[]): Promise { - const existing = await this.getExistingImages() - return JSON.stringify(restoredImages) === JSON.stringify(existing) - } }