Move bundle metadata files out of caches directory

Instead, use a separate '.gradle-build-action' directory for bundle
metadata files. This directory is always part of the cache-path.
This commit is contained in:
Daz DeBoer 2021-10-21 11:11:55 -06:00
parent 614d8770a4
commit 4cf255df10
No known key found for this signature in database
GPG Key ID: DD6B9F0B06683D5D

View File

@ -12,6 +12,8 @@ import {
tryDelete
} from './cache-utils'
const META_FILE_DIR = '.gradle-build-action'
export class GradleUserHomeCache extends AbstractCache {
private gradleUserHome: string
@ -65,11 +67,7 @@ export class GradleUserHomeCache extends AbstractCache {
}
private getBundleMetaFile(name: string): string {
return path.resolve(
this.gradleUserHome,
'caches',
`.gradle-build-action.${name}.cache`
)
return path.resolve(this.gradleUserHome, META_FILE_DIR, `${name}.cache`)
}
async beforeSave(): Promise<void> {
@ -142,9 +140,7 @@ export class GradleUserHomeCache extends AbstractCache {
} else {
core.info(`Caching ${bundle} with cache key: ${cacheKey}`)
await this.saveCache([artifactPath], cacheKey)
this.debug(`Writing cache metafile: ${bundleMetaFile}`)
fs.writeFileSync(bundleMetaFile, cacheKey)
this.writeBundleMetaFile(bundleMetaFile, cacheKey)
}
for (const file of bundleFiles) {
@ -166,6 +162,17 @@ export class GradleUserHomeCache extends AbstractCache {
return `${cacheKeyPrefix}${bundle}-${key}`
}
private writeBundleMetaFile(metaFile: string, cacheKey: string): void {
this.debug(`Writing bundle metafile: ${metaFile}`)
const dirName = path.dirname(metaFile)
if (!fs.existsSync(dirName)) {
fs.mkdirSync(dirName)
}
fs.writeFileSync(metaFile, cacheKey)
}
protected determineGradleUserHome(rootDir: string): string {
const customGradleUserHome = process.env['GRADLE_USER_HOME']
if (customGradleUserHome) {