forked from jpribyl/action-docker-layer-caching
-
Notifications
You must be signed in to change notification settings - Fork 0
/
post.ts
27 lines (23 loc) · 1.08 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
import * as core from '@actions/core'
import exec from 'actions-exec-listener'
import { LayerCache } from './src/LayerCache'
const main = async () => {
const primaryKey = core.getInput('key', { required: true })
const restoredKey = JSON.parse(core.getState(`restored-key`)) as string
const alreadyExistingImageIds = JSON.parse(core.getState(`already-existing-image-ids`)) as string[]
const currentImageIds = (await exec.exec(`docker image ls -q`)).stdoutStr.split(`\n`).filter(id => id !== ``)
const imageIdsToSave = new Set([...currentImageIds])
alreadyExistingImageIds.forEach(id => imageIdsToSave.delete(id))
const layerCache = new LayerCache(Array.from(imageIdsToSave))
core.debug(JSON.stringify({ restoredKey, formattedOriginalCacheKey: layerCache.getFormattedOriginalCacheKey()}))
if (restoredKey !== `` && restoredKey === layerCache.getFormattedOriginalCacheKey()) {
core.info(`Key ${restoredKey} already exists, aborting.`)
return
}
await layerCache.store(primaryKey)
await layerCache.cleanUp()
}
main().catch(e => {
console.error(e)
core.setFailed(e)
})