Merge pull request #1184 from github/edoardo/trap-telemetry-followup
Use `util.promisify` instead of manually constructing promise
This commit is contained in:
commit
b0d61cff1a
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;
|
exports.getTotalCacheSize = exports.getLanguagesSupportingCaching = exports.uploadTrapCaches = exports.downloadTrapCaches = exports.getTrapCachingExtractorConfigArgsForLang = exports.getTrapCachingExtractorConfigArgs = void 0;
|
||||||
const fs = __importStar(require("fs"));
|
const fs = __importStar(require("fs"));
|
||||||
const path = __importStar(require("path"));
|
const path = __importStar(require("path"));
|
||||||
|
const util_1 = require("util");
|
||||||
const cache = __importStar(require("@actions/cache"));
|
const cache = __importStar(require("@actions/cache"));
|
||||||
const get_folder_size_1 = __importDefault(require("get-folder-size"));
|
const get_folder_size_1 = __importDefault(require("get-folder-size"));
|
||||||
const actionsUtil = __importStar(require("./actions-util"));
|
const actionsUtil = __importStar(require("./actions-util"));
|
||||||
const codeql_1 = require("./codeql");
|
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
|
// This constant should be bumped if we make a breaking change
|
||||||
// to how the CodeQL Action stores or retrieves the TRAP cache,
|
// to how the CodeQL Action stores or retrieves the TRAP cache,
|
||||||
// and will invalidate previous caches. We don't need to bump
|
// and will invalidate previous caches. We don't need to bump
|
||||||
|
|
@ -136,7 +137,7 @@ exports.uploadTrapCaches = uploadTrapCaches;
|
||||||
async function getLanguagesSupportingCaching(codeql, languages, logger) {
|
async function getLanguagesSupportingCaching(codeql, languages, logger) {
|
||||||
var _a, _b, _c, _d;
|
var _a, _b, _c, _d;
|
||||||
const result = [];
|
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;
|
return result;
|
||||||
const resolveResult = await codeql.betterResolveLanguages();
|
const resolveResult = await codeql.betterResolveLanguages();
|
||||||
outer: for (const lang of languages) {
|
outer: for (const lang of languages) {
|
||||||
|
|
@ -160,20 +161,16 @@ async function getLanguagesSupportingCaching(codeql, languages, logger) {
|
||||||
}
|
}
|
||||||
exports.getLanguagesSupportingCaching = getLanguagesSupportingCaching;
|
exports.getLanguagesSupportingCaching = getLanguagesSupportingCaching;
|
||||||
async function getTotalCacheSize(trapCaches, logger) {
|
async function getTotalCacheSize(trapCaches, logger) {
|
||||||
const sizes = await Promise.all(Object.values(trapCaches).map(async (cacheDir) => {
|
try {
|
||||||
return new Promise((resolve) => {
|
const sizes = await Promise.all(Object.values(trapCaches).map(async (cacheDir) => {
|
||||||
(0, get_folder_size_1.default)(cacheDir, (err, size) => {
|
return (0, util_1.promisify)(get_folder_size_1.default)(cacheDir);
|
||||||
if (err) {
|
}));
|
||||||
logger.warning(`Error getting size of ${cacheDir}: ${err}`);
|
return sizes.reduce((a, b) => a + b, 0);
|
||||||
resolve(0);
|
}
|
||||||
}
|
catch (e) {
|
||||||
else {
|
logger.warning(`Encountered an error while getting TRAP cache size: ${e}`);
|
||||||
resolve(size);
|
return 0;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
return sizes.reduce((a, b) => a + b, 0);
|
|
||||||
}
|
}
|
||||||
exports.getTotalCacheSize = getTotalCacheSize;
|
exports.getTotalCacheSize = getTotalCacheSize;
|
||||||
async function cacheKey(codeql, language, baseSha) {
|
async function cacheKey(codeql, language, baseSha) {
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -1,5 +1,6 @@
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
|
import { promisify } from "util";
|
||||||
|
|
||||||
import * as cache from "@actions/cache";
|
import * as cache from "@actions/cache";
|
||||||
import getFolderSize from "get-folder-size";
|
import getFolderSize from "get-folder-size";
|
||||||
|
|
@ -188,21 +189,17 @@ export async function getTotalCacheSize(
|
||||||
trapCaches: Partial<Record<Language, string>>,
|
trapCaches: Partial<Record<Language, string>>,
|
||||||
logger: Logger
|
logger: Logger
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const sizes = await Promise.all(
|
try {
|
||||||
Object.values(trapCaches).map(async (cacheDir) => {
|
const sizes = await Promise.all(
|
||||||
return new Promise<number>((resolve) => {
|
Object.values(trapCaches).map(async (cacheDir) => {
|
||||||
getFolderSize(cacheDir, (err, size) => {
|
return promisify<string, number>(getFolderSize)(cacheDir);
|
||||||
if (err) {
|
})
|
||||||
logger.warning(`Error getting size of ${cacheDir}: ${err}`);
|
);
|
||||||
resolve(0);
|
return sizes.reduce((a, b) => a + b, 0);
|
||||||
} else {
|
} catch (e) {
|
||||||
resolve(size);
|
logger.warning(`Encountered an error while getting TRAP cache size: ${e}`);
|
||||||
}
|
return 0;
|
||||||
});
|
}
|
||||||
});
|
|
||||||
})
|
|
||||||
);
|
|
||||||
return sizes.reduce((a, b) => a + b, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function cacheKey(
|
async function cacheKey(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue