From 6cd8286138384bd4efe40395ee47da2dd38a6e65 Mon Sep 17 00:00:00 2001 From: Apple Date: Fri, 1 Apr 2022 01:41:12 +0530 Subject: [PATCH] Resolved comments --- packages/cache/__tests__/saveCache.test.ts | 9 ++++---- packages/cache/src/cache.ts | 23 ++++++++++++--------- packages/cache/src/internal/cacheUtils.ts | 7 +++++++ packages/cache/src/internal/contracts.d.ts | 4 ++-- packages/cache/src/internal/requestUtils.ts | 3 +-- 5 files changed, 27 insertions(+), 19 deletions(-) diff --git a/packages/cache/__tests__/saveCache.test.ts b/packages/cache/__tests__/saveCache.test.ts index 8844abf7..155eefbe 100644 --- a/packages/cache/__tests__/saveCache.test.ts +++ b/packages/cache/__tests__/saveCache.test.ts @@ -63,17 +63,16 @@ test('save with large cache outputs should fail', async () => { const reserveCacheMock = jest .spyOn(cacheHttpClient, 'reserveCache') .mockImplementation(async () => { - const response: ITypedResponseWithErrorMessage = { + const response: ITypedResponse = { statusCode: 400, result: null, - headers: {}, - typeKey: 'InvalidReserveCacheRequestException' + headers: {} } return response }) await expect(saveCache([filePath], primaryKey)).rejects.toThrowError( - 'Cache size of ~11264 MB (11811160064 B) is over the data cap limit, not saving cache.' + 'Cache size of ~11264 MB (11811160064 B) is over the 10GB limit, not saving cache.' ) const archiveFolder = '/foo/bar' @@ -94,7 +93,7 @@ test('save with reserve cache failure should fail', async () => { const reserveCacheMock = jest .spyOn(cacheHttpClient, 'reserveCache') .mockImplementation(async () => { - const response: ITypedResponseWithErrorMessage = { + const response: ITypedResponse = { statusCode: 500, result: null, headers: {} diff --git a/packages/cache/src/cache.ts b/packages/cache/src/cache.ts index aea2c560..7d8cd3cb 100644 --- a/packages/cache/src/cache.ts +++ b/packages/cache/src/cache.ts @@ -171,9 +171,17 @@ export async function saveCache( if (core.isDebug()) { await listTar(archivePath, compressionMethod) } - + const fileSizeLimit = 10 * 1024 * 1024 * 1024 // 10GB per repo limit const archiveFileSize = utils.getArchiveFileSizeInBytes(archivePath) core.debug(`File Size: ${archiveFileSize}`) + // For GHES, this check will take place in ReserveCache API with enterprise file size limit + if (archiveFileSize > fileSizeLimit && !utils.isGhes()) { + throw new Error( + `Cache size of ~${Math.round( + archiveFileSize / (1024 * 1024) + )} MB (${archiveFileSize} B) is over the 10GB limit, not saving cache.` + ) + } const cacheSize = archiveFileSize core.debug('Reserving Cache') @@ -186,20 +194,15 @@ export async function saveCache( } ) - if ( - reserveCacheResponse?.statusCode === 400 && - reserveCacheResponse?.typeKey === 'InvalidReserveCacheRequestException' - ) { + if (reserveCacheResponse?.result?.cacheId) { + cacheId = reserveCacheResponse?.result?.cacheId + } else if (reserveCacheResponse?.statusCode === 400) { throw new ReserveCacheError( - reserveCacheResponse?.message ?? + reserveCacheResponse?.error?.message ?? `Cache size of ~${Math.round( archiveFileSize / (1024 * 1024) )} MB (${archiveFileSize} B) is over the data cap limit, not saving cache.` ) - } - - if (reserveCacheResponse?.result?.cacheId) { - cacheId = reserveCacheResponse?.result?.cacheId } else { throw new ReserveCacheError( `Unable to reserve cache with key ${key}, another job may be creating this cache.` diff --git a/packages/cache/src/internal/cacheUtils.ts b/packages/cache/src/internal/cacheUtils.ts index 41096102..aefb87b1 100644 --- a/packages/cache/src/internal/cacheUtils.ts +++ b/packages/cache/src/internal/cacheUtils.ts @@ -123,3 +123,10 @@ export function assertDefined(name: string, value?: T): T { return value } + +export function isGhes(): boolean { + const ghUrl = new URL( + process.env["GITHUB_SERVER_URL"] || "https://github.com" + ); + return ghUrl.hostname.toUpperCase() !== "GITHUB.COM"; +} diff --git a/packages/cache/src/internal/contracts.d.ts b/packages/cache/src/internal/contracts.d.ts index 75568cd0..1fe54a57 100644 --- a/packages/cache/src/internal/contracts.d.ts +++ b/packages/cache/src/internal/contracts.d.ts @@ -1,9 +1,9 @@ import {CompressionMethod} from './constants' import {ITypedResponse} from '@actions/http-client/interfaces' +import {HttpClientError} from '@actions/http-client' export interface ITypedResponseWithErrorMessage extends ITypedResponse { - message?: string - typeKey?: string + error?: HttpClientError } export interface ArtifactCacheEntry { diff --git a/packages/cache/src/internal/requestUtils.ts b/packages/cache/src/internal/requestUtils.ts index 41546b3e..7a4ba77a 100644 --- a/packages/cache/src/internal/requestUtils.ts +++ b/packages/cache/src/internal/requestUtils.ts @@ -110,8 +110,7 @@ export async function retryTypedResponse( statusCode: error.statusCode, result: null, headers: {}, - message: error.message, - typeKey: error.result.typeKey + error: error } } else { return undefined