mirror of
https://github.com/gradle/gradle-build-action.git
synced 2024-11-26 11:02:10 +00:00
Avoid printing "reason unknown" for extract entries
This was happening when the main Gradle User Home entry was not saved due to having an unchanged cache key. Fixes #309
This commit is contained in:
parent
e88ed3e650
commit
7a15005377
3 changed files with 17 additions and 13 deletions
|
@ -94,11 +94,18 @@ export class GradleStateCache {
|
||||||
async save(listener: CacheListener): Promise<void> {
|
async save(listener: CacheListener): Promise<void> {
|
||||||
const cacheKey = generateCacheKey(this.cacheName).key
|
const cacheKey = generateCacheKey(this.cacheName).key
|
||||||
const restoredCacheKey = core.getState(RESTORED_CACHE_KEY_KEY)
|
const restoredCacheKey = core.getState(RESTORED_CACHE_KEY_KEY)
|
||||||
const entryListener = listener.entry(this.cacheDescription)
|
const gradleHomeEntryListener = listener.entry(this.cacheDescription)
|
||||||
|
|
||||||
if (restoredCacheKey && cacheKey === restoredCacheKey) {
|
if (restoredCacheKey && cacheKey === restoredCacheKey) {
|
||||||
core.info(`Cache hit occurred on the cache key ${cacheKey}, not saving cache.`)
|
core.info(`Cache hit occurred on the cache key ${cacheKey}, not saving cache.`)
|
||||||
entryListener.markUnchanged('cache key not changed')
|
|
||||||
|
for (const entryListener of listener.cacheEntries) {
|
||||||
|
if (entryListener === gradleHomeEntryListener) {
|
||||||
|
entryListener.markUnsaved('cache key not changed')
|
||||||
|
} else {
|
||||||
|
entryListener.markUnsaved(`referencing '${this.cacheDescription}' cache entry not saved`)
|
||||||
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +118,7 @@ export class GradleStateCache {
|
||||||
|
|
||||||
core.info(`Caching ${this.cacheDescription} with cache key: ${cacheKey}`)
|
core.info(`Caching ${this.cacheDescription} with cache key: ${cacheKey}`)
|
||||||
const cachePath = this.getCachePath()
|
const cachePath = this.getCachePath()
|
||||||
await saveCache(cachePath, cacheKey, entryListener)
|
await saveCache(cachePath, cacheKey, gradleHomeEntryListener)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,7 +213,7 @@ abstract class AbstractEntryExtractor {
|
||||||
|
|
||||||
if (previouslyRestoredKey === cacheKey) {
|
if (previouslyRestoredKey === cacheKey) {
|
||||||
cacheDebug(`No change to previously restored ${artifactType}. Not saving.`)
|
cacheDebug(`No change to previously restored ${artifactType}. Not saving.`)
|
||||||
entryListener.markUnchanged('contents unchanged')
|
entryListener.markUnsaved('contents unchanged')
|
||||||
} else {
|
} else {
|
||||||
core.info(`Caching ${artifactType} with path '${pattern}' and cache key: ${cacheKey}`)
|
core.info(`Caching ${artifactType} with path '${pattern}' and cache key: ${cacheKey}`)
|
||||||
await saveCache([pattern], cacheKey, entryListener)
|
await saveCache([pattern], cacheKey, entryListener)
|
||||||
|
|
|
@ -64,7 +64,7 @@ export class CacheEntryListener {
|
||||||
savedKey: string | undefined
|
savedKey: string | undefined
|
||||||
savedSize: number | undefined
|
savedSize: number | undefined
|
||||||
|
|
||||||
unchanged: string | undefined
|
unsaved: string | undefined
|
||||||
|
|
||||||
constructor(entryName: string) {
|
constructor(entryName: string) {
|
||||||
this.entryName = entryName
|
this.entryName = entryName
|
||||||
|
@ -98,8 +98,8 @@ export class CacheEntryListener {
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
markUnchanged(message: string): CacheEntryListener {
|
markUnsaved(message: string): CacheEntryListener {
|
||||||
this.unchanged = message
|
this.unsaved = message
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -159,8 +159,8 @@ function getRestoredMessage(entry: CacheEntryListener, isCacheWriteOnly: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSavedMessage(entry: CacheEntryListener, isCacheReadOnly: boolean): string {
|
function getSavedMessage(entry: CacheEntryListener, isCacheReadOnly: boolean): string {
|
||||||
if (entry.unchanged) {
|
if (entry.unsaved) {
|
||||||
return `(Entry not saved: ${entry.unchanged})`
|
return `(Entry not saved: ${entry.unsaved})`
|
||||||
}
|
}
|
||||||
if (entry.savedKey === undefined) {
|
if (entry.savedKey === undefined) {
|
||||||
if (isCacheReadOnly) {
|
if (isCacheReadOnly) {
|
||||||
|
@ -190,11 +190,8 @@ function getSize(
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatSize(bytes: number | undefined): string {
|
function formatSize(bytes: number | undefined): string {
|
||||||
if (bytes === undefined) {
|
if (bytes === undefined || bytes === 0) {
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
if (bytes === 0) {
|
|
||||||
return '0 (Entry already exists)'
|
|
||||||
}
|
|
||||||
return `${Math.round(bytes / (1024 * 1024))} MB (${bytes} B)`
|
return `${Math.round(bytes / (1024 * 1024))} MB (${bytes} B)`
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue