Skip to content

Commit

Permalink
Only stop Gradle Daemons when saving Gradle User Home state
Browse files Browse the repository at this point in the history
Fixes #341
  • Loading branch information
bigdaz committed Jun 22, 2022
1 parent 884bca0 commit 6965e8e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src/caches.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
Expand All @@ -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)
})
Expand Down
2 changes: 1 addition & 1 deletion src/daemon-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
3 changes: 1 addition & 2 deletions src/setup-gradle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6965e8e

Please sign in to comment.