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,