@@ -133,18 +133,12 @@ exports.restoreCache = restoreCache;
133
133
* @returns number returns cacheId if the cache was saved successfully and throws an error if save fails
134
134
*/
135
135
function saveCache(paths, key, options) {
136
+ var _a, _b, _c, _d, _e;
136
137
return __awaiter(this, void 0, void 0, function* () {
137
138
checkPaths(paths);
138
139
checkKey(key);
139
140
const compressionMethod = yield utils.getCompressionMethod();
140
- core.debug('Reserving Cache');
141
- const cacheId = yield cacheHttpClient.reserveCache(key, paths, {
142
- compressionMethod
143
- });
144
- if (cacheId === -1) {
145
- throw new ReserveCacheError(`Unable to reserve cache with key ${key}, another job may be creating this cache.`);
146
- }
147
- core.debug(`Cache ID: ${cacheId}`);
141
+ let cacheId = null;
148
142
const cachePaths = yield utils.resolvePaths(paths);
149
143
core.debug('Cache Paths:');
150
144
core.debug(`${JSON.stringify(cachePaths)}`);
@@ -159,9 +153,24 @@ function saveCache(paths, key, options) {
159
153
const fileSizeLimit = 10 * 1024 * 1024 * 1024; // 10GB per repo limit
160
154
const archiveFileSize = utils.getArchiveFileSizeInBytes(archivePath);
161
155
core.debug(`File Size: ${archiveFileSize}`);
162
- if (archiveFileSize > fileSizeLimit) {
156
+ // For GHES, this check will take place in ReserveCache API with enterprise file size limit
157
+ if (archiveFileSize > fileSizeLimit && !utils.isGhes()) {
163
158
throw new Error(`Cache size of ~${Math.round(archiveFileSize / (1024 * 1024))} MB (${archiveFileSize} B) is over the 10GB limit, not saving cache.`);
164
159
}
160
+ core.debug('Reserving Cache');
161
+ const reserveCacheResponse = yield cacheHttpClient.reserveCache(key, paths, {
162
+ compressionMethod,
163
+ cacheSize: archiveFileSize
164
+ });
165
+ if ((_a = reserveCacheResponse === null || reserveCacheResponse === void 0 ? void 0 : reserveCacheResponse.result) === null || _a === void 0 ? void 0 : _a.cacheId) {
166
+ cacheId = (_b = reserveCacheResponse === null || reserveCacheResponse === void 0 ? void 0 : reserveCacheResponse.result) === null || _b === void 0 ? void 0 : _b.cacheId;
167
+ }
168
+ else if ((reserveCacheResponse === null || reserveCacheResponse === void 0 ? void 0 : reserveCacheResponse.statusCode) === 400) {
169
+ 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.`);
170
+ }
171
+ else {
172
+ 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}`);
173
+ }
165
174
core.debug(`Saving Cache (ID: ${cacheId})`);
166
175
yield cacheHttpClient.saveCache(cacheId, archivePath, options);
167
176
}
@@ -295,18 +304,18 @@ function downloadCache(archiveLocation, archivePath, options) {
295
304
exports.downloadCache = downloadCache;
296
305
// Reserve Cache
297
306
function reserveCache(key, paths, options) {
298
- var _a, _b;
299
307
return __awaiter(this, void 0, void 0, function* () {
300
308
const httpClient = createHttpClient();
301
309
const version = getCacheVersion(paths, options === null || options === void 0 ? void 0 : options.compressionMethod);
302
310
const reserveCacheRequest = {
303
311
key,
304
- version
312
+ version,
313
+ cacheSize: options === null || options === void 0 ? void 0 : options.cacheSize
305
314
};
306
315
const response = yield requestUtils_1.retryTypedResponse('reserveCache', () => __awaiter(this, void 0, void 0, function* () {
307
316
return httpClient.postJson(getCacheApiUrl('caches'), reserveCacheRequest);
308
317
}));
309
- return (_b = (_a = response === null || response === void 0 ? void 0 : response.result) === null || _a === void 0 ? void 0 : _a.cacheId) !== null && _b !== void 0 ? _b : -1 ;
318
+ return response;
310
319
});
311
320
}
312
321
exports.reserveCache = reserveCache;
@@ -575,6 +584,11 @@ function assertDefined(name, value) {
575
584
return value;
576
585
}
577
586
exports.assertDefined = assertDefined;
587
+ function isGhes() {
588
+ const ghUrl = new URL(process.env['GITHUB_SERVER_URL'] || 'https://github.com');
589
+ return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
590
+ }
591
+ exports.isGhes = isGhes;
578
592
//# sourceMappingURL=cacheUtils.js.map
579
593
580
594
/***/ }),
@@ -954,7 +968,8 @@ function retryTypedResponse(name, method, maxAttempts = constants_1.DefaultRetry
954
968
return {
955
969
statusCode: error.statusCode,
956
970
result: null,
957
- headers: {}
971
+ headers: {},
972
+ error
958
973
};
959
974
}
960
975
else {
0 commit comments