Improve formatting for caching report

This commit is contained in:
Daz DeBoer 2021-10-30 07:39:21 -06:00
parent 75cec40e58
commit 6ca4d4ade2
No known key found for this signature in database
GPG key ID: DD6B9F0B06683D5D
3 changed files with 18 additions and 11 deletions

View file

@ -132,7 +132,7 @@ export abstract class AbstractCache {
}
const cacheKey = this.prepareCacheKey()
const entryReport = listener.entry(this.cacheName)
const entryReport = listener.entry(this.cacheDescription)
entryReport.markRequested(cacheKey.key, cacheKey.restoreKeys)
this.debug(

View file

@ -10,7 +10,7 @@ const PATHS_TO_CACHE = [
export class ProjectDotGradleCache extends AbstractCache {
private rootDir: string
constructor(rootDir: string) {
super('project', 'Project .gradle directory')
super('project', 'Project configuration cache')
this.rootDir = rootDir
}

View file

@ -5,7 +5,7 @@ import {isCacheDisabled, isCacheReadOnly} from './cache-utils'
import {CacheListener} from './cache-base'
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> {
if (isCacheDisabled()) {
@ -29,29 +29,36 @@ export async function restore(buildRootDirectory: string): Promise<void> {
projectDotGradleCache.prepareCacheKey()
}
core.saveState(CACHING_REPORT, cacheListener.stringify())
core.saveState(CACHE_LISTENER, cacheListener.stringify())
})
}
export async function save(): Promise<void> {
const cacheListener: CacheListener = CacheListener.rehydrate(core.getState(CACHE_LISTENER))
if (isCacheReadOnly()) {
core.info('Cache is read-only: will not save state for use in subsequent builds.')
logCachingReport(cacheListener)
return
}
const cachingReport: CacheListener = CacheListener.rehydrate(core.getState(CACHING_REPORT))
await core.group('Caching Gradle state', async () => {
const buildRootDirectory = core.getState(BUILD_ROOT_DIR)
return Promise.all([
new GradleUserHomeCache(buildRootDirectory).save(cachingReport),
new ProjectDotGradleCache(buildRootDirectory).save(cachingReport)
new GradleUserHomeCache(buildRootDirectory).save(cacheListener),
new ProjectDotGradleCache(buildRootDirectory).save(cacheListener)
])
})
logCachingReport(cachingReport)
logCachingReport(cacheListener)
}
function logCachingReport(report: CacheListener): void {
core.info(JSON.stringify(report, null, 2))
function logCachingReport(listener: CacheListener): void {
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 ?? ''}`)
}
}