mirror of
https://github.com/gradle/gradle-build-action.git
synced 2024-11-22 17:12:51 +00:00
Restore/cache deduplicated files in parallel
This commit is contained in:
parent
4b92b8d013
commit
5a90152b1f
3 changed files with 58 additions and 53 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/post/index.js
vendored
2
dist/post/index.js
vendored
File diff suppressed because one or more lines are too long
|
@ -42,38 +42,36 @@ export class GradleUserHomeCache extends AbstractCache {
|
||||||
const globber = await glob.create(markerFilePatterns)
|
const globber = await glob.create(markerFilePatterns)
|
||||||
const markerFiles = await globber.glob()
|
const markerFiles = await globber.glob()
|
||||||
|
|
||||||
|
const processes: Promise<void>[] = []
|
||||||
for (const markerFile of markerFiles) {
|
for (const markerFile of markerFiles) {
|
||||||
|
const p = this.restoreDeduplicatePath(markerFile)
|
||||||
|
processes.push(p)
|
||||||
|
}
|
||||||
|
await Promise.all(processes)
|
||||||
|
}
|
||||||
|
|
||||||
|
private async restoreDeduplicatePath(markerFile: string): Promise<void> {
|
||||||
const targetFile = markerFile.substring(
|
const targetFile = markerFile.substring(
|
||||||
0,
|
0,
|
||||||
markerFile.length - MARKER_FILE_EXTENSION.length
|
markerFile.length - MARKER_FILE_EXTENSION.length
|
||||||
)
|
)
|
||||||
core.info(
|
core.info(`Found marker file: ${markerFile}. Looking for ${targetFile}`)
|
||||||
`Found marker file: ${markerFile}. Looking for ${targetFile}`
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!fs.existsSync(targetFile)) {
|
if (!fs.existsSync(targetFile)) {
|
||||||
const key = path.relative(this.getGradleUserHome(), targetFile)
|
const key = path.relative(this.getGradleUserHome(), targetFile)
|
||||||
const cacheKey = `gradle-dedup-${key}`
|
const cacheKey = `gradle-dedup-${key}`
|
||||||
core.info(`Cache key: ${cacheKey}. Cache path: ${targetFile}`)
|
core.info(`Cache key: ${cacheKey}. Cache path: ${targetFile}`)
|
||||||
|
|
||||||
const restoreKey = await cache.restoreCache(
|
const restoreKey = await cache.restoreCache([targetFile], cacheKey)
|
||||||
[targetFile],
|
|
||||||
cacheKey
|
|
||||||
)
|
|
||||||
if (restoreKey) {
|
if (restoreKey) {
|
||||||
core.info(
|
core.info(`Restored ${cacheKey} from cache to ${targetFile}`)
|
||||||
`Restored ${cacheKey} from cache to ${targetFile}`
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
core.info(
|
core.info(`Did NOT restore from ${cacheKey} to ${targetFile}`)
|
||||||
`Did NOT restore from ${cacheKey} to ${targetFile}`
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
core.info(`Target file already exists: ${targetFile}`)
|
core.info(`Target file already exists: ${targetFile}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private async reportCacheEntrySize(): Promise<void> {
|
private async reportCacheEntrySize(): Promise<void> {
|
||||||
const gradleUserHome = path.resolve(os.homedir(), '.gradle')
|
const gradleUserHome = path.resolve(os.homedir(), '.gradle')
|
||||||
|
@ -99,7 +97,15 @@ export class GradleUserHomeCache extends AbstractCache {
|
||||||
const globber = await glob.create(targetFilePatterns)
|
const globber = await glob.create(targetFilePatterns)
|
||||||
const targetFiles = await globber.glob()
|
const targetFiles = await globber.glob()
|
||||||
|
|
||||||
|
const processes: Promise<void>[] = []
|
||||||
for (const targetFile of targetFiles) {
|
for (const targetFile of targetFiles) {
|
||||||
|
const p = this.cacheDeplucatePath(targetFile)
|
||||||
|
processes.push(p)
|
||||||
|
}
|
||||||
|
await Promise.all(processes)
|
||||||
|
}
|
||||||
|
|
||||||
|
private async cacheDeplucatePath(targetFile: string): Promise<void> {
|
||||||
core.info(`Deduplicate caching: ${targetFile}`)
|
core.info(`Deduplicate caching: ${targetFile}`)
|
||||||
|
|
||||||
const markerFile = `${targetFile}${MARKER_FILE_EXTENSION}`
|
const markerFile = `${targetFile}${MARKER_FILE_EXTENSION}`
|
||||||
|
@ -133,7 +139,6 @@ export class GradleUserHomeCache extends AbstractCache {
|
||||||
// Delete the target file
|
// Delete the target file
|
||||||
fs.unlinkSync(targetFile)
|
fs.unlinkSync(targetFile)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected cacheOutputExists(): boolean {
|
protected cacheOutputExists(): boolean {
|
||||||
// Need to check for 'caches' directory to avoid incorrect detection on MacOS agents
|
// Need to check for 'caches' directory to avoid incorrect detection on MacOS agents
|
||||||
|
|
Loading…
Reference in a new issue