Skip to content

Commit

Permalink
Make metadata reporting best-effort.
Browse files Browse the repository at this point in the history
  • Loading branch information
n-g committed Feb 1, 2024
1 parent df44d59 commit 4a4b8dd
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 29 deletions.
35 changes: 21 additions & 14 deletions dist/index/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
}
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
34 changes: 20 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 4 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ export async function ensureCacheMetadata(
cachePath: string
): Promise<CacheMetadata> {
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 {};
}
Expand All @@ -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);
Expand Down

0 comments on commit 4a4b8dd

Please sign in to comment.