From fe594a580dc60bfcdffeae81b4f8e8e68d745588 Mon Sep 17 00:00:00 2001 From: daz Date: Mon, 22 Jul 2024 11:35:12 -0600 Subject: [PATCH] Group cache-cleanup log messages for clarity --- sources/src/caching/cache-cleaner.ts | 27 ++++++++++++++++++++++----- sources/src/caching/caches.ts | 5 +++-- sources/src/daemon-controller.ts | 2 -- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/sources/src/caching/cache-cleaner.ts b/sources/src/caching/cache-cleaner.ts index 12e3be5..feb8708 100644 --- a/sources/src/caching/cache-cleaner.ts +++ b/sources/src/caching/cache-cleaner.ts @@ -1,7 +1,9 @@ import * as core from '@actions/core' +import * as exec from '@actions/exec' + import fs from 'fs' import path from 'path' -import {provisionAndMaybeExecute} from '../execution/gradle' +import * as provisioner from '../execution/provision' export class CacheCleaner { private readonly gradleUserHome: string @@ -24,9 +26,8 @@ export class CacheCleaner { await this.forceCleanupFilesOlderThan(cleanTimestamp) } + // Visible for testing async forceCleanupFilesOlderThan(cleanTimestamp: string): Promise { - core.info(`Cleaning up caches before ${cleanTimestamp}`) - // Run a dummy Gradle build to trigger cache cleanup const cleanupProjectDir = path.resolve(this.tmpDir, 'dummy-cleanup-project') fs.mkdirSync(cleanupProjectDir, {recursive: true}) @@ -54,7 +55,16 @@ export class CacheCleaner { ) 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 { + const args = [ '-g', this.gradleUserHome, '-I', @@ -65,6 +75,13 @@ export class CacheCleaner { '--build-cache', '-DGITHUB_DEPENDENCY_GRAPH_ENABLED=false', 'noop' - ]) + ] + + const result = await exec.getExecOutput(executable, args, { + cwd: cleanupProjectDir, + silent: true + }) + + core.info(result.stdout) } } diff --git a/sources/src/caching/caches.ts b/sources/src/caching/caches.ts index 6634f49..d3f4356 100644 --- a/sources/src/caching/caches.ts +++ b/sources/src/caching/caches.ts @@ -92,7 +92,9 @@ export async function save( return } - await daemonController.stopAllDaemons() + await core.group('Stopping Gradle daemons', async () => { + await daemonController.stopAllDaemons() + }) if (cacheConfig.isCacheCleanupEnabled()) { if (buildResults.anyConfigCacheHit()) { @@ -113,7 +115,6 @@ export async function save( } async function performCacheCleanup(gradleUserHome: string): Promise { - core.info('Forcing cache cleanup.') const cacheCleaner = new CacheCleaner(gradleUserHome, process.env['RUNNER_TEMP']!) try { await cacheCleaner.forceCleanup() diff --git a/sources/src/daemon-controller.ts b/sources/src/daemon-controller.ts index 4df3340..5bf5020 100644 --- a/sources/src/daemon-controller.ts +++ b/sources/src/daemon-controller.ts @@ -12,8 +12,6 @@ export class DaemonController { } async stopAllDaemons(): Promise { - core.info('Stopping all Gradle daemons before saving Gradle User Home state') - const executions: Promise[] = [] const args = ['--stop']