forked from jpribyl/action-docker-layer-caching
-
Notifications
You must be signed in to change notification settings - Fork 0
/
post.ts
45 lines (35 loc) · 1.34 KB
/
post.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import * as core from '@actions/core'
import { LayerCache } from './src/LayerCache'
import { ImageDetector } from './src/ImageDetector'
import { assertType } from 'typescript-is'
const main = async () => {
if (JSON.parse(core.getInput('skip-save', { required: true }))) {
core.info('Skipping save.')
return
}
const primaryKey = core.getInput('key', { required: true })
const restoredKey = JSON.parse(core.getState(`restored-key`))
const alreadyExistingImages = JSON.parse(core.getState(`already-existing-images`))
const restoredImages = JSON.parse(core.getState(`restored-images`))
assertType<string>(restoredKey)
assertType<string[]>(alreadyExistingImages)
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) {
core.info(`There is no image to save.`)
return
}
const layerCache = new LayerCache(imagesToSave)
layerCache.concurrency = parseInt(core.getInput(`concurrency`, { required: true }), 10)
await layerCache.store(primaryKey)
await layerCache.cleanUp()
}
main().catch(e => {
console.error(e)
core.setFailed(e)
})