Report sizes of cache entries

Using the patched version of @actions/cache, we now report the total
size of cache entries restored/saved, as well as details of each one.
This commit is contained in:
Daz DeBoer 2021-10-30 12:17:41 -06:00
parent 3ba05ede1f
commit 472ac8a356
No known key found for this signature in database
GPG key ID: DD6B9F0B06683D5D
4 changed files with 63 additions and 26 deletions

View file

@ -98,13 +98,15 @@ export class CacheEntryListener {
return this
}
markRestored(key: string): CacheEntryListener {
markRestored(key: string, size: number | undefined): CacheEntryListener {
this.restoredKey = key
this.restoredSize = size
return this
}
markSaved(key: string): CacheEntryListener {
markSaved(key: string, size: number | undefined): CacheEntryListener {
this.savedKey = key
this.savedSize = size
return this
}
}
@ -149,7 +151,7 @@ export abstract class AbstractCache {
}
core.saveState(this.cacheResultStateKey, cacheResult)
entryReport.markRestored(cacheResult)
entryReport.markRestored(cacheResult.key, cacheResult.size)
core.info(`Restored ${this.cacheDescription} from cache key: ${cacheResult}`)
try {
@ -170,7 +172,7 @@ export abstract class AbstractCache {
cachePath: string[],
cacheKey: string,
cacheRestoreKeys: string[] = []
): Promise<string | undefined> {
): Promise<cache.CacheEntry | undefined> {
try {
return await cache.restoreCache(cachePath, cacheKey, cacheRestoreKeys)
} catch (error) {
@ -214,18 +216,20 @@ export abstract class AbstractCache {
core.info(`Caching ${this.cacheDescription} with cache key: ${cacheKey}`)
const cachePath = this.getCachePath()
await this.saveCache(cachePath, cacheKey)
const savedEntry = await this.saveCache(cachePath, cacheKey)
listener.entry(this.cacheDescription).markSaved(cacheKey)
if (savedEntry) {
listener.entry(this.cacheDescription).markSaved(savedEntry.key, savedEntry.size)
}
return
}
protected async beforeSave(_listener: CacheListener): Promise<void> {}
protected async saveCache(cachePath: string[], cacheKey: string): Promise<void> {
protected async saveCache(cachePath: string[], cacheKey: string): Promise<cache.CacheEntry | undefined> {
try {
await cache.saveCache(cachePath, cacheKey)
return await cache.saveCache(cachePath, cacheKey)
} catch (error) {
if (error instanceof cache.ValidationError) {
// Validation errors should fail the build action
@ -238,6 +242,7 @@ export abstract class AbstractCache {
core.warning(String(error))
}
}
return undefined
}
protected debug(message: string): void {