Skip to content

Commit 2d2ac71

Browse files
committed
skip
1 parent 4575e80 commit 2d2ac71

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

main.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import * as core from '@actions/core'
22

33
import { LayerCache } from './src/LayerCache'
4+
45
const main = async () => {
5-
const repotag = core.getInput('repotag', { required: true })
6-
const key = core.getInput('key', { required: true })
6+
const repotag = core.getInput(`repotag`, { required: true })
7+
const primaryKey = core.getInput(`key`, { required: true })
8+
const restoreKeys = core.getInput(`restore-keys`, { required: false }).split(`\n`).filter(key => key !== ``)
79

810
const layerCache = new LayerCache(repotag)
9-
await layerCache.restore(key)
11+
const restoredKey = await layerCache.restore(primaryKey, restoreKeys)
1012
await layerCache.cleanUp()
13+
14+
core.saveState(`exists-primary-key`, primaryKey === restoredKey)
1115
}
1216

1317
main().catch(e => {

post.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@ import * as core from '@actions/core'
33
import { LayerCache } from './src/LayerCache'
44
const main = async () => {
55
const repotag = core.getInput('repotag', { required: true })
6-
const key = core.getInput('key', { required: true })
6+
const primaryKey = core.getInput('key', { required: true })
7+
8+
if (JSON.parse(core.getState(`exists-primary-key`)) === true) {
9+
core.info(`Key ${primaryKey} already exists, aborting.`)
10+
return
11+
}
712

813
const layerCache = new LayerCache(repotag)
9-
await layerCache.store(key)
14+
await layerCache.store(primaryKey)
1015
await layerCache.cleanUp()
1116
}
1217

src/LayerCache.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,32 +136,32 @@ class LayerCache {
136136
async restore(key: string, restoreKeys?: string[]) {
137137
this.originalKeyToStore = key
138138
// const restoreKeysIncludedRootKey = [key, ...(restoreKeys !== undefined ? restoreKeys : [])]
139-
const hasRestoredRootCache = await this.restoreRoot(restoreKeys)
140-
if (!hasRestoredRootCache) {
139+
const restoredCacheKey = await this.restoreRoot(restoreKeys)
140+
if (restoredCacheKey === undefined) {
141141
core.info(`Root cache could not be found. aborting.`)
142-
return false
142+
return undefined
143143
}
144144
if (this.enabledParallel) {
145145
const hasRestoredAllLayers = await this.restoreLayers()
146146
if (!hasRestoredAllLayers) {
147147
core.info(`Some layer cache could not be found. aborting.`)
148-
return false
148+
return undefined
149149
}
150150
await this.joinAllLayerCaches()
151151
}
152152
await this.loadImageFromUnpacked()
153-
return true
153+
return restoredCacheKey
154154
}
155155

156-
private async restoreRoot(restoreKeys?: string[]): Promise<boolean> {
156+
private async restoreRoot(restoreKeys?: string[]): Promise<string | undefined> {
157157
core.debug(`Trying to restore root cache, ID: ${this.getRootKey()}, dir: ${this.getUnpackedTarDir()}`)
158158
const restoredCacheKeyMayUndefined = await cache.restoreCache([this.getUnpackedTarDir()], this.getRootKey(), restoreKeys)
159159
core.debug(`restoredCacheKeyMayUndefined: ${restoredCacheKeyMayUndefined}`)
160160
if (restoredCacheKeyMayUndefined === undefined) {
161-
return false
161+
return undefined
162162
}
163163
this.originalKeyToStore = restoredCacheKeyMayUndefined.replace(/-root$/, '')
164-
return true
164+
return this.originalKeyToStore
165165
}
166166

167167
private async restoreLayers() {

0 commit comments

Comments
 (0)