From 4b348086a9879d63ab98241f20231d985a4248a1 Mon Sep 17 00:00:00 2001 From: Sampark Sharma Date: Mon, 14 Nov 2022 05:24:09 +0000 Subject: [PATCH] Add logs for cache version on miss --- packages/cache/src/internal/cacheHttpClient.ts | 18 +++++++++++++++++- packages/cache/src/internal/contracts.d.ts | 6 ++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/packages/cache/src/internal/cacheHttpClient.ts b/packages/cache/src/internal/cacheHttpClient.ts index c66d1a73..922c2750 100644 --- a/packages/cache/src/internal/cacheHttpClient.ts +++ b/packages/cache/src/internal/cacheHttpClient.ts @@ -17,7 +17,8 @@ import { CommitCacheRequest, ReserveCacheRequest, ReserveCacheResponse, - ITypedResponseWithError + ITypedResponseWithError, + ArtifactCacheList } from './contracts' import {downloadCacheHttpClient, downloadCacheStorageSDK} from './downloadUtils' import { @@ -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(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) diff --git a/packages/cache/src/internal/contracts.d.ts b/packages/cache/src/internal/contracts.d.ts index 1b2a13a1..b5f53bdc 100644 --- a/packages/cache/src/internal/contracts.d.ts +++ b/packages/cache/src/internal/contracts.d.ts @@ -9,10 +9,16 @@ export interface ITypedResponseWithError extends TypedResponse { 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 }