mirror of
https://github.com/gradle/gradle-build-action.git
synced 2024-11-22 17:12:51 +00:00
Only perform post-restore and pre-save cache actions when required
This commit is contained in:
parent
9bfa003014
commit
dbb485d80d
2 changed files with 11 additions and 4 deletions
|
@ -32,8 +32,7 @@ export class GradleUserHomeCache extends AbstractCache {
|
||||||
super('gradle', 'Gradle User Home')
|
super('gradle', 'Gradle User Home')
|
||||||
}
|
}
|
||||||
|
|
||||||
async restore(): Promise<void> {
|
async afterRestore(): Promise<void> {
|
||||||
await super.restore()
|
|
||||||
await this.reportCacheEntrySize('as restored from cache')
|
await this.reportCacheEntrySize('as restored from cache')
|
||||||
await this.restoreCommonArtifacts()
|
await this.restoreCommonArtifacts()
|
||||||
await this.reportCacheEntrySize('after restoring common artifacts')
|
await this.reportCacheEntrySize('after restoring common artifacts')
|
||||||
|
@ -119,9 +118,8 @@ export class GradleUserHomeCache extends AbstractCache {
|
||||||
core.info('-----------------------')
|
core.info('-----------------------')
|
||||||
}
|
}
|
||||||
|
|
||||||
async save(): Promise<void> {
|
async beforeSave(): Promise<void> {
|
||||||
await this.saveCommonArtifacts()
|
await this.saveCommonArtifacts()
|
||||||
await super.save()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async saveCommonArtifacts(): Promise<void> {
|
private async saveCommonArtifacts(): Promise<void> {
|
||||||
|
|
|
@ -109,6 +109,9 @@ export abstract class AbstractCache {
|
||||||
core.info(
|
core.info(
|
||||||
`${this.cacheDescription} restored from cache key: ${cacheResult}`
|
`${this.cacheDescription} restored from cache key: ${cacheResult}`
|
||||||
)
|
)
|
||||||
|
|
||||||
|
await this.afterRestore()
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,6 +137,8 @@ export abstract class AbstractCache {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected async afterRestore(): Promise<void> {}
|
||||||
|
|
||||||
async save(): Promise<void> {
|
async save(): Promise<void> {
|
||||||
if (!this.cacheOutputExists()) {
|
if (!this.cacheOutputExists()) {
|
||||||
this.debug(`No ${this.cacheDescription} to cache.`)
|
this.debug(`No ${this.cacheDescription} to cache.`)
|
||||||
|
@ -157,6 +162,8 @@ export abstract class AbstractCache {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await this.beforeSave()
|
||||||
|
|
||||||
core.info(
|
core.info(
|
||||||
`Caching ${this.cacheDescription} with cache key: ${cacheKey}`
|
`Caching ${this.cacheDescription} with cache key: ${cacheKey}`
|
||||||
)
|
)
|
||||||
|
@ -166,6 +173,8 @@ export abstract class AbstractCache {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected async beforeSave(): Promise<void> {}
|
||||||
|
|
||||||
protected async saveCache(
|
protected async saveCache(
|
||||||
cachePath: string[],
|
cachePath: string[],
|
||||||
cacheKey: string
|
cacheKey: string
|
||||||
|
|
Loading…
Reference in a new issue