Merge branch 'main' into henrymercer/bump-minimum-codeql-version

This commit is contained in:
Henry Mercer 2023-07-10 13:16:09 +01:00
commit fed45865ba
234 changed files with 26797 additions and 28982 deletions

40
lib/util.js generated
View file

@ -38,8 +38,8 @@ const semver = __importStar(require("semver"));
const api_client_1 = require("./api-client");
const apiCompatibility = __importStar(require("./api-compatibility.json"));
const config_utils_1 = require("./config-utils");
const environment_1 = require("./environment");
const feature_flags_1 = require("./feature-flags");
const shared_environment_1 = require("./shared-environment");
/**
* Specifies bundle versions that are known to be broken
* and will not be used if found in the toolcache.
@ -108,9 +108,18 @@ exports.withTmpDir = withTmpDir;
* from committing too much of the available memory to CodeQL.
* @returns number
*/
function getSystemReservedMemoryMegaBytes() {
async function getSystemReservedMemoryMegaBytes(totalMemoryMegaBytes, features) {
// Windows needs more memory for OS processes.
return 1024 * (process.platform === "win32" ? 1.5 : 1);
const fixedAmount = 1024 * (process.platform === "win32" ? 1.5 : 1);
if (await features.getValue(feature_flags_1.Feature.ScalingReservedRam)) {
// Reserve an additional 2% of the total memory, since the amount used by
// the kernel for page tables scales with the size of physical memory.
const scaledAmount = 0.02 * totalMemoryMegaBytes;
return fixedAmount + scaledAmount;
}
else {
return fixedAmount;
}
}
/**
* Get the value of the codeql `--ram` flag as configured by the `ram` input.
@ -119,7 +128,7 @@ function getSystemReservedMemoryMegaBytes() {
*
* @returns {number} the amount of RAM to use, in megabytes
*/
function getMemoryFlagValue(userInput) {
async function getMemoryFlagValue(userInput, features) {
let memoryToUseMegaBytes;
if (userInput) {
memoryToUseMegaBytes = Number(userInput);
@ -130,7 +139,7 @@ function getMemoryFlagValue(userInput) {
else {
const totalMemoryBytes = os.totalmem();
const totalMemoryMegaBytes = totalMemoryBytes / (1024 * 1024);
const reservedMemoryMegaBytes = getSystemReservedMemoryMegaBytes();
const reservedMemoryMegaBytes = await getSystemReservedMemoryMegaBytes(totalMemoryMegaBytes, features);
memoryToUseMegaBytes = totalMemoryMegaBytes - reservedMemoryMegaBytes;
}
return Math.floor(memoryToUseMegaBytes);
@ -143,8 +152,9 @@ exports.getMemoryFlagValue = getMemoryFlagValue;
*
* @returns string
*/
function getMemoryFlag(userInput) {
return `--ram=${getMemoryFlagValue(userInput)}`;
async function getMemoryFlag(userInput, features) {
const megabytes = await getMemoryFlagValue(userInput, features);
return `--ram=${megabytes}`;
}
exports.getMemoryFlag = getMemoryFlag;
/**
@ -337,11 +347,11 @@ exports.assertNever = assertNever;
* knowing what version of CodeQL we're running.
*/
function initializeEnvironment(version) {
core.exportVariable(String(shared_environment_1.EnvVar.FEATURE_MULTI_LANGUAGE), "false");
core.exportVariable(String(shared_environment_1.EnvVar.FEATURE_SANDWICH), "false");
core.exportVariable(String(shared_environment_1.EnvVar.FEATURE_SARIF_COMBINE), "true");
core.exportVariable(String(shared_environment_1.EnvVar.FEATURE_WILL_UPLOAD), "true");
core.exportVariable(String(shared_environment_1.EnvVar.VERSION), version);
core.exportVariable(String(environment_1.EnvVar.FEATURE_MULTI_LANGUAGE), "false");
core.exportVariable(String(environment_1.EnvVar.FEATURE_SANDWICH), "false");
core.exportVariable(String(environment_1.EnvVar.FEATURE_SARIF_COMBINE), "true");
core.exportVariable(String(environment_1.EnvVar.FEATURE_WILL_UPLOAD), "true");
core.exportVariable(String(environment_1.EnvVar.VERSION), version);
}
exports.initializeEnvironment = initializeEnvironment;
/**
@ -500,7 +510,7 @@ exports.getMlPoweredJsQueriesStatus = getMlPoweredJsQueriesStatus;
* In test mode, we don't upload SARIF results or status reports to the GitHub API.
*/
function isInTestMode() {
return process.env[shared_environment_1.CODEQL_ACTION_TEST_MODE] === "true";
return process.env[environment_1.EnvVar.TEST_MODE] === "true";
}
exports.isInTestMode = isInTestMode;
/**
@ -727,9 +737,9 @@ exports.fixInvalidNotifications = fixInvalidNotifications;
* For context, see documentation of:
* `CODEQL_ACTION_DISABLE_DUPLICATE_LOCATION_FIX`. */
function fixInvalidNotificationsInFile(inputPath, outputPath, logger) {
if (process.env[shared_environment_1.CODEQL_ACTION_DISABLE_DUPLICATE_LOCATION_FIX] === "true") {
if (process.env[environment_1.EnvVar.DISABLE_DUPLICATE_LOCATION_FIX] === "true") {
logger.info("SARIF notification object duplicate location fix disabled by the " +
`${shared_environment_1.CODEQL_ACTION_DISABLE_DUPLICATE_LOCATION_FIX} environment variable.`);
`${environment_1.EnvVar.DISABLE_DUPLICATE_LOCATION_FIX} environment variable.`);
fs.renameSync(inputPath, outputPath);
}
else {