Skip to content

Commit

Permalink
Save only when new images were created
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rcowsill committed Dec 5, 2020
1 parent b01c39f commit 8711f93
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
10 changes: 4 additions & 6 deletions post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@ const main = async () => {
assertType<string[]>(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)

Expand Down
5 changes: 0 additions & 5 deletions src/ImageDetector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,4 @@ export class ImageDetector {
alreadRegisteredImages.forEach(image => resultSet.delete(image))
return Array.from(resultSet)
}

async checkIfImageHasAdded(restoredImages: string[]): Promise<boolean> {
const existing = await this.getExistingImages()
return JSON.stringify(restoredImages) === JSON.stringify(existing)
}
}

0 comments on commit 8711f93

Please sign in to comment.