Only stop Gradle Daemons when saving Gradle User Home state

Fixes #341
This commit is contained in:
Daz DeBoer 2022-06-22 16:39:34 -06:00
parent 884bca012f
commit 6965e8ed4c
No known key found for this signature in database
GPG key ID: DD6B9F0B06683D5D
3 changed files with 10 additions and 4 deletions

View file

@ -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<void> {
export async function save(
gradleUserHome: string,
cacheListener: CacheListener,
daemonController: DaemonController
): Promise<void> {
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)
})

View file

@ -13,7 +13,7 @@ export class DaemonController {
}
async stopAllDaemons(): Promise<void> {
core.info('Stopping all Gradle daemons')
core.info('Stopping all Gradle daemons before saving Gradle User Home state')
const executions: Promise<number>[] = []
const args = ['--stop']

View file

@ -59,8 +59,7 @@ export async function complete(): Promise<void> {
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)