From 3aa7bfe163af67048d1ff279d70a090a67f9de1d Mon Sep 17 00:00:00 2001 From: Daz DeBoer Date: Mon, 17 Jan 2022 12:38:14 -0700 Subject: [PATCH] Initialize pre-existing Gradle User Home --- src/cache-base.ts | 6 ++++++ src/caches.ts | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/src/cache-base.ts b/src/cache-base.ts index acfa556..8657956 100644 --- a/src/cache-base.ts +++ b/src/cache-base.ts @@ -99,6 +99,12 @@ export class GradleStateCache { this.initializeGradleUserHome(this.gradleUserHome, initScriptsDir) } + 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)) + } + /** * Restores the cache entry, finding the closest match to the currently running job. */ diff --git a/src/caches.ts b/src/caches.ts index 1822c34..b640ef8 100644 --- a/src/caches.ts +++ b/src/caches.ts @@ -17,6 +17,13 @@ export async function restore(gradleUserHome: string): Promise { // Initialize the Gradle User Home even when caching is disabled. const gradleStateCache = new GradleStateCache(gradleUserHome) + if (gradleStateCache.cacheOutputExists()) { + core.info('Gradle User Home already exists: will not restore from cache.') + // We still add init-scripts for build-scan capture + gradleStateCache.init() + return + } + gradleStateCache.init() if (isCacheDisabled()) {