mirror of
https://github.com/github/codeql-action.git
synced 2025-12-11 18:24:43 +08:00
Compare commits
2 Commits
v2.27.1
...
henrymerce
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5a14a7b209 | ||
|
|
d060b60d93 |
22
lib/feature-flags.js
generated
22
lib/feature-flags.js
generated
@@ -28,7 +28,6 @@ const fs = __importStar(require("fs"));
|
|||||||
const path = __importStar(require("path"));
|
const path = __importStar(require("path"));
|
||||||
const semver = __importStar(require("semver"));
|
const semver = __importStar(require("semver"));
|
||||||
const api_client_1 = require("./api-client");
|
const api_client_1 = require("./api-client");
|
||||||
const codeql_1 = require("./codeql");
|
|
||||||
const defaults = __importStar(require("./defaults.json"));
|
const defaults = __importStar(require("./defaults.json"));
|
||||||
const util = __importStar(require("./util"));
|
const util = __importStar(require("./util"));
|
||||||
const DEFAULT_VERSION_FEATURE_FLAG_PREFIX = "default_codeql_version_";
|
const DEFAULT_VERSION_FEATURE_FLAG_PREFIX = "default_codeql_version_";
|
||||||
@@ -54,7 +53,7 @@ exports.featureConfig = {
|
|||||||
},
|
},
|
||||||
[Feature.ExportCodeScanningConfigEnabled]: {
|
[Feature.ExportCodeScanningConfigEnabled]: {
|
||||||
envVar: "CODEQL_ACTION_EXPORT_CODE_SCANNING_CONFIG",
|
envVar: "CODEQL_ACTION_EXPORT_CODE_SCANNING_CONFIG",
|
||||||
minimumVersion: codeql_1.CODEQL_VERSION_EXPORT_CODE_SCANNING_CONFIG,
|
minimumVersion: "2.12.3",
|
||||||
defaultValue: false,
|
defaultValue: false,
|
||||||
},
|
},
|
||||||
[Feature.MlPoweredQueriesEnabled]: {
|
[Feature.MlPoweredQueriesEnabled]: {
|
||||||
@@ -76,6 +75,7 @@ exports.FEATURE_FLAGS_FILE_NAME = "cached-feature-flags.json";
|
|||||||
*/
|
*/
|
||||||
class Features {
|
class Features {
|
||||||
constructor(gitHubVersion, repositoryNwo, tempDir, logger) {
|
constructor(gitHubVersion, repositoryNwo, tempDir, logger) {
|
||||||
|
this.logger = logger;
|
||||||
this.gitHubFeatureFlags = new GitHubFeatureFlags(gitHubVersion, repositoryNwo, path.join(tempDir, exports.FEATURE_FLAGS_FILE_NAME), logger);
|
this.gitHubFeatureFlags = new GitHubFeatureFlags(gitHubVersion, repositoryNwo, path.join(tempDir, exports.FEATURE_FLAGS_FILE_NAME), logger);
|
||||||
}
|
}
|
||||||
async getDefaultCliVersion(variant) {
|
async getDefaultCliVersion(variant) {
|
||||||
@@ -100,22 +100,36 @@ class Features {
|
|||||||
const envVar = (process.env[exports.featureConfig[feature].envVar] || "").toLocaleLowerCase();
|
const envVar = (process.env[exports.featureConfig[feature].envVar] || "").toLocaleLowerCase();
|
||||||
// Do not use this feature if user explicitly disables it via an environment variable.
|
// Do not use this feature if user explicitly disables it via an environment variable.
|
||||||
if (envVar === "false") {
|
if (envVar === "false") {
|
||||||
|
this.logger.debug(`Feature ${feature} is disabled via the environment variable ${exports.featureConfig[feature].envVar}.`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Never use this feature if the CLI version explicitly can't support it.
|
// Never use this feature if the CLI version explicitly can't support it.
|
||||||
const minimumVersion = exports.featureConfig[feature].minimumVersion;
|
const minimumVersion = exports.featureConfig[feature].minimumVersion;
|
||||||
|
this.logger.debug(`Minimum version for feature ${feature} is ${minimumVersion}.`);
|
||||||
if (codeql && minimumVersion) {
|
if (codeql && minimumVersion) {
|
||||||
if (!(await util.codeQlVersionAbove(codeql, minimumVersion))) {
|
if (!(await util.codeQlVersionAbove(codeql, minimumVersion))) {
|
||||||
|
this.logger.debug(`Feature ${feature} is disabled because the CodeQL CLI version is older than the minimum ` +
|
||||||
|
`version ${minimumVersion}.`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
this.logger.debug(`CodeQL CLI version ${await codeql.getVersion()} is newer than the minimum ` +
|
||||||
|
`version ${minimumVersion} for feature ${feature}.`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Use this feature if user explicitly enables it via an environment variable.
|
// Use this feature if user explicitly enables it via an environment variable.
|
||||||
if (envVar === "true") {
|
if (envVar === "true") {
|
||||||
|
this.logger.debug(`Feature ${feature} is enabled via the environment variable ${exports.featureConfig[feature].envVar}.`);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Ask the GitHub API if the feature is enabled.
|
// Ask the GitHub API if the feature is enabled.
|
||||||
return ((await this.gitHubFeatureFlags.getValue(feature)) ??
|
const apiValue = await this.gitHubFeatureFlags.getValue(feature);
|
||||||
exports.featureConfig[feature].defaultValue);
|
if (apiValue !== undefined) {
|
||||||
|
this.logger.debug(`Feature ${feature} is ${apiValue ? "enabled" : "disabled"} via the GitHub API.`);
|
||||||
|
return apiValue;
|
||||||
|
}
|
||||||
|
this.logger.debug(`Feature ${feature} is ${exports.featureConfig[feature].defaultValue ? "enabled" : "disabled"} due to its default value.`);
|
||||||
|
return exports.featureConfig[feature].defaultValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.Features = Features;
|
exports.Features = Features;
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -4,7 +4,7 @@ import * as path from "path";
|
|||||||
import * as semver from "semver";
|
import * as semver from "semver";
|
||||||
|
|
||||||
import { getApiClient } from "./api-client";
|
import { getApiClient } from "./api-client";
|
||||||
import { CodeQL, CODEQL_VERSION_EXPORT_CODE_SCANNING_CONFIG } from "./codeql";
|
import { CodeQL } from "./codeql";
|
||||||
import * as defaults from "./defaults.json";
|
import * as defaults from "./defaults.json";
|
||||||
import { Logger } from "./logging";
|
import { Logger } from "./logging";
|
||||||
import { RepositoryNwo } from "./repository";
|
import { RepositoryNwo } from "./repository";
|
||||||
@@ -57,7 +57,7 @@ export const featureConfig: Record<
|
|||||||
},
|
},
|
||||||
[Feature.ExportCodeScanningConfigEnabled]: {
|
[Feature.ExportCodeScanningConfigEnabled]: {
|
||||||
envVar: "CODEQL_ACTION_EXPORT_CODE_SCANNING_CONFIG",
|
envVar: "CODEQL_ACTION_EXPORT_CODE_SCANNING_CONFIG",
|
||||||
minimumVersion: CODEQL_VERSION_EXPORT_CODE_SCANNING_CONFIG,
|
minimumVersion: "2.12.3",
|
||||||
defaultValue: false,
|
defaultValue: false,
|
||||||
},
|
},
|
||||||
[Feature.MlPoweredQueriesEnabled]: {
|
[Feature.MlPoweredQueriesEnabled]: {
|
||||||
@@ -94,7 +94,7 @@ export class Features implements FeatureEnablement {
|
|||||||
gitHubVersion: util.GitHubVersion,
|
gitHubVersion: util.GitHubVersion,
|
||||||
repositoryNwo: RepositoryNwo,
|
repositoryNwo: RepositoryNwo,
|
||||||
tempDir: string,
|
tempDir: string,
|
||||||
logger: Logger
|
private readonly logger: Logger
|
||||||
) {
|
) {
|
||||||
this.gitHubFeatureFlags = new GitHubFeatureFlags(
|
this.gitHubFeatureFlags = new GitHubFeatureFlags(
|
||||||
gitHubVersion,
|
gitHubVersion,
|
||||||
@@ -135,26 +135,58 @@ export class Features implements FeatureEnablement {
|
|||||||
|
|
||||||
// Do not use this feature if user explicitly disables it via an environment variable.
|
// Do not use this feature if user explicitly disables it via an environment variable.
|
||||||
if (envVar === "false") {
|
if (envVar === "false") {
|
||||||
|
this.logger.debug(
|
||||||
|
`Feature ${feature} is disabled via the environment variable ${featureConfig[feature].envVar}.`
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Never use this feature if the CLI version explicitly can't support it.
|
// Never use this feature if the CLI version explicitly can't support it.
|
||||||
const minimumVersion = featureConfig[feature].minimumVersion;
|
const minimumVersion = featureConfig[feature].minimumVersion;
|
||||||
|
this.logger.debug(
|
||||||
|
`Minimum version for feature ${feature} is ${minimumVersion}.`
|
||||||
|
);
|
||||||
|
|
||||||
if (codeql && minimumVersion) {
|
if (codeql && minimumVersion) {
|
||||||
if (!(await util.codeQlVersionAbove(codeql, minimumVersion))) {
|
if (!(await util.codeQlVersionAbove(codeql, minimumVersion))) {
|
||||||
|
this.logger.debug(
|
||||||
|
`Feature ${feature} is disabled because the CodeQL CLI version is older than the minimum ` +
|
||||||
|
`version ${minimumVersion}.`
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
|
} else {
|
||||||
|
this.logger.debug(
|
||||||
|
`CodeQL CLI version ${await codeql.getVersion()} is newer than the minimum ` +
|
||||||
|
`version ${minimumVersion} for feature ${feature}.`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use this feature if user explicitly enables it via an environment variable.
|
// Use this feature if user explicitly enables it via an environment variable.
|
||||||
if (envVar === "true") {
|
if (envVar === "true") {
|
||||||
|
this.logger.debug(
|
||||||
|
`Feature ${feature} is enabled via the environment variable ${featureConfig[feature].envVar}.`
|
||||||
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ask the GitHub API if the feature is enabled.
|
// Ask the GitHub API if the feature is enabled.
|
||||||
return (
|
const apiValue = await this.gitHubFeatureFlags.getValue(feature);
|
||||||
(await this.gitHubFeatureFlags.getValue(feature)) ??
|
if (apiValue !== undefined) {
|
||||||
featureConfig[feature].defaultValue
|
this.logger.debug(
|
||||||
|
`Feature ${feature} is ${
|
||||||
|
apiValue ? "enabled" : "disabled"
|
||||||
|
} via the GitHub API.`
|
||||||
|
);
|
||||||
|
return apiValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.logger.debug(
|
||||||
|
`Feature ${feature} is ${
|
||||||
|
featureConfig[feature].defaultValue ? "enabled" : "disabled"
|
||||||
|
} due to its default value.`
|
||||||
);
|
);
|
||||||
|
return featureConfig[feature].defaultValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user