Track 'fully-restored' by tracking each cache restore

Instead of tracking a single 'fully-restored' flag, track the restore status of each
cache entry restore. If any of these are requested but not restored, then the overall
Gradle User Home cache is not fully restored.

Added special handling for the case when zero artifact bundles are set: this is used
in tests to simulate a not-fully-restored state.
This commit is contained in:
Daz DeBoer
2021-10-29 10:19:35 -06:00
parent 9edc2a11bd
commit 8ba5a0033b
3 changed files with 97 additions and 31 deletions

View File

@@ -1,7 +1,7 @@
import {GradleUserHomeCache} from './cache-gradle-user-home'
import {ProjectDotGradleCache} from './cache-project-dot-gradle'
import * as core from '@actions/core'
import {isCacheDisabled, isCacheReadOnly} from './cache-utils'
import {CachingReport, isCacheDisabled, isCacheReadOnly} from './cache-utils'
const BUILD_ROOT_DIR = 'BUILD_ROOT_DIR'
@@ -13,12 +13,15 @@ export async function restore(buildRootDirectory: string): Promise<void> {
await core.group('Restore Gradle state from cache', async () => {
core.saveState(BUILD_ROOT_DIR, buildRootDirectory)
const gradleHomeRestore = await new GradleUserHomeCache(buildRootDirectory).restore()
const cachingReport = new CachingReport()
await new GradleUserHomeCache(buildRootDirectory).restore(cachingReport)
const projectDotGradleCache = new ProjectDotGradleCache(buildRootDirectory)
if (gradleHomeRestore.fullyRestored) {
if (cachingReport.fullyRestored) {
// Only restore the configuration-cache if the Gradle Home is fully restored
await projectDotGradleCache.restore()
await projectDotGradleCache.restore(cachingReport)
} else {
// Otherwise, prepare the cache key for later save()
projectDotGradleCache.prepareCacheKey()