From 7dee0f45c22f5290744ee7cf90c38e6de41e42f0 Mon Sep 17 00:00:00 2001 From: Daz DeBoer Date: Mon, 17 Jan 2022 14:06:56 -0700 Subject: [PATCH] Fix check for pre-existing Gradle User Home --- src/cache-base.ts | 9 +++++++-- src/caches.ts | 8 ++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/cache-base.ts b/src/cache-base.ts index 8657956..e0200fe 100644 --- a/src/cache-base.ts +++ b/src/cache-base.ts @@ -100,9 +100,14 @@ export class GradleStateCache { } cacheOutputExists(): boolean { - // Need to check for 'caches' directory to avoid incorrect detection on MacOS agents const paths = this.getCachePath() - return paths.some(x => fs.existsSync(x)) + for (const p of paths) { + if (fs.existsSync(p)) { + cacheDebug(`Cache output exists at ${p}`) + return true + } + } + return false } /** diff --git a/src/caches.ts b/src/caches.ts index 68d83df..9b3653e 100644 --- a/src/caches.ts +++ b/src/caches.ts @@ -15,20 +15,24 @@ export async function restore(gradleUserHome: string): Promise { } core.exportVariable(CACHE_RESTORED_VAR, true) - // Initialize the Gradle User Home even when caching is disabled. const gradleStateCache = new GradleStateCache(gradleUserHome) - gradleStateCache.init() if (isCacheDisabled()) { core.info('Cache is disabled: will not restore state from previous builds.') + // Initialize the Gradle User Home even when caching is disabled. + gradleStateCache.init() return } if (gradleStateCache.cacheOutputExists()) { core.info('Gradle User Home already exists: will not restore from cache.') + // Initialize pre-existing Gradle User Home. + gradleStateCache.init() return } + gradleStateCache.init() + await core.group('Restore Gradle state from cache', async () => { core.saveState(GRADLE_USER_HOME, gradleUserHome)