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()) {