mirror of
https://github.com/gradle/gradle-build-action.git
synced 2024-11-23 01:22:50 +00:00
Attempt to stop all daemons on Job completion
This commit is contained in:
parent
a7f880172e
commit
aea6ddad5b
2 changed files with 36 additions and 4 deletions
|
@ -13,10 +13,9 @@ export interface BuildResult {
|
||||||
get buildScanUri(): string
|
get buildScanUri(): string
|
||||||
}
|
}
|
||||||
|
|
||||||
export function writeJobSummary(cacheListener: CacheListener): void {
|
export function writeJobSummary(buildResults: BuildResult[], cacheListener: CacheListener): void {
|
||||||
core.info('Writing job summary')
|
core.info('Writing job summary')
|
||||||
|
|
||||||
const buildResults = loadBuildResults()
|
|
||||||
if (buildResults.length === 0) {
|
if (buildResults.length === 0) {
|
||||||
core.debug('No Gradle build results found. Summary table will not be generated.')
|
core.debug('No Gradle build results found. Summary table will not be generated.')
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
|
import * as exec from '@actions/exec'
|
||||||
|
import * as fs from 'fs'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
import * as os from 'os'
|
import * as os from 'os'
|
||||||
import * as caches from './caches'
|
import * as caches from './caches'
|
||||||
|
|
||||||
import {CacheListener} from './cache-reporting'
|
import {CacheListener} from './cache-reporting'
|
||||||
import {writeJobSummary} from './job-summary'
|
import {BuildResult, loadBuildResults, writeJobSummary} from './job-summary'
|
||||||
|
|
||||||
const GRADLE_SETUP_VAR = 'GRADLE_BUILD_ACTION_SETUP_COMPLETED'
|
const GRADLE_SETUP_VAR = 'GRADLE_BUILD_ACTION_SETUP_COMPLETED'
|
||||||
const GRADLE_USER_HOME = 'GRADLE_USER_HOME'
|
const GRADLE_USER_HOME = 'GRADLE_USER_HOME'
|
||||||
|
@ -38,13 +41,18 @@ export async function complete(): Promise<void> {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const buildResults = loadBuildResults()
|
||||||
|
|
||||||
|
core.info('Stopping all Gradle daemons')
|
||||||
|
await stopAllDaemons(getUniqueGradleHomes(buildResults))
|
||||||
|
|
||||||
core.info('In final post-action step, saving state and writing summary')
|
core.info('In final post-action step, saving state and writing summary')
|
||||||
const cacheListener: CacheListener = CacheListener.rehydrate(core.getState(CACHE_LISTENER))
|
const cacheListener: CacheListener = CacheListener.rehydrate(core.getState(CACHE_LISTENER))
|
||||||
|
|
||||||
const gradleUserHome = core.getState(GRADLE_USER_HOME)
|
const gradleUserHome = core.getState(GRADLE_USER_HOME)
|
||||||
await caches.save(gradleUserHome, cacheListener)
|
await caches.save(gradleUserHome, cacheListener)
|
||||||
|
|
||||||
writeJobSummary(cacheListener)
|
writeJobSummary(buildResults, cacheListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
function determineGradleUserHome(rootDir: string): string {
|
function determineGradleUserHome(rootDir: string): string {
|
||||||
|
@ -55,3 +63,28 @@ function determineGradleUserHome(rootDir: string): string {
|
||||||
|
|
||||||
return path.resolve(os.homedir(), '.gradle')
|
return path.resolve(os.homedir(), '.gradle')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getUniqueGradleHomes(buildResults: BuildResult[]): string[] {
|
||||||
|
const gradleHomes = buildResults.map(buildResult => buildResult.gradleHomeDir)
|
||||||
|
return Array.from(new Set(gradleHomes))
|
||||||
|
}
|
||||||
|
|
||||||
|
async function stopAllDaemons(gradleHomes: string[]): Promise<void> {
|
||||||
|
const executions: Promise<number>[] = []
|
||||||
|
const args = ['--stop']
|
||||||
|
|
||||||
|
for (const gradleHome of gradleHomes) {
|
||||||
|
const executable = path.resolve(gradleHome, 'bin', 'gradle')
|
||||||
|
if (!fs.existsSync(executable)) {
|
||||||
|
core.warning(`Gradle executable not found at ${executable}. Could not stop Gradle daemons.`)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
core.info(`Stopping Gradle daemons in ${gradleHome}`)
|
||||||
|
executions.push(
|
||||||
|
exec.exec(executable, args, {
|
||||||
|
ignoreReturnCode: true
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
await Promise.all(executions)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue