Skip to content

Keep user-provided query filters first #2938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ See the [releases page](https://github.com/github/codeql-action/releases) for th

## [UNRELEASED]

No user facing changes.
- Fix bug in PR analysis where user-provided `include` query filter fails to exclude non-included queries. [#2938](https://github.com/github/codeql-action/pull/2938)

## 3.29.0 - 11 Jun 2025

Expand Down
6 changes: 5 additions & 1 deletion lib/codeql.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/codeql.js.map

Large diffs are not rendered by default.

22 changes: 10 additions & 12 deletions lib/codeql.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/codeql.test.js.map

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions lib/config-utils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/config-utils.js.map

Large diffs are not rendered by default.

40 changes: 7 additions & 33 deletions lib/config-utils.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/config-utils.test.js.map

Large diffs are not rendered by default.

27 changes: 14 additions & 13 deletions src/codeql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import * as actionsUtil from "./actions-util";
import { GitHubApiDetails } from "./api-client";
import { CliError } from "./cli-errors";
import * as codeql from "./codeql";
import { AugmentationProperties, Config } from "./config-utils";
import {
AugmentationProperties,
Config,
defaultAugmentationProperties,
} from "./config-utils";
import * as defaults from "./defaults.json";
import { DocUrl } from "./doc-url";
import { FeatureEnablement } from "./feature-flags";
Expand Down Expand Up @@ -537,8 +541,7 @@ test(
"basic",
injectedConfigMacro,
{
queriesInputCombines: false,
packsInputCombines: false,
...defaultAugmentationProperties,
},
{},
{},
Expand All @@ -548,8 +551,7 @@ test(
"injected packs from input",
injectedConfigMacro,
{
queriesInputCombines: false,
packsInputCombines: false,
...defaultAugmentationProperties,
packsInput: ["xxx", "yyy"],
},
{},
Expand All @@ -562,7 +564,7 @@ test(
"injected packs from input with existing packs combines",
injectedConfigMacro,
{
queriesInputCombines: false,
...defaultAugmentationProperties,
packsInputCombines: true,
packsInput: ["xxx", "yyy"],
},
Expand All @@ -584,8 +586,7 @@ test(
"injected packs from input with existing packs overrides",
injectedConfigMacro,
{
queriesInputCombines: false,
packsInputCombines: false,
...defaultAugmentationProperties,
packsInput: ["xxx", "yyy"],
},
{
Expand All @@ -605,8 +606,7 @@ test(
"injected queries from input",
injectedConfigMacro,
{
queriesInputCombines: false,
packsInputCombines: false,
...defaultAugmentationProperties,
queriesInput: [{ uses: "xxx" }, { uses: "yyy" }],
},
{},
Expand All @@ -626,8 +626,7 @@ test(
"injected queries from input overrides",
injectedConfigMacro,
{
queriesInputCombines: false,
packsInputCombines: false,
...defaultAugmentationProperties,
queriesInput: [{ uses: "xxx" }, { uses: "yyy" }],
},
{
Expand All @@ -651,8 +650,8 @@ test(
"injected queries from input combines",
injectedConfigMacro,
{
...defaultAugmentationProperties,
queriesInputCombines: true,
packsInputCombines: false,
queriesInput: [{ uses: "xxx" }, { uses: "yyy" }],
},
{
Expand All @@ -679,6 +678,7 @@ test(
"injected queries from input combines 2",
injectedConfigMacro,
{
...defaultAugmentationProperties,
queriesInputCombines: true,
packsInputCombines: true,
queriesInput: [{ uses: "xxx" }, { uses: "yyy" }],
Expand All @@ -700,6 +700,7 @@ test(
"injected queries and packs, but empty",
injectedConfigMacro,
{
...defaultAugmentationProperties,
queriesInputCombines: true,
packsInputCombines: true,
queriesInput: [],
Expand Down
6 changes: 5 additions & 1 deletion src/codeql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1266,8 +1266,12 @@ async function generateCodeScanningConfig(
}

augmentedConfig["query-filters"] = [
...(config.augmentationProperties.defaultQueryFilters || []),
// Ordering matters. If the first filter is an inclusion, it implicitly
// excludes all queries that are not included. If it is an exclusion,
// it implicitly includes all queries that are not excluded. So user
// filters (if any) should always be first to preserve intent.
...(augmentedConfig["query-filters"] || []),
...(config.augmentationProperties.extraQueryExclusions || []),
];
if (augmentedConfig["query-filters"]?.length === 0) {
delete augmentedConfig["query-filters"];
Expand Down
Loading
Loading