mirror of
				https://github.com/gradle/gradle-build-action.git
				synced 2025-11-04 09:58:56 +08:00 
			
		
		
		
	Add more details to cache summary report
This commit is contained in:
		@@ -95,9 +95,11 @@ export class GradleStateCache {
 | 
			
		||||
    async save(listener: CacheListener): Promise<void> {
 | 
			
		||||
        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
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user