From 06d64212d364ab70643cf38d3853d22bbc164705 Mon Sep 17 00:00:00 2001 From: Daz DeBoer Date: Mon, 17 Jan 2022 12:20:31 -0700 Subject: [PATCH] Initialize the Gradle User Home even when caching is disabled --- src/caches.ts | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/caches.ts b/src/caches.ts index 498ba76..1822c34 100644 --- a/src/caches.ts +++ b/src/caches.ts @@ -8,13 +8,22 @@ const GRADLE_USER_HOME = 'GRADLE_USER_HOME' const CACHE_LISTENER = 'CACHE_LISTENER' export async function restore(gradleUserHome: string): Promise { - if (!shouldRestoreCaches()) { + // Only restore cache on first action step in workflow. + if (process.env[CACHE_RESTORED_VAR]) { + core.info('Cache only restored on first action step.') return } + 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.') + return + } + await core.group('Restore Gradle state from cache', async () => { core.saveState(GRADLE_USER_HOME, gradleUserHome) @@ -24,8 +33,6 @@ export async function restore(gradleUserHome: string): Promise { core.saveState(CACHE_LISTENER, cacheListener.stringify()) }) - // Export var that is detected in all later restore steps - core.exportVariable(CACHE_RESTORED_VAR, true) // Export state that is detected in corresponding post-action step core.saveState(CACHE_RESTORED_VAR, true) } @@ -51,19 +58,6 @@ export async function save(): Promise { logCachingReport(cacheListener) } -function shouldRestoreCaches(): boolean { - if (isCacheDisabled()) { - core.info('Cache is disabled: will not restore state from previous builds.') - return false - } - - if (process.env[CACHE_RESTORED_VAR]) { - core.info('Cache only restored on first action step.') - return false - } - return true -} - function shouldSaveCaches(): boolean { if (isCacheDisabled()) { core.info('Cache is disabled: will not save state for later builds.')