Merge pull request #2597 from github/mbg/caching/output-improvements
Dependency caching: small output improvements
This commit is contained in:
commit
3ab67a2193
9 changed files with 59 additions and 15 deletions
|
|
@ -9,14 +9,16 @@ import { isHostedRunner, tryGetFolderBytes } from "./util";
|
|||
* Returns the total size of all the specified paths.
|
||||
* @param paths The paths for which to calculate the total size.
|
||||
* @param logger A logger to record some informational messages to.
|
||||
* @param quiet A value indicating whether to suppress logging warnings (default: false).
|
||||
* @returns The total size of all specified paths.
|
||||
*/
|
||||
export async function getTotalCacheSize(
|
||||
paths: string[],
|
||||
logger: Logger,
|
||||
quiet: boolean = false,
|
||||
): Promise<number> {
|
||||
const sizes = await Promise.all(
|
||||
paths.map((cacheDir) => tryGetFolderBytes(cacheDir, logger)),
|
||||
paths.map((cacheDir) => tryGetFolderBytes(cacheDir, logger, quiet)),
|
||||
);
|
||||
return sizes.map((a) => a || 0).reduce((a, b) => a + b, 0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@ export async function uploadDependencyCaches(config: Config, logger: Logger) {
|
|||
// use the cache quota that we compete with. In that case, we do not wish to use up all of the quota
|
||||
// with the dependency caches. For this, we could use the Cache API to check whether other workflows
|
||||
// are using the quota and how full it is.
|
||||
const size = await getTotalCacheSize(cacheConfig.paths, logger);
|
||||
const size = await getTotalCacheSize(cacheConfig.paths, logger, true);
|
||||
|
||||
// Skip uploading an empty cache.
|
||||
if (size === 0) {
|
||||
|
|
@ -181,10 +181,25 @@ export async function uploadDependencyCaches(config: Config, logger: Logger) {
|
|||
const key = await cacheKey(language, cacheConfig);
|
||||
|
||||
logger.info(
|
||||
`Uploading cache of size ${size} for ${language} with key ${key}`,
|
||||
`Uploading cache of size ${size} for ${language} with key ${key}...`,
|
||||
);
|
||||
|
||||
await actionsCache.saveCache(cacheConfig.paths, key);
|
||||
try {
|
||||
await actionsCache.saveCache(cacheConfig.paths, key);
|
||||
} catch (error) {
|
||||
// `ReserveCacheError` indicates that the cache key is already in use, which means that a
|
||||
// cache with that key already exists or is in the process of being uploaded by another
|
||||
// workflow. We can ignore this.
|
||||
if (error instanceof actionsCache.ReserveCacheError) {
|
||||
logger.info(
|
||||
`Not uploading cache for ${language}, because ${key} is already in use.`,
|
||||
);
|
||||
logger.debug(error.message);
|
||||
} else {
|
||||
// Propagate other errors upwards.
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -785,16 +785,23 @@ export function listFolder(dir: string): string[] {
|
|||
*
|
||||
* @param cacheDir A directory to get the size of.
|
||||
* @param logger A logger to log any errors to.
|
||||
* @param quiet A value indicating whether to suppress warnings for errors (default: false).
|
||||
* Ignored if the log level is `debug`.
|
||||
* @returns The size in bytes of the folder, or undefined if errors occurred.
|
||||
*/
|
||||
export async function tryGetFolderBytes(
|
||||
cacheDir: string,
|
||||
logger: Logger,
|
||||
quiet: boolean = false,
|
||||
): Promise<number | undefined> {
|
||||
try {
|
||||
return await promisify<string, number>(getFolderSize)(cacheDir);
|
||||
} catch (e) {
|
||||
logger.warning(`Encountered an error while getting size of folder: ${e}`);
|
||||
if (!quiet || logger.isDebug()) {
|
||||
logger.warning(
|
||||
`Encountered an error while getting size of '${cacheDir}': ${e}`,
|
||||
);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue