@@ -103304,7 +103304,7 @@ async function setupBazel() {
103304103304
103305103305 await setupBazelisk()
103306103306 await restoreCache(config.bazeliskCache)
103307- await restoreCache (config.diskCache)
103307+ await restoreDiskCache (config.diskCache)
103308103308 await restoreCache(config.repositoryCache)
103309103309 await restoreExternalCaches(config.externalCache)
103310103310
@@ -103421,7 +103421,7 @@ async function restoreExternalCaches(cacheConfig) {
103421103421 }
103422103422}
103423103423
103424- async function restoreCache (cacheConfig) {
103424+ async function restoreCacheImpl (cacheConfig, primaryKey, restoreKeys, cacheHit ) {
103425103425 if (!cacheConfig.enabled) {
103426103426 return
103427103427 }
@@ -103430,23 +103430,20 @@ async function restoreCache(cacheConfig) {
103430103430 await index_setTimeout(delay, async function () {
103431103431 core.startGroup(`Restore cache for ${cacheConfig.name}`)
103432103432
103433- const hash = await glob.hashFiles(cacheConfig.files.join('\n'))
103434103433 const name = cacheConfig.name
103435103434 const paths = cacheConfig.paths
103436- const restoreKey = `${config.baseCacheKey}-${name}-`
103437- const key = `${restoreKey}${hash}`
103438103435
103439- core.debug(`Attempting to restore ${name} cache from ${key }`)
103436+ core.debug(`Attempting to restore ${name} cache from ${primaryKey }`)
103440103437
103441103438 const restoredKey = await cache.restoreCache(
103442- paths, key, [restoreKey] ,
103439+ paths, primaryKey, restoreKeys ,
103443103440 { segmentTimeoutInMs: 300000 } // 5 minutes
103444103441 )
103445103442
103446103443 if (restoredKey) {
103447103444 core.info(`Successfully restored cache from ${restoredKey}`)
103448103445
103449- if (restoredKey === key ) {
103446+ if (cacheHit( restoredKey) ) {
103450103447 core.saveState(`${name}-cache-hit`, 'true')
103451103448 }
103452103449 } else {
@@ -103457,6 +103454,30 @@ async function restoreCache(cacheConfig) {
103457103454 }())
103458103455}
103459103456
103457+ async function restoreCache(cacheConfig) {
103458+ const hash = await glob.hashFiles(cacheConfig.files.join('\n'))
103459+ const restoreKey = `${config.baseCacheKey}-${cacheConfig.name}-`
103460+ const key = `${restoreKey}${hash}`
103461+ await restoreCacheImpl(
103462+ cacheConfig, key, [restoreKey],
103463+ restoredKey => restoredKey === key
103464+ )
103465+ }
103466+
103467+ async function restoreDiskCache(cacheConfig) {
103468+ const hash = await glob.hashFiles(cacheConfig.files.join('\n'))
103469+
103470+ // Since disk caches get updated on any change, each run has a unique key.
103471+ // Therefore it can only be restored by prefix match, rather than exact key match.
103472+ // When multiple prefix matches exist, the most recent is selected.
103473+ const restoreKey = `${config.baseCacheKey}-${cacheConfig.name}-`
103474+ const hashedRestoreKey = `${restoreKey}${hash}-`
103475+ await restoreCacheImpl(
103476+ cacheConfig, hashedRestoreKey, [hashedRestoreKey, restoreKey],
103477+ restoredKey => restoredKey.startsWith(hashedRestoreKey)
103478+ )
103479+ }
103480+
103460103481run()
103461103482
103462103483module.exports = __webpack_exports__;
0 commit comments