Skip to content

Commit

Permalink
Report on read-only / write-only cache
Browse files Browse the repository at this point in the history
  • Loading branch information
bigdaz committed Jun 3, 2022
1 parent 1437742 commit 03b924c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
33 changes: 24 additions & 9 deletions src/cache-reporting.ts
Expand Up @@ -6,6 +6,8 @@ import * as core from '@actions/core'
*/
export class CacheListener {
cacheEntries: CacheEntryListener[] = []
isCacheReadOnly = false
isCacheWriteOnly = false

get fullyRestored(): boolean {
return this.cacheEntries.every(x => !x.wasRequestedButNotRestored())
Expand Down Expand Up @@ -108,10 +110,10 @@ export function logCachingReport(listener: CacheListener): void {
Requested Key : ${entry.requestedKey ?? ''}
Restored Key : ${entry.restoredKey ?? ''}
Size: ${formatSize(entry.restoredSize)}
${getRestoredMessage(entry)}
${getRestoredMessage(entry, listener.isCacheWriteOnly)}
Saved Key : ${entry.savedKey ?? ''}
Size: ${formatSize(entry.savedSize)}
${getSavedMessage(entry)}
${getSavedMessage(entry, listener.isCacheReadOnly)}
---`
)
.join('\n')
Expand All @@ -133,6 +135,13 @@ export function logCachingReport(listener: CacheListener): void {
`
)

if (listener.isCacheReadOnly) {
core.summary.addRaw('- **Cache is read-only**\n')
}
if (listener.isCacheWriteOnly) {
core.summary.addRaw('- **Cache is write-only**\n')
}

core.summary.addDetails(
'Cache Entry Details',
`
Expand All @@ -144,25 +153,31 @@ ${entries}
)
}

function getRestoredMessage(entry: CacheEntryListener): string {
function getRestoredMessage(entry: CacheEntryListener, isCacheWriteOnly: boolean): string {
if (isCacheWriteOnly) {
return '(Entry not restored: cache is write-only)'
}
if (entry.restoredKey === undefined) {
return '(No match found)'
return '(Entry not restored: no match found)'
}
if (entry.restoredKey === entry.requestedKey) {
return '(Exact match found)'
return '(Entry restored: exact match found)'
}
return '(Fuzzy match found)'
return '(Entry restored: partial match found)'
}

function getSavedMessage(entry: CacheEntryListener): string {
function getSavedMessage(entry: CacheEntryListener, isCacheReadOnly: boolean): string {
if (entry.unchanged) {
return `(Entry not saved: ${entry.unchanged})`
}
if (entry.savedKey === undefined) {
return '(Entry not saved: ???'
if (isCacheReadOnly) {
return '(Entry not saved: cache is read-only)'
}
return '(Entry not saved: reason unknown)'
}
if (entry.savedSize === 0) {
return '(Could not save: entry exists)'
return '(Entry not saved: entry with key already exists)'
}
return '(Entry saved)'
}
Expand Down
2 changes: 2 additions & 0 deletions src/caches.ts
Expand Up @@ -35,6 +35,7 @@ export async function restore(gradleUserHome: string, cacheListener: CacheListen

if (isCacheWriteOnly()) {
core.info('Cache is write-only: will not restore from cache.')
cacheListener.isCacheWriteOnly = true
return
}

Expand All @@ -50,6 +51,7 @@ export async function save(gradleUserHome: string, cacheListener: CacheListener)

if (isCacheReadOnly()) {
core.info('Cache is read-only: will not save state for use in subsequent builds.')
cacheListener.isCacheReadOnly = true
return
}

Expand Down

0 comments on commit 03b924c

Please sign in to comment.