-
Notifications
You must be signed in to change notification settings - Fork 56
/
main.ts
30 lines (23 loc) · 1.18 KB
/
main.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
import * as core from '@actions/core'
import * as exec from 'actions-exec-listener'
import { LayerCache } from './src/LayerCache'
import { ImageDetector } from './src/ImageDetector'
const main = async () => {
const primaryKey = core.getInput(`key`, { required: true })
const restoreKeys = core.getInput(`restore-keys`, { required: false }).split(`\n`).filter(key => key !== ``)
const imageDetector = new ImageDetector()
const alreadyExistingImages = await imageDetector.getExistingImages()
core.saveState(`already-existing-images`, JSON.stringify(alreadyExistingImages))
const layerCache = new LayerCache([])
layerCache.concurrency = parseInt(core.getInput(`concurrency`, { required: true }), 10)
const restoredKey = await layerCache.restore(primaryKey, restoreKeys)
await layerCache.cleanUp()
core.saveState(`restored-key`, JSON.stringify(restoredKey !== undefined ? restoredKey : ''))
core.saveState(`restored-images`, JSON.stringify(await imageDetector.getImagesShouldSave(alreadyExistingImages)))
}
main().catch(e => {
console.error(e)
core.setFailed(e)
core.saveState(`restored-key`, JSON.stringify(``))
core.saveState(`restored-images`, JSON.stringify([]))
})