@@ -49,7 +49,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
4949 });
5050};
5151Object.defineProperty(exports, "__esModule", ({ value: true }));
52- exports.FinalizeCacheError = exports.ReserveCacheError = exports.ValidationError = void 0;
52+ exports.FinalizeCacheError = exports.CacheWriteDeniedError = exports.CACHE_WRITE_DENIED_PREFIX = exports. ReserveCacheError = exports.ValidationError = void 0;
5353exports.isFeatureAvailable = isFeatureAvailable;
5454exports.restoreCache = restoreCache;
5555exports.saveCache = saveCache;
@@ -77,6 +77,26 @@ class ReserveCacheError extends Error {
7777 }
7878}
7979exports.ReserveCacheError = ReserveCacheError;
80+ /**
81+ * Stable prefix used by the cache receiver to signal that the token has
82+ * no writable scopes (read-only cache policy). Consumers can match on
83+ * this prefix to distinguish policy denials from ordinary contention.
84+ */
85+ exports.CACHE_WRITE_DENIED_PREFIX = 'cache write denied:';
86+ /**
87+ * Extends ReserveCacheError for source-compatibility: existing
88+ * `instanceof ReserveCacheError` checks and `typedError.name ===
89+ * ReserveCacheError.name` paths keep working, while consumers that want to
90+ * distinguish a policy denial can check for CacheWriteDeniedError.name.
91+ */
92+ class CacheWriteDeniedError extends ReserveCacheError {
93+ constructor(message) {
94+ super(message);
95+ this.name = 'CacheWriteDeniedError';
96+ Object.setPrototypeOf(this, CacheWriteDeniedError.prototype);
97+ }
98+ }
99+ exports.CacheWriteDeniedError = CacheWriteDeniedError;
80100class FinalizeCacheError extends Error {
81101 constructor(message) {
82102 super(message);
@@ -387,7 +407,11 @@ function saveCacheV1(paths_1, key_1, options_1) {
387407 throw new Error((_d = (_c = reserveCacheResponse === null || reserveCacheResponse === void 0 ? void 0 : reserveCacheResponse.error) === null || _c === void 0 ? void 0 : _c.message) !== null && _d !== void 0 ? _d : `Cache size of ~${Math.round(archiveFileSize / (1024 * 1024))} MB (${archiveFileSize} B) is over the data cap limit, not saving cache.`);
388408 }
389409 else {
390- throw new ReserveCacheError(`Unable to reserve cache with key ${key}, another job may be creating this cache. More details: ${(_e = reserveCacheResponse === null || reserveCacheResponse === void 0 ? void 0 : reserveCacheResponse.error) === null || _e === void 0 ? void 0 : _e.message}`);
410+ const detailMessage = (_e = reserveCacheResponse === null || reserveCacheResponse === void 0 ? void 0 : reserveCacheResponse.error) === null || _e === void 0 ? void 0 : _e.message;
411+ if (detailMessage === null || detailMessage === void 0 ? void 0 : detailMessage.startsWith(exports.CACHE_WRITE_DENIED_PREFIX)) {
412+ throw new CacheWriteDeniedError(`Unable to reserve cache with key ${key}. More details: ${detailMessage}`);
413+ }
414+ throw new ReserveCacheError(`Unable to reserve cache with key ${key}, another job may be creating this cache. More details: ${detailMessage}`);
391415 }
392416 core.debug(`Saving Cache (ID: ${cacheId})`);
393417 yield cacheHttpClient.saveCache(cacheId, archivePath, '', options);
@@ -397,6 +421,9 @@ function saveCacheV1(paths_1, key_1, options_1) {
397421 if (typedError.name === ValidationError.name) {
398422 throw error;
399423 }
424+ else if (typedError.name === CacheWriteDeniedError.name) {
425+ core.warning(`Failed to save: ${typedError.message}`);
426+ }
400427 else if (typedError.name === ReserveCacheError.name) {
401428 core.info(`Failed to save: ${typedError.message}`);
402429 }
@@ -435,6 +462,7 @@ function saveCacheV1(paths_1, key_1, options_1) {
435462 */
436463function saveCacheV2(paths_1, key_1, options_1) {
437464 return __awaiter(this, arguments, void 0, function* (paths, key, options, enableCrossOsArchive = false) {
465+ var _a;
438466 // Override UploadOptions to force the use of Azure
439467 // ...options goes first because we want to override the default values
440468 // set in UploadOptions with these specific figures
@@ -470,7 +498,11 @@ function saveCacheV2(paths_1, key_1, options_1) {
470498 try {
471499 const response = yield twirpClient.CreateCacheEntry(request);
472500 if (!response.ok) {
473- if (response.message) {
501+ // Skip the redundant inner warning when the receiver signalled a
502+ // policy denial: the outer catch arm below will log a single
503+ // customer-facing warning.
504+ if (response.message &&
505+ !response.message.startsWith(exports.CACHE_WRITE_DENIED_PREFIX)) {
474506 core.warning(`Cache reservation failed: ${response.message}`);
475507 }
476508 throw new Error(response.message || 'Response was not ok');
@@ -479,6 +511,10 @@ function saveCacheV2(paths_1, key_1, options_1) {
479511 }
480512 catch (error) {
481513 core.debug(`Failed to reserve cache: ${error}`);
514+ const errorMessage = (_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : '';
515+ if (errorMessage.startsWith(exports.CACHE_WRITE_DENIED_PREFIX)) {
516+ throw new CacheWriteDeniedError(`Unable to reserve cache with key ${key}. More details: ${errorMessage}`);
517+ }
482518 throw new ReserveCacheError(`Unable to reserve cache with key ${key}, another job may be creating this cache.`);
483519 }
484520 core.debug(`Attempting to upload cache located at: ${archivePath}`);
@@ -503,6 +539,9 @@ function saveCacheV2(paths_1, key_1, options_1) {
503539 if (typedError.name === ValidationError.name) {
504540 throw error;
505541 }
542+ else if (typedError.name === CacheWriteDeniedError.name) {
543+ core.warning(`Failed to save: ${typedError.message}`);
544+ }
506545 else if (typedError.name === ReserveCacheError.name) {
507546 core.info(`Failed to save: ${typedError.message}`);
508547 }
@@ -46500,6 +46539,10 @@ async function saveCache(packageManager) {
4650046539 return;
4650146540 }
4650246541 if (cacheId == -1) {
46542+ // saveCache returns -1 without throwing when the cache was not saved, e.g.
46543+ // a reserve collision or a read-only token (fork PR). @actions/cache has
46544+ // already logged the reason at the appropriate severity, so just trace it.
46545+ core.debug(`Cache was not saved for the key: ${primaryKey}`);
4650346546 return;
4650446547 }
4650546548 core.info(`Cache saved with the key: ${primaryKey}`);
@@ -87938,7 +87981,7 @@ function randomUUID() {
8793887981/***/ ((module) => {
8793987982
8794087983"use strict";
87941- module.exports = /*#__PURE__*/JSON.parse('{"name":"@actions/cache","version":"5.0.5","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":"^2.0.0","@actions/exec":"^2.0.0","@actions/glob":"^0.5.1","@protobuf-ts/runtime-rpc":"^2.11.1","@actions/http-client":"^3.0.2","@actions/io":"^2.0.0","@azure/abort-controller":"^1.1.0","@azure/core-rest-pipeline":"^1.22.0","@azure/storage-blob":"^12.29.1","semver":"^6.3.1"},"devDependencies":{"@types/node":"^24.1.0","@types/semver":"^6.0.0","@protobuf-ts/plugin":"^2.9.4","typescript":"^5.2.2"},"overrides":{"uri-js":"npm:uri-js-replace@^1.0.1","node-fetch":"^3.3.2"}}');
87984+ module.exports = /*#__PURE__*/JSON.parse('{"name":"@actions/cache","version":"5.1.0","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":"^2.0.0","@actions/exec":"^2.0.0","@actions/glob":"^0.5.1","@protobuf-ts/runtime-rpc":"^2.11.1","@actions/http-client":"^3.0.2","@actions/io":"^2.0.0","@azure/abort-controller":"^1.1.0","@azure/core-rest-pipeline":"^1.22.0","@azure/storage-blob":"^12.29.1","semver":"^6.3.1"},"devDependencies":{"@types/node":"^24.1.0","@types/semver":"^6.0.0","@protobuf-ts/plugin":"^2.9.4","typescript":"^5.2.2"},"overrides":{"uri-js":"npm:uri-js-replace@^1.0.1","node-fetch":"^3.3.2"}}');
8794287985
8794387986/***/ })
8794487987
0 commit comments