mirror of
https://github.com/gradle/gradle-build-action.git
synced 2024-11-25 18:42:09 +00:00
Add more details to cache summary report
This commit is contained in:
parent
a9a5bcf180
commit
143774290e
3 changed files with 38 additions and 3 deletions
|
@ -95,9 +95,11 @@ export class GradleStateCache {
|
||||||
async save(listener: CacheListener): Promise<void> {
|
async save(listener: CacheListener): Promise<void> {
|
||||||
const cacheKey = generateCacheKey(this.cacheName).key
|
const cacheKey = generateCacheKey(this.cacheName).key
|
||||||
const restoredCacheKey = core.getState(RESTORED_CACHE_KEY_KEY)
|
const restoredCacheKey = core.getState(RESTORED_CACHE_KEY_KEY)
|
||||||
|
const entryListener = listener.entry(this.cacheDescription)
|
||||||
|
|
||||||
if (restoredCacheKey && cacheKey === restoredCacheKey) {
|
if (restoredCacheKey && cacheKey === restoredCacheKey) {
|
||||||
core.info(`Cache hit occurred on the cache key ${cacheKey}, not saving cache.`)
|
core.info(`Cache hit occurred on the cache key ${cacheKey}, not saving cache.`)
|
||||||
|
entryListener.markUnchanged('cache key not changed')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +112,6 @@ export class GradleStateCache {
|
||||||
|
|
||||||
core.info(`Caching ${this.cacheDescription} with cache key: ${cacheKey}`)
|
core.info(`Caching ${this.cacheDescription} with cache key: ${cacheKey}`)
|
||||||
const cachePath = this.getCachePath()
|
const cachePath = this.getCachePath()
|
||||||
const entryListener = listener.entry(this.cacheDescription)
|
|
||||||
await saveCache(cachePath, cacheKey, entryListener)
|
await saveCache(cachePath, cacheKey, entryListener)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
@ -212,6 +212,7 @@ abstract class AbstractEntryExtractor {
|
||||||
|
|
||||||
if (previouslyRestoredKey === cacheKey) {
|
if (previouslyRestoredKey === cacheKey) {
|
||||||
cacheDebug(`No change to previously restored ${artifactType}. Not saving.`)
|
cacheDebug(`No change to previously restored ${artifactType}. Not saving.`)
|
||||||
|
entryListener.markUnchanged('entry contents unchanged')
|
||||||
} else {
|
} else {
|
||||||
core.info(`Caching ${artifactType} with path '${pattern}' and cache key: ${cacheKey}`)
|
core.info(`Caching ${artifactType} with path '${pattern}' and cache key: ${cacheKey}`)
|
||||||
await saveCache([pattern], cacheKey, entryListener)
|
await saveCache([pattern], cacheKey, entryListener)
|
||||||
|
|
|
@ -54,6 +54,8 @@ export class CacheEntryListener {
|
||||||
savedKey: string | undefined
|
savedKey: string | undefined
|
||||||
savedSize: number | undefined
|
savedSize: number | undefined
|
||||||
|
|
||||||
|
unchanged: string | undefined
|
||||||
|
|
||||||
constructor(entryName: string) {
|
constructor(entryName: string) {
|
||||||
this.entryName = entryName
|
this.entryName = entryName
|
||||||
}
|
}
|
||||||
|
@ -85,6 +87,11 @@ export class CacheEntryListener {
|
||||||
this.savedSize = 0
|
this.savedSize = 0
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
markUnchanged(message: string): CacheEntryListener {
|
||||||
|
this.unchanged = message
|
||||||
|
return this
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function logCachingReport(listener: CacheListener): void {
|
export function logCachingReport(listener: CacheListener): void {
|
||||||
|
@ -92,7 +99,7 @@ export function logCachingReport(listener: CacheListener): void {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
core.summary.addHeading('Caching Summary', 3)
|
core.summary.addHeading('Gradle Home Caching Summary', 3)
|
||||||
|
|
||||||
const entries = listener.cacheEntries
|
const entries = listener.cacheEntries
|
||||||
.map(
|
.map(
|
||||||
|
@ -101,8 +108,11 @@ export function logCachingReport(listener: CacheListener): void {
|
||||||
Requested Key : ${entry.requestedKey ?? ''}
|
Requested Key : ${entry.requestedKey ?? ''}
|
||||||
Restored Key : ${entry.restoredKey ?? ''}
|
Restored Key : ${entry.restoredKey ?? ''}
|
||||||
Size: ${formatSize(entry.restoredSize)}
|
Size: ${formatSize(entry.restoredSize)}
|
||||||
|
${getRestoredMessage(entry)}
|
||||||
Saved Key : ${entry.savedKey ?? ''}
|
Saved Key : ${entry.savedKey ?? ''}
|
||||||
Size: ${formatSize(entry.savedSize)}`
|
Size: ${formatSize(entry.savedSize)}
|
||||||
|
${getSavedMessage(entry)}
|
||||||
|
---`
|
||||||
)
|
)
|
||||||
.join('\n')
|
.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(
|
function getCount(
|
||||||
cacheEntries: CacheEntryListener[],
|
cacheEntries: CacheEntryListener[],
|
||||||
predicate: (value: CacheEntryListener) => number | undefined
|
predicate: (value: CacheEntryListener) => number | undefined
|
||||||
|
|
Loading…
Reference in a new issue