Allow feature flags to specify tool feature requirements
This commit is contained in:
parent
24a01703e4
commit
829376a618
6 changed files with 177 additions and 15 deletions
22
lib/feature-flags.js
generated
22
lib/feature-flags.js
generated
|
|
@ -29,6 +29,7 @@ const path = __importStar(require("path"));
|
|||
const semver = __importStar(require("semver"));
|
||||
const api_client_1 = require("./api-client");
|
||||
const defaults = __importStar(require("./defaults.json"));
|
||||
const tools_features_1 = require("./tools-features");
|
||||
const util = __importStar(require("./util"));
|
||||
const DEFAULT_VERSION_FEATURE_FLAG_PREFIX = "default_codeql_version_";
|
||||
const DEFAULT_VERSION_FEATURE_FLAG_SUFFIX = "_enabled";
|
||||
|
|
@ -48,6 +49,7 @@ exports.CODEQL_VERSION_FINE_GRAINED_PARALLELISM = "2.15.1";
|
|||
*/
|
||||
var Feature;
|
||||
(function (Feature) {
|
||||
Feature["AutobuildDirectTracingEnabled"] = "autobuild_direct_tracing_enabled";
|
||||
Feature["CliSarifMerge"] = "cli_sarif_merge_enabled";
|
||||
Feature["CppDependencyInstallation"] = "cpp_dependency_installation_enabled";
|
||||
Feature["CppTrapCachingEnabled"] = "cpp_trap_caching_enabled";
|
||||
|
|
@ -57,6 +59,12 @@ var Feature;
|
|||
Feature["QaTelemetryEnabled"] = "qa_telemetry_enabled";
|
||||
})(Feature || (exports.Feature = Feature = {}));
|
||||
exports.featureConfig = {
|
||||
[Feature.AutobuildDirectTracingEnabled]: {
|
||||
envVar: "CODEQL_ACTION_AUTOBUILD_BUILD_MODE_DIRECT_TRACING",
|
||||
minimumVersion: undefined,
|
||||
toolsFeature: tools_features_1.ToolsFeature.TraceCommandUseBuildMode,
|
||||
defaultValue: false,
|
||||
},
|
||||
[Feature.CliSarifMerge]: {
|
||||
envVar: "CODEQL_ACTION_CLI_SARIF_MERGE",
|
||||
// This is guarded by a `supportsFeature` check rather than by a version check.
|
||||
|
|
@ -124,6 +132,9 @@ class Features {
|
|||
if (!codeql && exports.featureConfig[feature].minimumVersion) {
|
||||
throw new Error(`Internal error: A minimum version is specified for feature ${feature}, but no instance of CodeQL was provided.`);
|
||||
}
|
||||
if (!codeql && exports.featureConfig[feature].toolsFeature) {
|
||||
throw new Error(`Internal error: A required tools feature is specified for feature ${feature}, but no instance of CodeQL was provided.`);
|
||||
}
|
||||
const envVar = (process.env[exports.featureConfig[feature].envVar] || "").toLocaleLowerCase();
|
||||
// Do not use this feature if user explicitly disables it via an environment variable.
|
||||
if (envVar === "false") {
|
||||
|
|
@ -143,6 +154,17 @@ class Features {
|
|||
`version ${minimumVersion} for feature ${feature}.`);
|
||||
}
|
||||
}
|
||||
const toolsFeature = exports.featureConfig[feature].toolsFeature;
|
||||
if (codeql && toolsFeature) {
|
||||
if (!(await codeql.supportsFeature(toolsFeature))) {
|
||||
this.logger.debug(`Feature ${feature} is disabled because the CodeQL CLI version does not support the ` +
|
||||
`required tools feature ${toolsFeature}.`);
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
this.logger.debug(`CodeQL CLI version ${(await codeql.getVersion()).version} supports the required tools feature ${toolsFeature} for feature ${feature}.`);
|
||||
}
|
||||
}
|
||||
// Use this feature if user explicitly enables it via an environment variable.
|
||||
if (envVar === "true") {
|
||||
this.logger.debug(`Feature ${feature} is enabled via the environment variable ${exports.featureConfig[feature].envVar}.`);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue