1
0
Fork 0

Address review comments

pull/1268/head
Sampark Sharma 2022-11-15 10:32:24 +00:00 committed by GitHub
parent a735d9bcd4
commit aaac0e6c98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 14 deletions

View File

@ -115,20 +115,7 @@ export async function getCacheEntry(
const cacheDownloadUrl = cacheResult?.archiveLocation const cacheDownloadUrl = cacheResult?.archiveLocation
if (!cacheDownloadUrl) { if (!cacheDownloadUrl) {
// List cache for primary key only if cache miss occurs // List cache for primary key only if cache miss occurs
const resource = `caches?key=${encodeURIComponent(keys[0])}` await listCache(keys[0], httpClient, version)
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}`)
})
}
}
throw new Error('Cache not found.') throw new Error('Cache not found.')
} }
core.setSecret(cacheDownloadUrl) core.setSecret(cacheDownloadUrl)
@ -138,6 +125,32 @@ export async function getCacheEntry(
return cacheResult 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( export async function downloadCache(
archiveLocation: string, archiveLocation: string,
archivePath: string, archivePath: string,