From 6965e8ed4cec82001d545c8e86be55efbed42be5 Mon Sep 17 00:00:00 2001 From: Daz DeBoer Date: Wed, 22 Jun 2022 16:39:34 -0600 Subject: [PATCH] Only stop Gradle Daemons when saving Gradle User Home state Fixes #341 --- src/caches.ts | 9 ++++++++- src/daemon-controller.ts | 2 +- src/setup-gradle.ts | 3 +-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/caches.ts b/src/caches.ts index 51e3f70..3490346 100644 --- a/src/caches.ts +++ b/src/caches.ts @@ -1,6 +1,7 @@ import * as core from '@actions/core' import {isCacheDisabled, isCacheReadOnly, isCacheWriteOnly} from './cache-utils' import {CacheListener} from './cache-reporting' +import {DaemonController} from './daemon-controller' import {GradleStateCache} from './cache-base' const CACHE_RESTORED_VAR = 'GRADLE_BUILD_ACTION_CACHE_RESTORED' @@ -45,7 +46,11 @@ export async function restore(gradleUserHome: string, cacheListener: CacheListen }) } -export async function save(gradleUserHome: string, cacheListener: CacheListener): Promise { +export async function save( + gradleUserHome: string, + cacheListener: CacheListener, + daemonController: DaemonController +): Promise { if (isCacheDisabled()) { core.info('Cache is disabled: will not save state for later builds.') return @@ -62,6 +67,8 @@ export async function save(gradleUserHome: string, cacheListener: CacheListener) return } + await daemonController.stopAllDaemons() + await core.group('Caching Gradle state', async () => { return new GradleStateCache(gradleUserHome).save(cacheListener) }) diff --git a/src/daemon-controller.ts b/src/daemon-controller.ts index b063bc1..a77c383 100644 --- a/src/daemon-controller.ts +++ b/src/daemon-controller.ts @@ -13,7 +13,7 @@ export class DaemonController { } async stopAllDaemons(): Promise { - core.info('Stopping all Gradle daemons') + core.info('Stopping all Gradle daemons before saving Gradle User Home state') const executions: Promise[] = [] const args = ['--stop'] diff --git a/src/setup-gradle.ts b/src/setup-gradle.ts index 1ae3197..6c8762c 100644 --- a/src/setup-gradle.ts +++ b/src/setup-gradle.ts @@ -59,8 +59,7 @@ export async function complete(): Promise { const cacheListener: CacheListener = CacheListener.rehydrate(core.getState(CACHE_LISTENER)) const daemonController = new DaemonController(buildResults) - await daemonController.stopAllDaemons() - await caches.save(gradleUserHome, cacheListener) + await caches.save(gradleUserHome, cacheListener, daemonController) if (shouldGenerateJobSummary()) { await writeJobSummary(buildResults, cacheListener)