C++: simplify CppDependencyInstallation interface

This commit is contained in:
Paolo Tranquilli 2023-09-20 09:50:30 +02:00
parent c4c06786f2
commit bf2187592f
7 changed files with 45 additions and 76 deletions

38
lib/autobuild.js generated
View file

@ -100,35 +100,27 @@ async function determineAutobuildLanguages(config, logger) {
}
exports.determineAutobuildLanguages = determineAutobuildLanguages;
async function setupCppAutobuild(codeql, logger) {
const envVar = "CODEQL_EXTRACTOR_CPP_AUTOINSTALL_DEPENDENCIES";
const actionInput = (0, actions_util_1.getOptionalInput)("cpp-autoinstall-dependencies");
const envVar = feature_flags_1.featureConfig[feature_flags_1.Feature.CppDependencyInstallation].envVar;
const featureName = "C++ automatic installation of dependencies";
if (actionInput === "true") {
if (!(await (0, util_1.codeQlVersionAbove)(codeql, "2.15.0"))) {
logger.warning(`${featureName} was explicitly requested but is only available starting from CodeQL version 2.15.0, disabling it`);
const gitHubVersion = await (0, api_client_1.getGitHubVersion)();
const repositoryNwo = (0, repository_1.parseRepositoryNwo)((0, util_1.getRequiredEnvParam)("GITHUB_REPOSITORY"));
const features = new feature_flags_1.Features(gitHubVersion, repositoryNwo, (0, actions_util_1.getTemporaryDirectory)(), logger);
if (await features.getValue(feature_flags_1.Feature.CppDependencyInstallation, codeql)) {
// disable autoinstall on self-hosted runners unless explicitly requested
if (process.env["RUNNER_ENVIRONMENT"] === "self-hosted" &&
process.env[envVar] !== "true") {
logger.info(`Disabling ${featureName} as we are on a self-hosted runner`);
logger.info(`This can be enabled by setting ${envVar}: true in the env`);
core.exportVariable(envVar, "false");
}
else {
logger.info(`${actionInput === "true" ? "Enabling" : "Disabling"} ${featureName} explicitly requested`);
core.exportVariable(envVar, actionInput);
}
}
else if (process.env["RUNNER_ENVIRONMENT"] === "self-hosted") {
logger.info(`Disabling ${featureName} which is the default for self-hosted runners`);
core.exportVariable(envVar, "false");
}
else {
const gitHubVersion = await (0, api_client_1.getGitHubVersion)();
const repositoryNwo = (0, repository_1.parseRepositoryNwo)((0, util_1.getRequiredEnvParam)("GITHUB_REPOSITORY"));
const features = new feature_flags_1.Features(gitHubVersion, repositoryNwo, (0, actions_util_1.getTemporaryDirectory)(), logger);
if (await features.getValue(feature_flags_1.Feature.CppDependencyInstallation, codeql)) {
logger.info(`Enabling ${featureName}`);
logger.info(`Enabling ${featureName}`);
core.exportVariable(envVar, "true");
}
else {
logger.info(`Disabling ${featureName}`);
core.exportVariable(envVar, "false");
}
}
else {
logger.info(`Disabling ${featureName}`);
core.exportVariable(envVar, "false");
}
}
async function runAutobuild(language, config, logger) {