From aaac0e6c9895ec46d5d87b004b063b325681a35b Mon Sep 17 00:00:00 2001 From: Sampark Sharma Date: Tue, 15 Nov 2022 10:32:24 +0000 Subject: [PATCH] Address review comments --- .../cache/src/internal/cacheHttpClient.ts | 41 ++++++++++++------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/packages/cache/src/internal/cacheHttpClient.ts b/packages/cache/src/internal/cacheHttpClient.ts index 922c2750..6d2cccde 100644 --- a/packages/cache/src/internal/cacheHttpClient.ts +++ b/packages/cache/src/internal/cacheHttpClient.ts @@ -115,20 +115,7 @@ export async function getCacheEntry( const cacheDownloadUrl = cacheResult?.archiveLocation if (!cacheDownloadUrl) { // List cache for primary key only if cache miss occurs - const resource = `caches?key=${encodeURIComponent(keys[0])}` - const response = await httpClient.getJson(getCacheApiUrl(resource)) - if(response.statusCode === 204) { - const cacheListResult = response.result - const totalCount = cacheListResult?.totalCount - if(totalCount && totalCount > 0) { - core.info(`Cache miss occurred on the cache key '${keys[0]}' and version '${version} but there is ${totalCount} existing version of the cache for this key. More info on versioning can be found here: https://github.com/actions/cache#cache-version`) - core.debug(`Other versions are as follows:`) - cacheListResult?.artifactCaches?.forEach(cacheEntry => { - core.debug(`Cache Key: ${cacheEntry?.cacheKey}, Cache Version: ${cacheEntry?.cacheVersion}, Cache Scope: ${cacheEntry?.scope}, Cache Created: ${cacheEntry?.creationTime}`) - }) - } - } - + await listCache(keys[0], httpClient, version) throw new Error('Cache not found.') } core.setSecret(cacheDownloadUrl) @@ -138,6 +125,32 @@ export async function getCacheEntry( return cacheResult } +async function listCache( + key: string, + httpClient: HttpClient, + version: string +): Promise { + const resource = `caches?key=${encodeURIComponent(key)}` + const response = await retryTypedResponse('listCache', async () => + httpClient.getJson(getCacheApiUrl(resource)) + ) + if (response.statusCode === 204) { + const cacheListResult = response.result + const totalCount = cacheListResult?.totalCount + if (totalCount && totalCount > 0) { + core.info( + `Cache miss occurred on the cache key '${key}' and version '${version} but there is ${totalCount} existing version of the cache for this key. More info on versioning can be found here: https://github.com/actions/cache#cache-version` + ) + core.debug(`Other versions are as follows:`) + cacheListResult?.artifactCaches?.forEach(cacheEntry => { + core.debug( + `Cache Key: ${cacheEntry?.cacheKey}, Cache Version: ${cacheEntry?.cacheVersion}, Cache Scope: ${cacheEntry?.scope}, Cache Created: ${cacheEntry?.creationTime}` + ) + }) + } + } +} + export async function downloadCache( archiveLocation: string, archivePath: string,