mirror of
				https://github.com/gradle/gradle-build-action.git
				synced 2025-11-04 09:58:56 +08:00 
			
		
		
		
	Improve formatting for caching report
This commit is contained in:
		@@ -132,7 +132,7 @@ export abstract class AbstractCache {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const cacheKey = this.prepareCacheKey()
 | 
					        const cacheKey = this.prepareCacheKey()
 | 
				
			||||||
        const entryReport = listener.entry(this.cacheName)
 | 
					        const entryReport = listener.entry(this.cacheDescription)
 | 
				
			||||||
        entryReport.markRequested(cacheKey.key, cacheKey.restoreKeys)
 | 
					        entryReport.markRequested(cacheKey.key, cacheKey.restoreKeys)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.debug(
 | 
					        this.debug(
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,7 +10,7 @@ const PATHS_TO_CACHE = [
 | 
				
			|||||||
export class ProjectDotGradleCache extends AbstractCache {
 | 
					export class ProjectDotGradleCache extends AbstractCache {
 | 
				
			||||||
    private rootDir: string
 | 
					    private rootDir: string
 | 
				
			||||||
    constructor(rootDir: string) {
 | 
					    constructor(rootDir: string) {
 | 
				
			||||||
        super('project', 'Project .gradle directory')
 | 
					        super('project', 'Project configuration cache')
 | 
				
			||||||
        this.rootDir = rootDir
 | 
					        this.rootDir = rootDir
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,7 +5,7 @@ import {isCacheDisabled, isCacheReadOnly} from './cache-utils'
 | 
				
			|||||||
import {CacheListener} from './cache-base'
 | 
					import {CacheListener} from './cache-base'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const BUILD_ROOT_DIR = 'BUILD_ROOT_DIR'
 | 
					const BUILD_ROOT_DIR = 'BUILD_ROOT_DIR'
 | 
				
			||||||
const CACHING_REPORT = 'CACHING_REPORT'
 | 
					const CACHE_LISTENER = 'CACHE_LISTENER'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export async function restore(buildRootDirectory: string): Promise<void> {
 | 
					export async function restore(buildRootDirectory: string): Promise<void> {
 | 
				
			||||||
    if (isCacheDisabled()) {
 | 
					    if (isCacheDisabled()) {
 | 
				
			||||||
@@ -29,29 +29,36 @@ export async function restore(buildRootDirectory: string): Promise<void> {
 | 
				
			|||||||
            projectDotGradleCache.prepareCacheKey()
 | 
					            projectDotGradleCache.prepareCacheKey()
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        core.saveState(CACHING_REPORT, cacheListener.stringify())
 | 
					        core.saveState(CACHE_LISTENER, cacheListener.stringify())
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export async function save(): Promise<void> {
 | 
					export async function save(): Promise<void> {
 | 
				
			||||||
 | 
					    const cacheListener: CacheListener = CacheListener.rehydrate(core.getState(CACHE_LISTENER))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (isCacheReadOnly()) {
 | 
					    if (isCacheReadOnly()) {
 | 
				
			||||||
        core.info('Cache is read-only: will not save state for use in subsequent builds.')
 | 
					        core.info('Cache is read-only: will not save state for use in subsequent builds.')
 | 
				
			||||||
 | 
					        logCachingReport(cacheListener)
 | 
				
			||||||
        return
 | 
					        return
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const cachingReport: CacheListener = CacheListener.rehydrate(core.getState(CACHING_REPORT))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    await core.group('Caching Gradle state', async () => {
 | 
					    await core.group('Caching Gradle state', async () => {
 | 
				
			||||||
        const buildRootDirectory = core.getState(BUILD_ROOT_DIR)
 | 
					        const buildRootDirectory = core.getState(BUILD_ROOT_DIR)
 | 
				
			||||||
        return Promise.all([
 | 
					        return Promise.all([
 | 
				
			||||||
            new GradleUserHomeCache(buildRootDirectory).save(cachingReport),
 | 
					            new GradleUserHomeCache(buildRootDirectory).save(cacheListener),
 | 
				
			||||||
            new ProjectDotGradleCache(buildRootDirectory).save(cachingReport)
 | 
					            new ProjectDotGradleCache(buildRootDirectory).save(cacheListener)
 | 
				
			||||||
        ])
 | 
					        ])
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    logCachingReport(cachingReport)
 | 
					    logCachingReport(cacheListener)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function logCachingReport(report: CacheListener): void {
 | 
					function logCachingReport(listener: CacheListener): void {
 | 
				
			||||||
    core.info(JSON.stringify(report, null, 2))
 | 
					    core.info('---------- CACHING REPORT -------------')
 | 
				
			||||||
 | 
					    for (const entry of listener.cacheEntries) {
 | 
				
			||||||
 | 
					        core.info(`${entry.entryName}
 | 
				
			||||||
 | 
					    Requested Key: ${entry.requestedKey ?? ''}
 | 
				
			||||||
 | 
					    Restored Key : ${entry.restoredKey ?? ''}
 | 
				
			||||||
 | 
					    Saved Key    : ${entry.savedKey ?? ''}`)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user