mirror of
https://github.com/gradle/actions
synced 2024-11-23 18:02:13 +00:00
Group cache-cleanup log messages for clarity
This commit is contained in:
parent
53f2a5657b
commit
fe594a580d
3 changed files with 25 additions and 9 deletions
|
@ -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<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})
|
||||
|
@ -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',
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<void> {
|
||||
core.info('Forcing cache cleanup.')
|
||||
const cacheCleaner = new CacheCleaner(gradleUserHome, process.env['RUNNER_TEMP']!)
|
||||
try {
|
||||
await cacheCleaner.forceCleanup()
|
||||
|
|
|
@ -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']
|
||||
|
||||
|
|
Loading…
Reference in a new issue