@@ -672,20 +672,12 @@ function saveCacheV2(paths, key, options, enableCrossOsArchive = false) {
672672 key,
673673 version
674674 };
675- let signedUploadUrl;
676- try {
677- const response = yield twirpClient.CreateCacheEntry(request);
678- if (!response.ok) {
679- throw new Error('Response was not ok');
680- }
681- signedUploadUrl = response.signedUploadUrl;
682- }
683- catch (error) {
684- core.debug(`Failed to reserve cache: ${error}`);
675+ const response = yield twirpClient.CreateCacheEntry(request);
676+ if (!response.ok) {
685677 throw new ReserveCacheError(`Unable to reserve cache with key ${key}, another job may be creating this cache.`);
686678 }
687679 core.debug(`Attempting to upload cache located at: ${archivePath}`);
688- yield cacheHttpClient.saveCache(cacheId, archivePath, signedUploadUrl, options);
680+ yield cacheHttpClient.saveCache(cacheId, archivePath, response. signedUploadUrl, options);
689681 const finalizeRequest = {
690682 key,
691683 version,
@@ -103217,7 +103209,7 @@ exports.visitAsync = visitAsync;
103217103209/***/ ((module) => {
103218103210
103219103211"use strict";
103220- module.exports = /*#__PURE__*/JSON.parse('{"name":"@actions/cache","version":"4.0.2","preview":true,"description":"Actions cache lib","keywords":["github","actions","cache"],"homepage":"https://github.com/actions/toolkit/tree/main/packages/cache","license":"MIT","main":"lib/cache.js","types":"lib/cache.d.ts","directories":{"lib":"lib","test":"__tests__"},"files":["lib","!.DS_Store"],"publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/actions/toolkit.git","directory":"packages/cache"},"scripts":{"audit-moderate":"npm install && npm audit --json --audit-level=moderate > audit.json","test":"echo \\"Error: run tests from root\\" && exit 1","tsc":"tsc"},"bugs":{"url":"https://github.com/actions/toolkit/issues"},"dependencies":{"@actions/core":"^1.11.1","@actions/exec":"^1.0.1","@actions/glob":"^0.1.0","@actions/http-client":"^2.1.1","@actions/io":"^1.0.1","@azure/abort-controller":"^1.1.0","@azure/ms-rest-js":"^2.6.0","@azure/storage-blob":"^12.13.0","@protobuf-ts/plugin":"^2.9.4","semver":"^6.3.1"},"devDependencies":{"@types/semver":"^6.0.0","typescript":"^5.2.2"}}');
103212+ module.exports = /*#__PURE__*/JSON.parse('{"name":"@actions/cache","version":"4.0.1","preview":true,"description":"Actions cache lib","keywords":["github","actions","cache"],"homepage":"https://github.com/actions/toolkit/tree/main/packages/cache","license":"MIT","main":"lib/cache.js","types":"lib/cache.d.ts","directories":{"lib":"lib","test":"__tests__"},"files":["lib","!.DS_Store"],"publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/actions/toolkit.git","directory":"packages/cache"},"scripts":{"audit-moderate":"npm install && npm audit --json --audit-level=moderate > audit.json","test":"echo \\"Error: run tests from root\\" && exit 1","tsc":"tsc"},"bugs":{"url":"https://github.com/actions/toolkit/issues"},"dependencies":{"@actions/core":"^1.11.1","@actions/exec":"^1.0.1","@actions/glob":"^0.1.0","@actions/http-client":"^2.1.1","@actions/io":"^1.0.1","@azure/abort-controller":"^1.1.0","@azure/ms-rest-js":"^2.6.0","@azure/storage-blob":"^12.13.0","@protobuf-ts/plugin":"^2.9.4","semver":"^6.3.1"},"devDependencies":{"@types/semver":"^6.0.0","typescript":"^5.2.2"}}');
103221103213
103222103214/***/ }),
103223103215
@@ -103304,7 +103296,7 @@ async function setupBazel() {
103304103296
103305103297 await setupBazelisk()
103306103298 await restoreCache(config.bazeliskCache)
103307- await restoreCache (config.diskCache)
103299+ await restoreDiskCache (config.diskCache)
103308103300 await restoreCache(config.repositoryCache)
103309103301 await restoreExternalCaches(config.externalCache)
103310103302
@@ -103421,7 +103413,7 @@ async function restoreExternalCaches(cacheConfig) {
103421103413 }
103422103414}
103423103415
103424- async function restoreCache (cacheConfig) {
103416+ async function restoreCacheImpl (cacheConfig, primaryKey, restoreKeys, cacheHit ) {
103425103417 if (!cacheConfig.enabled) {
103426103418 return
103427103419 }
@@ -103430,23 +103422,20 @@ async function restoreCache(cacheConfig) {
103430103422 await index_setTimeout(delay, async function () {
103431103423 core.startGroup(`Restore cache for ${cacheConfig.name}`)
103432103424
103433- const hash = await glob.hashFiles(cacheConfig.files.join('\n'))
103434103425 const name = cacheConfig.name
103435103426 const paths = cacheConfig.paths
103436- const restoreKey = `${config.baseCacheKey}-${name}-`
103437- const key = `${restoreKey}${hash}`
103438103427
103439103428 core.debug(`Attempting to restore ${name} cache from ${key}`)
103440103429
103441103430 const restoredKey = await cache.restoreCache(
103442- paths, key, [restoreKey] ,
103431+ paths, primaryKey, restoreKeys ,
103443103432 { segmentTimeoutInMs: 300000 } // 5 minutes
103444103433 )
103445103434
103446103435 if (restoredKey) {
103447103436 core.info(`Successfully restored cache from ${restoredKey}`)
103448103437
103449- if (restoredKey === key ) {
103438+ if (cacheHit( restoredKey) ) {
103450103439 core.saveState(`${name}-cache-hit`, 'true')
103451103440 }
103452103441 } else {
@@ -103457,6 +103446,30 @@ async function restoreCache(cacheConfig) {
103457103446 }())
103458103447}
103459103448
103449+ async function restoreCache(cacheConfig) {
103450+ const hash = await glob.hashFiles(cacheConfig.files.join('\n'))
103451+ const restoreKey = `${config.baseCacheKey}-${cacheConfig.name}-`
103452+ const key = `${restoreKey}${hash}`
103453+ await restoreCacheImpl(
103454+ cacheConfig, key, [restoreKey],
103455+ restoredKey => restoredKey === key
103456+ )
103457+ }
103458+
103459+ async function restoreDiskCache(cacheConfig) {
103460+ const hash = await glob.hashFiles(cacheConfig.files.join('\n'))
103461+
103462+ // Since disk caches get updated on any change, each run has a unique key.
103463+ // Therefore it can only be restored by prefix match, rather than exact key match.
103464+ // When multiple prefix matches exist, the most recent is selected.
103465+ const restoreKey = `${config.baseCacheKey}-${cacheConfig.name}-`
103466+ const hashedRestoreKey = `${restoreKey}${hash}-`
103467+ await restoreCacheImpl(
103468+ cacheConfig, hashedRestoreKey, [hashedRestoreKey, restoreKey],
103469+ restoredKey => restoredKey.startsWith(hashedRestoreKey)
103470+ )
103471+ }
103472+
103460103473run()
103461103474
103462103475module.exports = __webpack_exports__;
0 commit comments