Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Group cache-cleanup log messages #319

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions sources/src/caching/cache-cleaner.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -24,9 +26,8 @@ export class CacheCleaner {
await this.forceCleanupFilesOlderThan(cleanTimestamp)
}

// Visible for testing
async forceCleanupFilesOlderThan(cleanTimestamp: string): Promise<void> {
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})
Expand Down Expand Up @@ -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<void> {
const args = [
'-g',
this.gradleUserHome,
'-I',
Expand All @@ -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)
}
}
5 changes: 3 additions & 2 deletions sources/src/caching/caches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -113,7 +115,6 @@ export async function save(
}

async function performCacheCleanup(gradleUserHome: string): Promise<void> {
core.info('Forcing cache cleanup.')
const cacheCleaner = new CacheCleaner(gradleUserHome, process.env['RUNNER_TEMP']!)
try {
await cacheCleaner.forceCleanup()
Expand Down
2 changes: 0 additions & 2 deletions sources/src/daemon-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ export class DaemonController {
}

async stopAllDaemons(): Promise<void> {
core.info('Stopping all Gradle daemons before saving Gradle User Home state')

const executions: Promise<number>[] = []
const args = ['--stop']

Expand Down
Loading