mirror of
https://github.com/gradle/gradle-build-action.git
synced 2024-11-22 17:12:51 +00:00
Merge pull request #92 from gradle/dd/cache-debug-logging
Improve cache logging and behaviour
This commit is contained in:
commit
4bc52c85c3
6 changed files with 67 additions and 42 deletions
2
dist/main/index.js
vendored
2
dist/main/index.js
vendored
File diff suppressed because one or more lines are too long
2
dist/main/index.js.map
vendored
2
dist/main/index.js.map
vendored
File diff suppressed because one or more lines are too long
2
dist/post/index.js
vendored
2
dist/post/index.js
vendored
File diff suppressed because one or more lines are too long
2
dist/post/index.js.map
vendored
2
dist/post/index.js.map
vendored
File diff suppressed because one or more lines are too long
|
@ -26,9 +26,9 @@ export class GradleUserHomeCache extends AbstractCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
async afterRestore(): Promise<void> {
|
async afterRestore(): Promise<void> {
|
||||||
await this.reportCacheEntrySize('as restored from cache')
|
await this.reportGradleUserHomeSize('as restored from cache')
|
||||||
await this.restoreCommonArtifacts()
|
await this.restoreCommonArtifacts()
|
||||||
await this.reportCacheEntrySize('after restoring common artifacts')
|
await this.reportGradleUserHomeSize('after restoring common artifacts')
|
||||||
}
|
}
|
||||||
|
|
||||||
private async restoreCommonArtifacts(): Promise<void> {
|
private async restoreCommonArtifacts(): Promise<void> {
|
||||||
|
@ -59,7 +59,7 @@ export class GradleUserHomeCache extends AbstractCache {
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
this.debug(
|
this.debug(
|
||||||
`Failed to restore ${bundle} with key ${cacheKey} to ${artifactPath}`
|
`Did not restore ${bundle} with key ${cacheKey} to ${artifactPath}`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -77,41 +77,10 @@ export class GradleUserHomeCache extends AbstractCache {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private async reportCacheEntrySize(label: string): Promise<void> {
|
|
||||||
if (!this.cacheDebuggingEnabled) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (!fs.existsSync(this.gradleUserHome)) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const result = await exec.getExecOutput(
|
|
||||||
'du',
|
|
||||||
['-h', '-c', '-t', '5M'],
|
|
||||||
{
|
|
||||||
cwd: this.gradleUserHome,
|
|
||||||
silent: true,
|
|
||||||
ignoreReturnCode: true
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
core.info(`Gradle User Home cache entry (directories >5M): ${label}`)
|
|
||||||
|
|
||||||
core.info(
|
|
||||||
result.stdout
|
|
||||||
.trimEnd()
|
|
||||||
.replace(/\t/g, ' ')
|
|
||||||
.split('\n')
|
|
||||||
.map(it => {
|
|
||||||
return ` ${it}`
|
|
||||||
})
|
|
||||||
.join('\n')
|
|
||||||
)
|
|
||||||
|
|
||||||
core.info('-----------------------')
|
|
||||||
}
|
|
||||||
|
|
||||||
async beforeSave(): Promise<void> {
|
async beforeSave(): Promise<void> {
|
||||||
|
await this.reportGradleUserHomeSize('before saving common artifacts')
|
||||||
await this.saveCommonArtifacts()
|
await this.saveCommonArtifacts()
|
||||||
|
await this.reportGradleUserHomeSize('after saving common artifacts')
|
||||||
}
|
}
|
||||||
|
|
||||||
private async saveCommonArtifacts(): Promise<void> {
|
private async saveCommonArtifacts(): Promise<void> {
|
||||||
|
@ -175,6 +144,10 @@ export class GradleUserHomeCache extends AbstractCache {
|
||||||
)
|
)
|
||||||
const key = hashFileNames(relativeFiles)
|
const key = hashFileNames(relativeFiles)
|
||||||
|
|
||||||
|
this.debug(
|
||||||
|
`Generating cache key for ${bundle} from files: ${relativeFiles}`
|
||||||
|
)
|
||||||
|
|
||||||
return `${cacheKeyPrefix}${bundle}-${key}`
|
return `${cacheKeyPrefix}${bundle}-${key}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,4 +178,37 @@ export class GradleUserHomeCache extends AbstractCache {
|
||||||
])
|
])
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async reportGradleUserHomeSize(label: string): Promise<void> {
|
||||||
|
if (!this.cacheDebuggingEnabled) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!fs.existsSync(this.gradleUserHome)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const result = await exec.getExecOutput(
|
||||||
|
'du',
|
||||||
|
['-h', '-c', '-t', '5M'],
|
||||||
|
{
|
||||||
|
cwd: this.gradleUserHome,
|
||||||
|
silent: true,
|
||||||
|
ignoreReturnCode: true
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
core.info(`Gradle User Home cache entry (directories >5M): ${label}`)
|
||||||
|
|
||||||
|
core.info(
|
||||||
|
result.stdout
|
||||||
|
.trimEnd()
|
||||||
|
.replace(/\t/g, ' ')
|
||||||
|
.split('\n')
|
||||||
|
.map(it => {
|
||||||
|
return ` ${it}`
|
||||||
|
})
|
||||||
|
.join('\n')
|
||||||
|
)
|
||||||
|
|
||||||
|
core.info('-----------------------')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,6 +122,12 @@ export abstract class AbstractCache {
|
||||||
|
|
||||||
core.saveState(this.cacheKeyStateKey, cacheKey.key)
|
core.saveState(this.cacheKeyStateKey, cacheKey.key)
|
||||||
|
|
||||||
|
this.debug(
|
||||||
|
`Requesting ${this.cacheDescription} with
|
||||||
|
key:${cacheKey.key}
|
||||||
|
restoreKeys:[${cacheKey.restoreKeys}]`
|
||||||
|
)
|
||||||
|
|
||||||
const cacheResult = await this.restoreCache(
|
const cacheResult = await this.restoreCache(
|
||||||
this.getCachePath(),
|
this.getCachePath(),
|
||||||
cacheKey.key,
|
cacheKey.key,
|
||||||
|
@ -141,7 +147,13 @@ export abstract class AbstractCache {
|
||||||
`Restored ${this.cacheDescription} from cache key: ${cacheResult}`
|
`Restored ${this.cacheDescription} from cache key: ${cacheResult}`
|
||||||
)
|
)
|
||||||
|
|
||||||
|
try {
|
||||||
await this.afterRestore()
|
await this.afterRestore()
|
||||||
|
} catch (error) {
|
||||||
|
core.warning(
|
||||||
|
`Restore ${this.cacheDescription} failed in 'afterRestore': ${error}`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -193,7 +205,14 @@ export abstract class AbstractCache {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
await this.beforeSave()
|
await this.beforeSave()
|
||||||
|
} catch (error) {
|
||||||
|
core.warning(
|
||||||
|
`Save ${this.cacheDescription} failed in 'beforeSave': ${error}`
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
core.info(
|
core.info(
|
||||||
`Caching ${this.cacheDescription} with cache key: ${cacheKey}`
|
`Caching ${this.cacheDescription} with cache key: ${cacheKey}`
|
||||||
|
|
Loading…
Reference in a new issue