Add telemetry for TRAP caching
This commit is contained in:
parent
ca10a6d552
commit
4139682b64
63 changed files with 1195 additions and 126 deletions
30
lib/trap-caching.js
generated
30
lib/trap-caching.js
generated
|
|
@ -18,11 +18,15 @@ 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.getLanguagesSupportingCaching = exports.uploadTrapCaches = exports.downloadTrapCaches = exports.getTrapCachingExtractorConfigArgsForLang = exports.getTrapCachingExtractorConfigArgs = void 0;
|
||||
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 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_1 = require("./util");
|
||||
|
|
@ -106,9 +110,16 @@ async function downloadTrapCaches(codeql, languages, logger) {
|
|||
return result;
|
||||
}
|
||||
exports.downloadTrapCaches = downloadTrapCaches;
|
||||
/**
|
||||
* Possibly upload TRAP caches to the Actions cache.
|
||||
* @param codeql The CodeQL instance to use.
|
||||
* @param config The configuration for this workflow.
|
||||
* @param logger A logger to record some informational messages to.
|
||||
* @returns Whether the TRAP caches were uploaded.
|
||||
*/
|
||||
async function uploadTrapCaches(codeql, config, logger) {
|
||||
if (!(await actionsUtil.isAnalyzingDefaultBranch()))
|
||||
return; // Only upload caches from the default branch
|
||||
return false; // Only upload caches from the default branch
|
||||
const toAwait = [];
|
||||
for (const language of config.languages) {
|
||||
const cacheDir = config.trapCaches[language];
|
||||
|
|
@ -119,6 +130,7 @@ async function uploadTrapCaches(codeql, config, logger) {
|
|||
toAwait.push(cache.saveCache([cacheDir], key));
|
||||
}
|
||||
await Promise.all(toAwait);
|
||||
return true;
|
||||
}
|
||||
exports.uploadTrapCaches = uploadTrapCaches;
|
||||
async function getLanguagesSupportingCaching(codeql, languages, logger) {
|
||||
|
|
@ -147,6 +159,20 @@ async function getLanguagesSupportingCaching(codeql, languages, logger) {
|
|||
return result;
|
||||
}
|
||||
exports.getLanguagesSupportingCaching = getLanguagesSupportingCaching;
|
||||
async function getTotalCacheSize(trapCaches) {
|
||||
const sizes = await Promise.all(Object.values(trapCaches).map(async (cacheDir) => {
|
||||
return new Promise((resolve) => {
|
||||
(0, get_folder_size_1.default)(cacheDir, (err, size) => {
|
||||
// Ignore file system errors when getting the size. It's only used for telemetry anyway.
|
||||
if (err)
|
||||
resolve(0);
|
||||
resolve(size);
|
||||
});
|
||||
});
|
||||
}));
|
||||
return sizes.reduce((a, b) => a + b, 0);
|
||||
}
|
||||
exports.getTotalCacheSize = getTotalCacheSize;
|
||||
async function cacheKey(codeql, language, baseSha) {
|
||||
return `${await cachePrefix(codeql, language)}${baseSha}`;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue