mirror of
https://github.com/gradle/gradle-build-action.git
synced 2024-12-25 14:06:18 +08:00
Restore/cache deduplicated files in parallel
This commit is contained in:
parent
4b92b8d013
commit
5a90152b1f
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,36 +42,34 @@ 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 targetFile = markerFile.substring(
|
const p = this.restoreDeduplicatePath(markerFile)
|
||||||
0,
|
processes.push(p)
|
||||||
markerFile.length - MARKER_FILE_EXTENSION.length
|
}
|
||||||
)
|
await Promise.all(processes)
|
||||||
core.info(
|
}
|
||||||
`Found marker file: ${markerFile}. Looking for ${targetFile}`
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!fs.existsSync(targetFile)) {
|
private async restoreDeduplicatePath(markerFile: string): Promise<void> {
|
||||||
const key = path.relative(this.getGradleUserHome(), targetFile)
|
const targetFile = markerFile.substring(
|
||||||
const cacheKey = `gradle-dedup-${key}`
|
0,
|
||||||
core.info(`Cache key: ${cacheKey}. Cache path: ${targetFile}`)
|
markerFile.length - MARKER_FILE_EXTENSION.length
|
||||||
|
)
|
||||||
|
core.info(`Found marker file: ${markerFile}. Looking for ${targetFile}`)
|
||||||
|
|
||||||
const restoreKey = await cache.restoreCache(
|
if (!fs.existsSync(targetFile)) {
|
||||||
[targetFile],
|
const key = path.relative(this.getGradleUserHome(), targetFile)
|
||||||
cacheKey
|
const cacheKey = `gradle-dedup-${key}`
|
||||||
)
|
core.info(`Cache key: ${cacheKey}. Cache path: ${targetFile}`)
|
||||||
if (restoreKey) {
|
|
||||||
core.info(
|
const restoreKey = await cache.restoreCache([targetFile], cacheKey)
|
||||||
`Restored ${cacheKey} from cache to ${targetFile}`
|
if (restoreKey) {
|
||||||
)
|
core.info(`Restored ${cacheKey} from cache to ${targetFile}`)
|
||||||
} else {
|
|
||||||
core.info(
|
|
||||||
`Did NOT restore from ${cacheKey} to ${targetFile}`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
core.info(`Target file already exists: ${targetFile}`)
|
core.info(`Did NOT restore from ${cacheKey} to ${targetFile}`)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
core.info(`Target file already exists: ${targetFile}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,40 +97,47 @@ 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) {
|
||||||
core.info(`Deduplicate caching: ${targetFile}`)
|
const p = this.cacheDeplucatePath(targetFile)
|
||||||
|
processes.push(p)
|
||||||
|
}
|
||||||
|
await Promise.all(processes)
|
||||||
|
}
|
||||||
|
|
||||||
const markerFile = `${targetFile}${MARKER_FILE_EXTENSION}`
|
private async cacheDeplucatePath(targetFile: string): Promise<void> {
|
||||||
|
core.info(`Deduplicate caching: ${targetFile}`)
|
||||||
|
|
||||||
if (!fs.existsSync(markerFile)) {
|
const markerFile = `${targetFile}${MARKER_FILE_EXTENSION}`
|
||||||
const key = path.relative(this.getGradleUserHome(), targetFile)
|
|
||||||
const cacheKey = `gradle-dedup-${key}`
|
|
||||||
core.info(`Cache key: ${cacheKey}. Cache path: ${targetFile}`)
|
|
||||||
|
|
||||||
try {
|
if (!fs.existsSync(markerFile)) {
|
||||||
await cache.saveCache([targetFile], cacheKey)
|
const key = path.relative(this.getGradleUserHome(), targetFile)
|
||||||
} catch (error) {
|
const cacheKey = `gradle-dedup-${key}`
|
||||||
// Fail on validation errors or non-errors (the latter to keep Typescript happy)
|
core.info(`Cache key: ${cacheKey}. Cache path: ${targetFile}`)
|
||||||
if (
|
|
||||||
error instanceof cache.ValidationError ||
|
try {
|
||||||
!(error instanceof Error)
|
await cache.saveCache([targetFile], cacheKey)
|
||||||
) {
|
} catch (error) {
|
||||||
throw error
|
// Fail on validation errors or non-errors (the latter to keep Typescript happy)
|
||||||
}
|
if (
|
||||||
// TODO : Avoid warning for reserve cache error: this is expected
|
error instanceof cache.ValidationError ||
|
||||||
core.warning(error.message)
|
!(error instanceof Error)
|
||||||
|
) {
|
||||||
|
throw error
|
||||||
}
|
}
|
||||||
|
// TODO : Avoid warning for reserve cache error: this is expected
|
||||||
// Write the marker file and delete the original
|
core.warning(error.message)
|
||||||
fs.writeFileSync(markerFile, 'dummy')
|
|
||||||
} else {
|
|
||||||
core.info(`Marker file already exists: ${markerFile}`)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO : Should not need to delete. Just exclude from cache path.
|
// Write the marker file and delete the original
|
||||||
// Delete the target file
|
fs.writeFileSync(markerFile, 'dummy')
|
||||||
fs.unlinkSync(targetFile)
|
} else {
|
||||||
|
core.info(`Marker file already exists: ${markerFile}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO : Should not need to delete. Just exclude from cache path.
|
||||||
|
// Delete the target file
|
||||||
|
fs.unlinkSync(targetFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected cacheOutputExists(): boolean {
|
protected cacheOutputExists(): boolean {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user