TRAP Caching: Skip uploading of small caches
This commit is contained in:
parent
a643eb3621
commit
b98b2def63
9 changed files with 88 additions and 35 deletions
33
lib/trap-caching.js
generated
33
lib/trap-caching.js
generated
|
|
@ -18,19 +18,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getTotalCacheSize = exports.getLanguagesSupportingCaching = exports.uploadTrapCaches = exports.downloadTrapCaches = exports.getTrapCachingExtractorConfigArgsForLang = exports.getTrapCachingExtractorConfigArgs = void 0;
|
||||
const fs = __importStar(require("fs"));
|
||||
const path = __importStar(require("path"));
|
||||
const util_1 = require("util");
|
||||
const cache = __importStar(require("@actions/cache"));
|
||||
const get_folder_size_1 = __importDefault(require("get-folder-size"));
|
||||
const actionsUtil = __importStar(require("./actions-util"));
|
||||
const codeql_1 = require("./codeql");
|
||||
const util_2 = require("./util");
|
||||
const util_1 = require("./util");
|
||||
// This constant should be bumped if we make a breaking change
|
||||
// to how the CodeQL Action stores or retrieves the TRAP cache,
|
||||
// and will invalidate previous caches. We don't need to bump
|
||||
|
|
@ -39,6 +34,9 @@ const util_2 = require("./util");
|
|||
const CACHE_VERSION = 1;
|
||||
// This constant sets the size of each TRAP cache in megabytes.
|
||||
const CACHE_SIZE_MB = 1024;
|
||||
// This constant sets the minimum size in megabytes of a TRAP
|
||||
// cache for us to consider it worth uploading.
|
||||
const MINIMUM_CACHE_MB_TO_UPLOAD = 10;
|
||||
async function getTrapCachingExtractorConfigArgs(config) {
|
||||
const result = [];
|
||||
for (const language of config.languages)
|
||||
|
|
@ -126,6 +124,15 @@ async function uploadTrapCaches(codeql, config, logger) {
|
|||
const cacheDir = config.trapCaches[language];
|
||||
if (cacheDir === undefined)
|
||||
continue;
|
||||
const trapFolderSize = await (0, util_1.tryGetFolderBytes)(cacheDir, logger);
|
||||
if (trapFolderSize === undefined) {
|
||||
logger.info(`Skipping upload of TRAP cache for ${language} as we couldn't determine its size`);
|
||||
continue;
|
||||
}
|
||||
if (trapFolderSize < MINIMUM_CACHE_MB_TO_UPLOAD * 1048576) {
|
||||
logger.info(`Skipping upload of TRAP cache for ${language} as it is too small`);
|
||||
continue;
|
||||
}
|
||||
const key = await cacheKey(codeql, language, process.env.GITHUB_SHA || "unknown");
|
||||
logger.info(`Uploading TRAP cache to Actions cache with key ${key}`);
|
||||
toAwait.push(cache.saveCache([cacheDir], key));
|
||||
|
|
@ -137,7 +144,7 @@ exports.uploadTrapCaches = uploadTrapCaches;
|
|||
async function getLanguagesSupportingCaching(codeql, languages, logger) {
|
||||
var _a, _b, _c, _d;
|
||||
const result = [];
|
||||
if (!(await (0, util_2.codeQlVersionAbove)(codeql, codeql_1.CODEQL_VERSION_BETTER_RESOLVE_LANGUAGES)))
|
||||
if (!(await (0, util_1.codeQlVersionAbove)(codeql, codeql_1.CODEQL_VERSION_BETTER_RESOLVE_LANGUAGES)))
|
||||
return result;
|
||||
const resolveResult = await codeql.betterResolveLanguages();
|
||||
outer: for (const lang of languages) {
|
||||
|
|
@ -168,16 +175,8 @@ async function getLanguagesSupportingCaching(codeql, languages, logger) {
|
|||
}
|
||||
exports.getLanguagesSupportingCaching = getLanguagesSupportingCaching;
|
||||
async function getTotalCacheSize(trapCaches, logger) {
|
||||
try {
|
||||
const sizes = await Promise.all(Object.values(trapCaches).map(async (cacheDir) => {
|
||||
return (0, util_1.promisify)(get_folder_size_1.default)(cacheDir);
|
||||
}));
|
||||
return sizes.reduce((a, b) => a + b, 0);
|
||||
}
|
||||
catch (e) {
|
||||
logger.warning(`Encountered an error while getting TRAP cache size: ${e}`);
|
||||
return 0;
|
||||
}
|
||||
const sizes = await Promise.all(Object.values(trapCaches).map((cacheDir) => (0, util_1.tryGetFolderBytes)(cacheDir, logger)));
|
||||
return sizes.map((a) => a || 0).reduce((a, b) => a + b, 0);
|
||||
}
|
||||
exports.getTotalCacheSize = getTotalCacheSize;
|
||||
async function cacheKey(codeql, language, baseSha) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue