diff --git a/src/cache-gradle-user-home.ts b/src/cache-gradle-user-home.ts index 3ebbf4e..cd7d931 100644 --- a/src/cache-gradle-user-home.ts +++ b/src/cache-gradle-user-home.ts @@ -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 { @@ -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) {