Skip to content

Commit 840c9ad

Browse files
committed
Add logging to combineQueries
1 parent 54746c8 commit 840c9ad

File tree

7 files changed

+50
-6
lines changed

7 files changed

+50
-6
lines changed

lib/analyze-action.js

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init-action.js

Lines changed: 17 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/upload-sarif-action.js

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/actions-util.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,12 @@ export function isSelfHostedRunner() {
249249

250250
/** Determines whether we are running in default setup. */
251251
export function isDefaultSetup(): boolean {
252-
return getWorkflowEventName() === "dynamic";
252+
try {
253+
return getWorkflowEventName() === "dynamic";
254+
} catch {
255+
// `getWorkflowEventName()` throws if `GITHUB_EVENT_NAME` is not set.
256+
return false;
257+
}
253258
}
254259

255260
export function prettyPrintInvocation(cmd: string, args: string[]): string {

src/codeql.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ const injectedConfigMacro = test.macro({
505505
tempDir,
506506
};
507507
thisStubConfig.computedConfig = generateCodeScanningConfig(
508+
getRunnerLogger(true),
508509
thisStubConfig.originalUserInput,
509510
augmentationProperties,
510511
);

src/config-utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ export async function initActionState(
473473
// Compute the full Code Scanning configuration that combines the configuration from the
474474
// configuration file / `config` input with other inputs, such as `queries`.
475475
const computedConfig = generateCodeScanningConfig(
476+
logger,
476477
userConfig,
477478
augmentationProperties,
478479
);

src/config/db-config.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import * as path from "path";
22

33
import * as semver from "semver";
44

5+
import { isDefaultSetup } from "../actions-util";
56
import * as errorMessages from "../error-messages";
67
import {
78
RepositoryProperties,
89
RepositoryPropertyName,
910
} from "../feature-flags/properties";
1011
import { Language } from "../languages";
12+
import { Logger } from "../logging";
1113
import { cloneObject, ConfigurationError, prettyPrintPack } from "../util";
1214

1315
export interface ExcludeQueryFilter {
@@ -364,11 +366,13 @@ function parseQueriesFromInput(
364366
/**
365367
* Combines queries from various configuration sources.
366368
*
369+
* @param logger The logger to use.
367370
* @param config The loaded configuration file (either `config-file` or `config` input).
368371
* @param augmentationProperties Additional configuration data from other sources.
369372
* @returns Returns `augmentedConfig` with `queries` set to the computed array of queries.
370373
*/
371374
function combineQueries(
375+
logger: Logger,
372376
config: UserConfig,
373377
augmentationProperties: AugmentationProperties,
374378
): QuerySpec[] {
@@ -383,6 +387,12 @@ function combineQueries(
383387
// settings. If they don't allow combining with other query configurations, return just the
384388
// ones configured in the repository properties.
385389
if (!augmentationProperties.repoPropertyQueries.combines) {
390+
if (!isDefaultSetup()) {
391+
logger.info(
392+
`Queries are configured in the repository properties and don't allow combining with other query settings. ` +
393+
`Any queries configured elsewhere will be ignored.`,
394+
);
395+
}
386396
return augmentationProperties.repoPropertyQueries.input;
387397
} else {
388398
// Otherwise, add them to the query array and continue.
@@ -414,6 +424,7 @@ function combineQueries(
414424
}
415425

416426
export function generateCodeScanningConfig(
427+
logger: Logger,
417428
originalUserInput: UserConfig,
418429
augmentationProperties: AugmentationProperties,
419430
): UserConfig {
@@ -422,9 +433,13 @@ export function generateCodeScanningConfig(
422433

423434
// Inject the queries from the input
424435
augmentedConfig.queries = combineQueries(
436+
logger,
425437
augmentedConfig,
426438
augmentationProperties,
427439
);
440+
logger.debug(
441+
`Combined queries: ${augmentedConfig.queries?.map((q) => q.uses).join(",")}`,
442+
);
428443
if (augmentedConfig.queries?.length === 0) {
429444
delete augmentedConfig.queries;
430445
}

0 commit comments

Comments
 (0)