Use util.promisify instead of manually constructing promise
This commit is contained in:
parent
8a4437ae33
commit
016a5e3bae
3 changed files with 26 additions and 32 deletions
29
lib/trap-caching.js
generated
29
lib/trap-caching.js
generated
|
|
@ -25,11 +25,12 @@ 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_1 = require("./util");
|
||||
const util_2 = 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
|
||||
|
|
@ -136,7 +137,7 @@ exports.uploadTrapCaches = uploadTrapCaches;
|
|||
async function getLanguagesSupportingCaching(codeql, languages, logger) {
|
||||
var _a, _b, _c, _d;
|
||||
const result = [];
|
||||
if (!(await (0, util_1.codeQlVersionAbove)(codeql, codeql_1.CODEQL_VERSION_BETTER_RESOLVE_LANGUAGES)))
|
||||
if (!(await (0, util_2.codeQlVersionAbove)(codeql, codeql_1.CODEQL_VERSION_BETTER_RESOLVE_LANGUAGES)))
|
||||
return result;
|
||||
const resolveResult = await codeql.betterResolveLanguages();
|
||||
outer: for (const lang of languages) {
|
||||
|
|
@ -160,20 +161,16 @@ async function getLanguagesSupportingCaching(codeql, languages, logger) {
|
|||
}
|
||||
exports.getLanguagesSupportingCaching = getLanguagesSupportingCaching;
|
||||
async function getTotalCacheSize(trapCaches, logger) {
|
||||
const sizes = await Promise.all(Object.values(trapCaches).map(async (cacheDir) => {
|
||||
return new Promise((resolve) => {
|
||||
(0, get_folder_size_1.default)(cacheDir, (err, size) => {
|
||||
if (err) {
|
||||
logger.warning(`Error getting size of ${cacheDir}: ${err}`);
|
||||
resolve(0);
|
||||
}
|
||||
else {
|
||||
resolve(size);
|
||||
}
|
||||
});
|
||||
});
|
||||
}));
|
||||
return sizes.reduce((a, b) => a + b, 0);
|
||||
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;
|
||||
}
|
||||
}
|
||||
exports.getTotalCacheSize = getTotalCacheSize;
|
||||
async function cacheKey(codeql, language, baseSha) {
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue