Group cache-cleanup log messages for clarity

This commit is contained in:
daz 2024-07-22 11:35:12 -06:00 committed by Daz DeBoer
parent 53f2a5657b
commit fe594a580d
3 changed files with 25 additions and 9 deletions

View file

@ -1,7 +1,9 @@
import * as core from '@actions/core' import * as core from '@actions/core'
import * as exec from '@actions/exec'
import fs from 'fs' import fs from 'fs'
import path from 'path' import path from 'path'
import {provisionAndMaybeExecute} from '../execution/gradle' import * as provisioner from '../execution/provision'
export class CacheCleaner { export class CacheCleaner {
private readonly gradleUserHome: string private readonly gradleUserHome: string
@ -24,9 +26,8 @@ export class CacheCleaner {
await this.forceCleanupFilesOlderThan(cleanTimestamp) await this.forceCleanupFilesOlderThan(cleanTimestamp)
} }
// Visible for testing
async forceCleanupFilesOlderThan(cleanTimestamp: string): Promise<void> { async forceCleanupFilesOlderThan(cleanTimestamp: string): Promise<void> {
core.info(`Cleaning up caches before ${cleanTimestamp}`)
// Run a dummy Gradle build to trigger cache cleanup // Run a dummy Gradle build to trigger cache cleanup
const cleanupProjectDir = path.resolve(this.tmpDir, 'dummy-cleanup-project') const cleanupProjectDir = path.resolve(this.tmpDir, 'dummy-cleanup-project')
fs.mkdirSync(cleanupProjectDir, {recursive: true}) fs.mkdirSync(cleanupProjectDir, {recursive: true})
@ -54,7 +55,16 @@ export class CacheCleaner {
) )
fs.writeFileSync(path.resolve(cleanupProjectDir, 'build.gradle'), 'task("noop") {}') fs.writeFileSync(path.resolve(cleanupProjectDir, 'build.gradle'), 'task("noop") {}')
await provisionAndMaybeExecute('current', cleanupProjectDir, [ const executable = await provisioner.provisionGradle('current')
await core.group('Executing Gradle to clean up caches', async () => {
core.info(`Cleaning up caches last used before ${cleanTimestamp}`)
await this.executeCleanupBuild(executable!, cleanupProjectDir)
})
}
private async executeCleanupBuild(executable: string, cleanupProjectDir: string): Promise<void> {
const args = [
'-g', '-g',
this.gradleUserHome, this.gradleUserHome,
'-I', '-I',
@ -65,6 +75,13 @@ export class CacheCleaner {
'--build-cache', '--build-cache',
'-DGITHUB_DEPENDENCY_GRAPH_ENABLED=false', '-DGITHUB_DEPENDENCY_GRAPH_ENABLED=false',
'noop' 'noop'
]) ]
const result = await exec.getExecOutput(executable, args, {
cwd: cleanupProjectDir,
silent: true
})
core.info(result.stdout)
} }
} }

View file

@ -92,7 +92,9 @@ export async function save(
return return
} }
await daemonController.stopAllDaemons() await core.group('Stopping Gradle daemons', async () => {
await daemonController.stopAllDaemons()
})
if (cacheConfig.isCacheCleanupEnabled()) { if (cacheConfig.isCacheCleanupEnabled()) {
if (buildResults.anyConfigCacheHit()) { if (buildResults.anyConfigCacheHit()) {
@ -113,7 +115,6 @@ export async function save(
} }
async function performCacheCleanup(gradleUserHome: string): Promise<void> { async function performCacheCleanup(gradleUserHome: string): Promise<void> {
core.info('Forcing cache cleanup.')
const cacheCleaner = new CacheCleaner(gradleUserHome, process.env['RUNNER_TEMP']!) const cacheCleaner = new CacheCleaner(gradleUserHome, process.env['RUNNER_TEMP']!)
try { try {
await cacheCleaner.forceCleanup() await cacheCleaner.forceCleanup()

View file

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