Skip to content

Commit

Permalink
Add logs for cache version on miss
Browse files Browse the repository at this point in the history
  • Loading branch information
Phantsure authored Nov 14, 2022
1 parent 436cf8d commit 4b34808
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
18 changes: 17 additions & 1 deletion packages/cache/src/internal/cacheHttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import {
CommitCacheRequest,
ReserveCacheRequest,
ReserveCacheResponse,
ITypedResponseWithError
ITypedResponseWithError,
ArtifactCacheList
} from './contracts'
import {downloadCacheHttpClient, downloadCacheStorageSDK} from './downloadUtils'
import {
Expand Down Expand Up @@ -113,6 +114,21 @@ export async function getCacheEntry(
const cacheResult = response.result
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}`)
})
}
}

throw new Error('Cache not found.')
}
core.setSecret(cacheDownloadUrl)
Expand Down
6 changes: 6 additions & 0 deletions packages/cache/src/internal/contracts.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ export interface ITypedResponseWithError<T> extends TypedResponse<T> {
export interface ArtifactCacheEntry {
cacheKey?: string
scope?: string
cacheVersion?: string
creationTime?: string
archiveLocation?: string
}

export interface ArtifactCacheList {
totalCount: number
artifactCaches?: ArtifactCacheEntry[]
}

export interface CommitCacheRequest {
size: number
}
Expand Down

0 comments on commit 4b34808

Please sign in to comment.