Unverified Commit aea6ddad authored by Daz DeBoer's avatar Daz DeBoer
Browse files

Attempt to stop all daemons on Job completion

parent a7f88017
Loading
Loading
Loading
Loading
+1 −2
Changes for src/job-summary.ts: 1 added line, 2 removed lines.
Original line number Diff line number Diff line
@@ -13,10 +13,9 @@ export interface BuildResult {
    get buildScanUri(): string
}

export function writeJobSummary(cacheListener: CacheListener): void {
export function writeJobSummary(buildResults: BuildResult[], cacheListener: CacheListener): void {
    core.info('Writing job summary')

    const buildResults = loadBuildResults()
    if (buildResults.length === 0) {
        core.debug('No Gradle build results found. Summary table will not be generated.')
    } else {
+35 −2
Changes for src/setup-gradle.ts: 35 added lines, 2 removed lines.
Original line number Diff line number Diff line
import * as core from '@actions/core'
import * as exec from '@actions/exec'
import * as fs from 'fs'
import * as path from 'path'
import * as os from 'os'
import * as caches from './caches'

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_USER_HOME = 'GRADLE_USER_HOME'
@@ -38,13 +41,18 @@ export async function complete(): Promise<void> {
        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')
    const cacheListener: CacheListener = CacheListener.rehydrate(core.getState(CACHE_LISTENER))

    const gradleUserHome = core.getState(GRADLE_USER_HOME)
    await caches.save(gradleUserHome, cacheListener)

    writeJobSummary(cacheListener)
    writeJobSummary(buildResults, cacheListener)
}

function determineGradleUserHome(rootDir: string): string {
@@ -55,3 +63,28 @@ function determineGradleUserHome(rootDir: string): string {

    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)
}