Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Phantsure authored Nov 15, 2022
1 parent a735d9b commit aaac0e6
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions packages/cache/src/internal/cacheHttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ArtifactCacheList>(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)
Expand All @@ -138,6 +125,32 @@ export async function getCacheEntry(
return cacheResult
}

async function listCache(
key: string,
httpClient: HttpClient,
version: string
): Promise<void> {
const resource = `caches?key=${encodeURIComponent(key)}`
const response = await retryTypedResponse('listCache', async () =>
httpClient.getJson<ArtifactCacheList>(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,
Expand Down

0 comments on commit aaac0e6

Please sign in to comment.