mirror of
https://github.com/github/codeql-action.git
synced 2025-12-28 02:00:12 +08:00
Override query configuration for Code Quality only analyses
This commit is contained in:
@@ -197,18 +197,36 @@ test("load code quality config", async (t) => {
|
||||
}),
|
||||
);
|
||||
|
||||
t.deepEqual(
|
||||
config,
|
||||
await configUtils.getDefaultConfig(
|
||||
createTestInitConfigInputs({
|
||||
analysisKindsInput: "code-quality",
|
||||
languagesInput: languages,
|
||||
tempDir,
|
||||
codeql,
|
||||
logger,
|
||||
}),
|
||||
),
|
||||
);
|
||||
const userConfig: configUtils.UserConfig = {
|
||||
"disable-default-queries": true,
|
||||
queries: [{ uses: "code-quality" }],
|
||||
"query-filters": [],
|
||||
};
|
||||
|
||||
// And the config we expect it to result in
|
||||
const expectedConfig: configUtils.Config = {
|
||||
analysisKinds: [AnalysisKind.CodeQuality],
|
||||
languages: [KnownLanguage.actions],
|
||||
buildMode: undefined,
|
||||
// This gets set because we only have `AnalysisKind.CodeQuality`
|
||||
originalUserInput: userConfig,
|
||||
computedConfig: userConfig,
|
||||
tempDir,
|
||||
codeQLCmd: codeql.getPath(),
|
||||
gitHubVersion: githubVersion,
|
||||
dbLocation: path.resolve(tempDir, "codeql_databases"),
|
||||
debugMode: false,
|
||||
debugArtifactName: "",
|
||||
debugDatabaseName: "",
|
||||
trapCaches: {},
|
||||
trapCacheDownloadTime: 0,
|
||||
dependencyCachingEnabled: CachingKind.None,
|
||||
extraQueryExclusions: [],
|
||||
overlayDatabaseMode: OverlayDatabaseMode.None,
|
||||
useOverlayDatabaseCaching: false,
|
||||
};
|
||||
|
||||
t.deepEqual(config, expectedConfig);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
AnalysisConfig,
|
||||
AnalysisKind,
|
||||
CodeQuality,
|
||||
codeQualityQueries,
|
||||
CodeScanning,
|
||||
parseAnalysisKinds,
|
||||
} from "./analyses";
|
||||
@@ -34,6 +35,7 @@ import {
|
||||
BuildMode,
|
||||
codeQlVersionAtLeast,
|
||||
cloneObject,
|
||||
isDefined,
|
||||
} from "./util";
|
||||
|
||||
// Property names from the user-supplied config file.
|
||||
@@ -1080,6 +1082,19 @@ function userConfigFromActionPath(tempDir: string): string {
|
||||
return path.resolve(tempDir, "user-config-from-action.yml");
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given `UserConfig` contains any query customisations.
|
||||
*
|
||||
* @returns Returns `true` if the `UserConfig` customises which queries are run.
|
||||
*/
|
||||
function hasQueryCustomisation(userConfig: UserConfig): boolean {
|
||||
return (
|
||||
isDefined(userConfig["disable-default-queries"]) ||
|
||||
isDefined(userConfig.queries) ||
|
||||
isDefined(userConfig["query-filters"])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load and return the config.
|
||||
*
|
||||
@@ -1116,6 +1131,29 @@ export async function initConfig(inputs: InitConfigInputs): Promise<Config> {
|
||||
|
||||
const config = await initActionState(inputs, userConfig);
|
||||
|
||||
// If Code Scanning analysis is disabled, then we initialise the database for Code Quality.
|
||||
// That entails disabling the default queries and only running quality queries.
|
||||
if (!isCodeScanningEnabled(config)) {
|
||||
// Warn if any query customisations are present in the computed configuration.
|
||||
if (hasQueryCustomisation(config.computedConfig)) {
|
||||
logger.warning(
|
||||
"Query customizations will be ignored, because only `code-quality` analysis is enabled.",
|
||||
);
|
||||
}
|
||||
|
||||
const queries = codeQualityQueries.map((v) => ({ uses: v }));
|
||||
|
||||
// Set the query customisation options for Code Quality only analysis.
|
||||
config.originalUserInput["disable-default-queries"] = true;
|
||||
config.originalUserInput.queries = queries;
|
||||
config.originalUserInput["query-filters"] = [];
|
||||
|
||||
// Update the computed configuration for the call to `getOverlayDatabaseMode`.
|
||||
config.computedConfig["disable-default-queries"] = true;
|
||||
config.computedConfig.queries = queries;
|
||||
config.computedConfig["query-filters"] = [];
|
||||
}
|
||||
|
||||
// The choice of overlay database mode depends on the selection of languages
|
||||
// and queries, which in turn depends on the user config and the augmentation
|
||||
// properties. So we need to calculate the overlay database mode after the
|
||||
|
||||
Reference in New Issue
Block a user