diff --git a/dist/index/index.js b/dist/index/index.js index 6975ba7..70bcd2d 100644 --- a/dist/index/index.js +++ b/dist/index/index.js @@ -27157,8 +27157,8 @@ async function getCacheUtil(cachePath) { } async function ensureCacheMetadata(cachePath) { const namespaceFolderPath = external_path_.join(cachePath, privateNamespaceDir); - const metadataFilePath = external_path_.join(namespaceFolderPath, metadataFileName); external_fs_.mkdirSync(namespaceFolderPath, { recursive: true }); + const metadataFilePath = external_path_.join(namespaceFolderPath, metadataFileName); if (!external_fs_.existsSync(metadataFilePath)) { return {}; } @@ -27168,6 +27168,7 @@ async function ensureCacheMetadata(cachePath) { } async function writeCacheMetadata(cachePath, metadata) { const namespaceFolderPath = external_path_.join(cachePath, privateNamespaceDir); + external_fs_.mkdirSync(namespaceFolderPath, { recursive: true }); const metadataFilePath = external_path_.join(namespaceFolderPath, metadataFileName); const rawData = JSON.stringify(metadata); external_fs_.writeFileSync(metadataFilePath, rawData); @@ -27207,21 +27208,27 @@ async function main() { else { core.info("All cache paths found and restored."); } - // Write/update cache volume metadata file - const metadata = await ensureCacheMetadata(localCachePath); - metadata.updatedAt = new Date().toISOString(); - metadata.version = 1; - if (!metadata.userRequest) { - metadata.userRequest = {}; + try { + // Write/update cache volume metadata file + const metadata = await ensureCacheMetadata(localCachePath); + metadata.updatedAt = new Date().toISOString(); + metadata.version = 1; + if (!metadata.userRequest) { + metadata.userRequest = {}; + } + for (const p of cachePaths) { + metadata.userRequest[p.pathInCache] = { + cacheFramework: p.framework, + mountTarget: [p.mountTarget], + source: ActionVersion, + }; + } + writeCacheMetadata(localCachePath, metadata); } - for (const p of cachePaths) { - metadata.userRequest[p.pathInCache] = { - cacheFramework: p.framework, - mountTarget: [p.mountTarget], - source: ActionVersion, - }; + catch (e) { + core.warning("Failed to record cache metadata."); + core.info(e.message); } - writeCacheMetadata(localCachePath, metadata); // Save the list of cache paths to actions state for the post-cache action core.saveState(StatePathsKey, cachePaths); const cacheUtilInfo = await getCacheSummaryUtil(localCachePath); diff --git a/src/index.ts b/src/index.ts index 737b2cc..9c71255 100644 --- a/src/index.ts +++ b/src/index.ts @@ -40,22 +40,28 @@ async function main() { core.info("All cache paths found and restored."); } - // Write/update cache volume metadata file - const metadata = await utils.ensureCacheMetadata(localCachePath); - metadata.updatedAt = new Date().toISOString(); - metadata.version = 1; - if (!metadata.userRequest) { - metadata.userRequest = {}; - } + try { + // Write/update cache volume metadata file + const metadata = await utils.ensureCacheMetadata(localCachePath); + metadata.updatedAt = new Date().toISOString(); + metadata.version = 1; + if (!metadata.userRequest) { + metadata.userRequest = {}; + } - for (const p of cachePaths) { - metadata.userRequest[p.pathInCache] = { - cacheFramework: p.framework, - mountTarget: [p.mountTarget], - source: ActionVersion, - }; + for (const p of cachePaths) { + metadata.userRequest[p.pathInCache] = { + cacheFramework: p.framework, + mountTarget: [p.mountTarget], + source: ActionVersion, + }; + } + utils.writeCacheMetadata(localCachePath, metadata); + } catch (e) { + core.warning("Failed to record cache metadata."); + core.info(e.message); } - utils.writeCacheMetadata(localCachePath, metadata); + // Save the list of cache paths to actions state for the post-cache action core.saveState(utils.StatePathsKey, cachePaths); diff --git a/src/utils.ts b/src/utils.ts index 0375696..b869376 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -53,8 +53,9 @@ export async function ensureCacheMetadata( cachePath: string ): Promise { const namespaceFolderPath = path.join(cachePath, privateNamespaceDir); - const metadataFilePath = path.join(namespaceFolderPath, metadataFileName); fs.mkdirSync(namespaceFolderPath, { recursive: true }); + + const metadataFilePath = path.join(namespaceFolderPath, metadataFileName); if (!fs.existsSync(metadataFilePath)) { return {}; } @@ -69,6 +70,8 @@ export async function writeCacheMetadata( metadata: CacheMetadata ) { const namespaceFolderPath = path.join(cachePath, privateNamespaceDir); + fs.mkdirSync(namespaceFolderPath, { recursive: true }); + const metadataFilePath = path.join(namespaceFolderPath, metadataFileName); const rawData = JSON.stringify(metadata); fs.writeFileSync(metadataFilePath, rawData);