Skip to content

Commit 7bc6222

Browse files
committed
Allow warnings in tryGetFolderBytes to be suppressed
To avoid confusing run annotations when dependency caching is enabled
1 parent b0c0aad commit 7bc6222

9 files changed

+25
-11
lines changed

lib/caching-utils.js

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/caching-utils.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/dependency-caching.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/dependency-caching.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/util.js

+6-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/util.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/caching-utils.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ import { isHostedRunner, tryGetFolderBytes } from "./util";
99
* Returns the total size of all the specified paths.
1010
* @param paths The paths for which to calculate the total size.
1111
* @param logger A logger to record some informational messages to.
12+
* @param quiet A value indicating whether to suppress logging warnings (default: false).
1213
* @returns The total size of all specified paths.
1314
*/
1415
export async function getTotalCacheSize(
1516
paths: string[],
1617
logger: Logger,
18+
quiet: boolean = false,
1719
): Promise<number> {
1820
const sizes = await Promise.all(
19-
paths.map((cacheDir) => tryGetFolderBytes(cacheDir, logger)),
21+
paths.map((cacheDir) => tryGetFolderBytes(cacheDir, logger, quiet)),
2022
);
2123
return sizes.map((a) => a || 0).reduce((a, b) => a + b, 0);
2224
}

src/dependency-caching.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export async function uploadDependencyCaches(config: Config, logger: Logger) {
168168
// use the cache quota that we compete with. In that case, we do not wish to use up all of the quota
169169
// with the dependency caches. For this, we could use the Cache API to check whether other workflows
170170
// are using the quota and how full it is.
171-
const size = await getTotalCacheSize(cacheConfig.paths, logger);
171+
const size = await getTotalCacheSize(cacheConfig.paths, logger, true);
172172

173173
// Skip uploading an empty cache.
174174
if (size === 0) {

src/util.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -785,16 +785,23 @@ export function listFolder(dir: string): string[] {
785785
*
786786
* @param cacheDir A directory to get the size of.
787787
* @param logger A logger to log any errors to.
788+
* @param quiet A value indicating whether to suppress warnings for errors (default: false).
789+
* Ignored if the log level is `debug`.
788790
* @returns The size in bytes of the folder, or undefined if errors occurred.
789791
*/
790792
export async function tryGetFolderBytes(
791793
cacheDir: string,
792794
logger: Logger,
795+
quiet: boolean = false,
793796
): Promise<number | undefined> {
794797
try {
795798
return await promisify<string, number>(getFolderSize)(cacheDir);
796799
} catch (e) {
797-
logger.warning(`Encountered an error while getting size of folder: ${e}`);
800+
if (!quiet || logger.isDebug()) {
801+
logger.warning(
802+
`Encountered an error while getting size of '${cacheDir}': ${e}`,
803+
);
804+
}
798805
return undefined;
799806
}
800807
}

0 commit comments

Comments
 (0)