diff --git a/src/cache-base.ts b/src/cache-base.ts index d13b6fd..07af09b 100644 --- a/src/cache-base.ts +++ b/src/cache-base.ts @@ -95,9 +95,11 @@ export class GradleStateCache { async save(listener: CacheListener): Promise { const cacheKey = generateCacheKey(this.cacheName).key const restoredCacheKey = core.getState(RESTORED_CACHE_KEY_KEY) + const entryListener = listener.entry(this.cacheDescription) if (restoredCacheKey && cacheKey === restoredCacheKey) { core.info(`Cache hit occurred on the cache key ${cacheKey}, not saving cache.`) + entryListener.markUnchanged('cache key not changed') return } @@ -110,7 +112,6 @@ export class GradleStateCache { core.info(`Caching ${this.cacheDescription} with cache key: ${cacheKey}`) const cachePath = this.getCachePath() - const entryListener = listener.entry(this.cacheDescription) await saveCache(cachePath, cacheKey, entryListener) return diff --git a/src/cache-extract-entries.ts b/src/cache-extract-entries.ts index 657d0ce..184cf8d 100644 --- a/src/cache-extract-entries.ts +++ b/src/cache-extract-entries.ts @@ -212,6 +212,7 @@ abstract class AbstractEntryExtractor { if (previouslyRestoredKey === cacheKey) { cacheDebug(`No change to previously restored ${artifactType}. Not saving.`) + entryListener.markUnchanged('entry contents unchanged') } else { core.info(`Caching ${artifactType} with path '${pattern}' and cache key: ${cacheKey}`) await saveCache([pattern], cacheKey, entryListener) diff --git a/src/cache-reporting.ts b/src/cache-reporting.ts index ed607cf..fda2e42 100644 --- a/src/cache-reporting.ts +++ b/src/cache-reporting.ts @@ -54,6 +54,8 @@ export class CacheEntryListener { savedKey: string | undefined savedSize: number | undefined + unchanged: string | undefined + constructor(entryName: string) { this.entryName = entryName } @@ -85,6 +87,11 @@ export class CacheEntryListener { this.savedSize = 0 return this } + + markUnchanged(message: string): CacheEntryListener { + this.unchanged = message + return this + } } export function logCachingReport(listener: CacheListener): void { @@ -92,7 +99,7 @@ export function logCachingReport(listener: CacheListener): void { return } - core.summary.addHeading('Caching Summary', 3) + core.summary.addHeading('Gradle Home Caching Summary', 3) const entries = listener.cacheEntries .map( @@ -101,8 +108,11 @@ export function logCachingReport(listener: CacheListener): void { Requested Key : ${entry.requestedKey ?? ''} Restored Key : ${entry.restoredKey ?? ''} Size: ${formatSize(entry.restoredSize)} + ${getRestoredMessage(entry)} Saved Key : ${entry.savedKey ?? ''} - Size: ${formatSize(entry.savedSize)}` + Size: ${formatSize(entry.savedSize)} + ${getSavedMessage(entry)} +---` ) .join('\n') @@ -134,6 +144,29 @@ ${entries} ) } +function getRestoredMessage(entry: CacheEntryListener): string { + if (entry.restoredKey === undefined) { + return '(No match found)' + } + if (entry.restoredKey === entry.requestedKey) { + return '(Exact match found)' + } + return '(Fuzzy match found)' +} + +function getSavedMessage(entry: CacheEntryListener): string { + if (entry.unchanged) { + return `(Entry not saved: ${entry.unchanged})` + } + if (entry.savedKey === undefined) { + return '(Entry not saved: ???' + } + if (entry.savedSize === 0) { + return '(Could not save: entry exists)' + } + return '(Entry saved)' +} + function getCount( cacheEntries: CacheEntryListener[], predicate: (value: CacheEntryListener) => number | undefined