TRAP Caching: Skip uploading of small caches

This commit is contained in:
Edoardo Pirovano
2022-09-23 11:51:06 +01:00
parent a643eb3621
commit b98b2def63
9 changed files with 88 additions and 35 deletions

View File

@@ -2,9 +2,11 @@ import * as fs from "fs";
import * as os from "os";
import * as path from "path";
import { Readable } from "stream";
import { promisify } from "util";
import * as core from "@actions/core";
import del from "del";
import getFolderSize from "get-folder-size";
import * as semver from "semver";
import * as api from "./api-client";
@@ -836,3 +838,23 @@ export async function isGoExtractionReconciliationEnabled(
))
);
}
/**
* Get the size a folder in bytes. This will log any filesystem errors
* as a warning and then return undefined.
*
* @param cacheDir A directory to get the size of.
* @param logger A logger to log any errors to.
* @returns The size in bytes of the folder, or undefined if errors occurred.
*/
export async function tryGetFolderBytes(
cacheDir: string,
logger: Logger
): Promise<number | undefined> {
try {
return await promisify<string, number>(getFolderSize)(cacheDir);
} catch (e) {
logger.warning(`Encountered an error while getting size of folder: ${e}`);
return undefined;
}
}