mirror of
https://github.com/github/codeql-action.git
synced 2026-01-06 14:40:10 +08:00
Ignore repository property query config if CQ-only analysis
This commit is contained in:
@@ -29,6 +29,7 @@ import {
|
||||
getRecordingLogger,
|
||||
LoggedMessage,
|
||||
mockCodeQLVersion,
|
||||
createTestConfig,
|
||||
} from "./testing-utils";
|
||||
import {
|
||||
GitHubVariant,
|
||||
@@ -230,6 +231,63 @@ test("load code quality config", async (t) => {
|
||||
});
|
||||
});
|
||||
|
||||
test("initActionState doesn't throw if there are queries configured in the repository properties", async (t) => {
|
||||
return await withTmpDir(async (tempDir) => {
|
||||
const logger = getRunnerLogger(true);
|
||||
const languages = "javascript";
|
||||
|
||||
const codeql = createStubCodeQL({
|
||||
async betterResolveLanguages() {
|
||||
return {
|
||||
extractors: {
|
||||
javascript: [{ extractor_root: "" }],
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
// This should be ignored and no error should be thrown.
|
||||
const repositoryProperties = {
|
||||
"github-codeql-extra-queries": "+foo",
|
||||
};
|
||||
|
||||
// Expected configuration for a CQ-only analysis.
|
||||
const computedConfig: configUtils.UserConfig = {
|
||||
"disable-default-queries": true,
|
||||
queries: [{ uses: "code-quality" }],
|
||||
"query-filters": [],
|
||||
};
|
||||
|
||||
const expectedConfig = createTestConfig({
|
||||
analysisKinds: [AnalysisKind.CodeQuality],
|
||||
languages: [KnownLanguage.javascript],
|
||||
codeQLCmd: codeql.getPath(),
|
||||
computedConfig,
|
||||
dbLocation: path.resolve(tempDir, "codeql_databases"),
|
||||
debugArtifactName: "",
|
||||
debugDatabaseName: "",
|
||||
tempDir,
|
||||
repositoryProperties,
|
||||
});
|
||||
|
||||
await t.notThrowsAsync(async () => {
|
||||
const config = await configUtils.initConfig(
|
||||
createTestInitConfigInputs({
|
||||
analysisKindsInput: "code-quality",
|
||||
languagesInput: languages,
|
||||
repository: { owner: "github", repo: "example" },
|
||||
tempDir,
|
||||
codeql,
|
||||
repositoryProperties,
|
||||
logger,
|
||||
}),
|
||||
);
|
||||
|
||||
t.deepEqual(config, expectedConfig);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test("loading a saved config produces the same config", async (t) => {
|
||||
return await withTmpDir(async (tempDir) => {
|
||||
const logger = getRunnerLogger(true);
|
||||
|
||||
@@ -463,6 +463,24 @@ export async function initActionState(
|
||||
languages,
|
||||
);
|
||||
|
||||
// If `code-quality` is the only enabled analysis kind, we don't support query customisation.
|
||||
// It would be a problem if queries that are configured in repository properties cause `code-quality`-only
|
||||
// analyses to break. We therefore ignore query customisations that are configured in repository properties
|
||||
// if `code-quality` is the only enabled analysis kind.
|
||||
if (
|
||||
analysisKinds.length === 1 &&
|
||||
analysisKinds.includes(AnalysisKind.CodeQuality) &&
|
||||
augmentationProperties.repoPropertyQueries.input
|
||||
) {
|
||||
logger.info(
|
||||
`Ignoring queries configured in the repository properties, because query customisations are not supported for Code Quality analyses.`,
|
||||
);
|
||||
augmentationProperties.repoPropertyQueries = {
|
||||
combines: false,
|
||||
input: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
const { trapCaches, trapCacheDownloadTime } = await downloadCacheWithTime(
|
||||
trapCachingEnabled,
|
||||
codeql,
|
||||
|
||||
Reference in New Issue
Block a user