From 1512f400b38466450275d117a9ba7e3ef72b298f Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Wed, 19 Nov 2025 15:35:46 +0000 Subject: [PATCH 01/13] Add function to query `git` for all generated files --- src/git-utils.test.ts | 39 +++++++++++++++++++++++++++++++++++++++ src/git-utils.ts | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/src/git-utils.test.ts b/src/git-utils.test.ts index 06837e0223..67c5213560 100644 --- a/src/git-utils.test.ts +++ b/src/git-utils.test.ts @@ -1,4 +1,5 @@ import * as fs from "fs"; +import * as os from "os"; import * as path from "path"; import * as core from "@actions/core"; @@ -392,3 +393,41 @@ test("getFileOidsUnderPath throws on unexpected output format", async (t) => { runGitCommandStub.restore(); } }); + +test("listFiles returns array of file paths", async (t) => { + sinon + .stub(gitUtils, "runGitCommand") + .resolves(["dir/file.txt", "README.txt"].join(os.EOL)); + + await t.notThrowsAsync(async () => { + const result = await gitUtils.listFiles("/some/path"); + t.is(result.length, 2); + t.is(result[0], "dir/file.txt"); + }); +}); + +test("getGeneratedFiles returns generated files only", async (t) => { + const runGitCommandStub = sinon.stub(gitUtils, "runGitCommand"); + + runGitCommandStub + .onFirstCall() + .resolves(["dir/file.txt", "test.json", "README.txt"].join(os.EOL)); + runGitCommandStub + .onSecondCall() + .resolves( + [ + "dir/file.txt: linguist-generated: unspecified", + "test.json: linguist-generated: true", + "README.txt: linguist-generated: false", + ].join(os.EOL), + ); + + await t.notThrowsAsync(async () => { + const result = await gitUtils.getGeneratedFiles("/some/path"); + + t.assert(runGitCommandStub.calledTwice); + + t.is(result.length, 1); + t.is(result[0], "test.json"); + }); +}); diff --git a/src/git-utils.ts b/src/git-utils.ts index 8371240273..eb1151521c 100644 --- a/src/git-utils.ts +++ b/src/git-utils.ts @@ -1,3 +1,5 @@ +import * as os from "os"; + import * as core from "@actions/core"; import * as toolrunner from "@actions/exec/lib/toolrunner"; import * as io from "@actions/io"; @@ -408,3 +410,34 @@ export async function isAnalyzingDefaultBranch(): Promise { return currentRef === defaultBranch; } + +export async function listFiles(workingDirectory: string): Promise { + const stdout = await runGitCommand( + workingDirectory, + ["ls-files"], + "Unable to list tracked files.", + ); + return stdout.split(os.EOL); +} + +export async function getGeneratedFiles( + workingDirectory: string, +): Promise { + const files = await listFiles(workingDirectory); + const stdout = await runGitCommand( + workingDirectory, + ["check-attr", "linguist-generated", "--", ...files], + "Unable to check attributes of files.", + ); + + const generatedFiles: string[] = []; + const regex = /^([^:]+): linguist-generated: true$/; + for (const result of stdout.split(os.EOL)) { + const match = result.match(regex); + if (match) { + generatedFiles.push(match[1]); + } + } + + return generatedFiles; +} From 3eaf00092ba5fd106e6444a9fb14fc4795bbb2c1 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Wed, 19 Nov 2025 19:07:21 +0000 Subject: [PATCH 02/13] Add `isCCR` helper, and update `isDefaultSetup` --- src/actions-util.test.ts | 25 +++++++++++++++++++++++++ src/actions-util.ts | 13 ++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/actions-util.test.ts b/src/actions-util.test.ts index d8e7aa412b..f613a4ed72 100644 --- a/src/actions-util.test.ts +++ b/src/actions-util.test.ts @@ -5,6 +5,9 @@ import { fixCodeQualityCategory, getPullRequestBranches, isAnalyzingPullRequest, + isCCR, + isDefaultSetup, + isDynamicWorkflow, } from "./actions-util"; import { computeAutomationID } from "./api-client"; import { EnvVar } from "./environment"; @@ -246,3 +249,25 @@ test("fixCodeQualityCategory", (t) => { }, ); }); + +test("isDynamicWorkflow() returns true if event name is `dynamic`", (t) => { + process.env.GITHUB_EVENT_NAME = "dynamic"; + t.assert(isDynamicWorkflow()); + process.env.GITHUB_EVENT_NAME = "push"; + t.false(isDynamicWorkflow()); +}); + +test("isCCR() returns true when expected", (t) => { + process.env.GITHUB_EVENT_NAME = "dynamic"; + process.env.CODEQL_ACTION_ANALYSIS_KEY = + "dynamic/copilot-pull-request-reviewer"; + t.assert(isCCR()); + t.false(isDefaultSetup()); +}); + +test("isDefaultSetup() returns true when expected", (t) => { + process.env.GITHUB_EVENT_NAME = "dynamic"; + process.env.CODEQL_ACTION_ANALYSIS_KEY = "dynamic/github-code-scanning"; + t.assert(isDefaultSetup()); + t.false(isCCR()); +}); diff --git a/src/actions-util.ts b/src/actions-util.ts index a2d691b42d..2251bedd17 100644 --- a/src/actions-util.ts +++ b/src/actions-util.ts @@ -254,7 +254,18 @@ export function isDynamicWorkflow(): boolean { /** Determines whether we are running in default setup. */ export function isDefaultSetup(): boolean { - return isDynamicWorkflow(); + return isDynamicWorkflow() && !isCCR(); +} + +/** Determines whether we are running in CCR. */ +export function isCCR(): boolean { + return ( + (isDynamicWorkflow() && + process.env["CODEQL_ACTION_ANALYSIS_KEY"]?.startsWith( + "dynamic/copilot-pull-request-reviewer", + )) || + false + ); } export function prettyPrintInvocation(cmd: string, args: string[]): string { From 846f8590dcf58922d594b96c68f6351532c2c4af Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Wed, 19 Nov 2025 19:10:42 +0000 Subject: [PATCH 03/13] Add `IgnoreGeneratedFiles` FF --- lib/analyze-action-post.js | 5 +++++ lib/analyze-action.js | 12 +++++++++++- lib/autobuild-action.js | 5 +++++ lib/init-action-post.js | 12 +++++++++++- lib/init-action.js | 12 +++++++++++- lib/resolve-environment-action.js | 5 +++++ lib/setup-codeql-action.js | 5 +++++ lib/start-proxy-action-post.js | 5 +++++ lib/start-proxy-action.js | 5 +++++ lib/upload-lib.js | 12 +++++++++++- lib/upload-sarif-action-post.js | 5 +++++ lib/upload-sarif-action.js | 12 +++++++++++- src/feature-flags.ts | 6 ++++++ 13 files changed, 96 insertions(+), 5 deletions(-) diff --git a/lib/analyze-action-post.js b/lib/analyze-action-post.js index 706105a7f8..3a66120b33 100644 --- a/lib/analyze-action-post.js +++ b/lib/analyze-action-post.js @@ -120074,6 +120074,11 @@ var featureConfig = { legacyApi: true, minimumVersion: void 0 }, + ["ignore_generated_files" /* IgnoreGeneratedFiles */]: { + defaultValue: false, + envVar: "CODEQL_ACTION_IGNORE_GENERATED_FILES", + minimumVersion: void 0 + }, ["java_minimize_dependency_jars" /* JavaMinimizeDependencyJars */]: { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_MINIMIZE_DEPENDENCY_JARS", diff --git a/lib/analyze-action.js b/lib/analyze-action.js index 373b5bbcde..15875e4c1f 100644 --- a/lib/analyze-action.js +++ b/lib/analyze-action.js @@ -87570,7 +87570,12 @@ function isDynamicWorkflow() { return getWorkflowEventName() === "dynamic"; } function isDefaultSetup() { - return isDynamicWorkflow(); + return isDynamicWorkflow() && !isCCR(); +} +function isCCR() { + return isDynamicWorkflow() && process.env["CODEQL_ACTION_ANALYSIS_KEY"]?.startsWith( + "dynamic/copilot-pull-request-reviewer" + ) || false; } function prettyPrintInvocation(cmd, args) { return [cmd, ...args].map((x) => x.includes(" ") ? `'${x}'` : x).join(" "); @@ -88695,6 +88700,11 @@ var featureConfig = { legacyApi: true, minimumVersion: void 0 }, + ["ignore_generated_files" /* IgnoreGeneratedFiles */]: { + defaultValue: false, + envVar: "CODEQL_ACTION_IGNORE_GENERATED_FILES", + minimumVersion: void 0 + }, ["java_minimize_dependency_jars" /* JavaMinimizeDependencyJars */]: { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_MINIMIZE_DEPENDENCY_JARS", diff --git a/lib/autobuild-action.js b/lib/autobuild-action.js index abc46dd807..b174fb9dd2 100644 --- a/lib/autobuild-action.js +++ b/lib/autobuild-action.js @@ -84014,6 +84014,11 @@ var featureConfig = { legacyApi: true, minimumVersion: void 0 }, + ["ignore_generated_files" /* IgnoreGeneratedFiles */]: { + defaultValue: false, + envVar: "CODEQL_ACTION_IGNORE_GENERATED_FILES", + minimumVersion: void 0 + }, ["java_minimize_dependency_jars" /* JavaMinimizeDependencyJars */]: { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_MINIMIZE_DEPENDENCY_JARS", diff --git a/lib/init-action-post.js b/lib/init-action-post.js index 7e812f3921..b8b6bfa80a 100644 --- a/lib/init-action-post.js +++ b/lib/init-action-post.js @@ -122511,7 +122511,12 @@ function isDynamicWorkflow() { return getWorkflowEventName() === "dynamic"; } function isDefaultSetup() { - return isDynamicWorkflow(); + return isDynamicWorkflow() && !isCCR(); +} +function isCCR() { + return isDynamicWorkflow() && process.env["CODEQL_ACTION_ANALYSIS_KEY"]?.startsWith( + "dynamic/copilot-pull-request-reviewer" + ) || false; } function prettyPrintInvocation(cmd, args) { return [cmd, ...args].map((x) => x.includes(" ") ? `'${x}'` : x).join(" "); @@ -123455,6 +123460,11 @@ var featureConfig = { legacyApi: true, minimumVersion: void 0 }, + ["ignore_generated_files" /* IgnoreGeneratedFiles */]: { + defaultValue: false, + envVar: "CODEQL_ACTION_IGNORE_GENERATED_FILES", + minimumVersion: void 0 + }, ["java_minimize_dependency_jars" /* JavaMinimizeDependencyJars */]: { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_MINIMIZE_DEPENDENCY_JARS", diff --git a/lib/init-action.js b/lib/init-action.js index 50d2ebc15d..e79ca0a451 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -84914,7 +84914,12 @@ function isDynamicWorkflow() { return getWorkflowEventName() === "dynamic"; } function isDefaultSetup() { - return isDynamicWorkflow(); + return isDynamicWorkflow() && !isCCR(); +} +function isCCR() { + return isDynamicWorkflow() && process.env["CODEQL_ACTION_ANALYSIS_KEY"]?.startsWith( + "dynamic/copilot-pull-request-reviewer" + ) || false; } function prettyPrintInvocation(cmd, args) { return [cmd, ...args].map((x) => x.includes(" ") ? `'${x}'` : x).join(" "); @@ -86109,6 +86114,11 @@ var featureConfig = { legacyApi: true, minimumVersion: void 0 }, + ["ignore_generated_files" /* IgnoreGeneratedFiles */]: { + defaultValue: false, + envVar: "CODEQL_ACTION_IGNORE_GENERATED_FILES", + minimumVersion: void 0 + }, ["java_minimize_dependency_jars" /* JavaMinimizeDependencyJars */]: { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_MINIMIZE_DEPENDENCY_JARS", diff --git a/lib/resolve-environment-action.js b/lib/resolve-environment-action.js index 5c6dc080b6..1d38d97dc9 100644 --- a/lib/resolve-environment-action.js +++ b/lib/resolve-environment-action.js @@ -84005,6 +84005,11 @@ var featureConfig = { legacyApi: true, minimumVersion: void 0 }, + ["ignore_generated_files" /* IgnoreGeneratedFiles */]: { + defaultValue: false, + envVar: "CODEQL_ACTION_IGNORE_GENERATED_FILES", + minimumVersion: void 0 + }, ["java_minimize_dependency_jars" /* JavaMinimizeDependencyJars */]: { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_MINIMIZE_DEPENDENCY_JARS", diff --git a/lib/setup-codeql-action.js b/lib/setup-codeql-action.js index 6862c4bbe7..e2555417fc 100644 --- a/lib/setup-codeql-action.js +++ b/lib/setup-codeql-action.js @@ -83917,6 +83917,11 @@ var featureConfig = { legacyApi: true, minimumVersion: void 0 }, + ["ignore_generated_files" /* IgnoreGeneratedFiles */]: { + defaultValue: false, + envVar: "CODEQL_ACTION_IGNORE_GENERATED_FILES", + minimumVersion: void 0 + }, ["java_minimize_dependency_jars" /* JavaMinimizeDependencyJars */]: { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_MINIMIZE_DEPENDENCY_JARS", diff --git a/lib/start-proxy-action-post.js b/lib/start-proxy-action-post.js index 8bf22667b2..c4967ae073 100644 --- a/lib/start-proxy-action-post.js +++ b/lib/start-proxy-action-post.js @@ -119480,6 +119480,11 @@ var featureConfig = { legacyApi: true, minimumVersion: void 0 }, + ["ignore_generated_files" /* IgnoreGeneratedFiles */]: { + defaultValue: false, + envVar: "CODEQL_ACTION_IGNORE_GENERATED_FILES", + minimumVersion: void 0 + }, ["java_minimize_dependency_jars" /* JavaMinimizeDependencyJars */]: { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_MINIMIZE_DEPENDENCY_JARS", diff --git a/lib/start-proxy-action.js b/lib/start-proxy-action.js index 45a83e46e1..5762819ea4 100644 --- a/lib/start-proxy-action.js +++ b/lib/start-proxy-action.js @@ -100033,6 +100033,11 @@ var featureConfig = { legacyApi: true, minimumVersion: void 0 }, + ["ignore_generated_files" /* IgnoreGeneratedFiles */]: { + defaultValue: false, + envVar: "CODEQL_ACTION_IGNORE_GENERATED_FILES", + minimumVersion: void 0 + }, ["java_minimize_dependency_jars" /* JavaMinimizeDependencyJars */]: { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_MINIMIZE_DEPENDENCY_JARS", diff --git a/lib/upload-lib.js b/lib/upload-lib.js index 5cff5baa76..f42e02273b 100644 --- a/lib/upload-lib.js +++ b/lib/upload-lib.js @@ -86174,7 +86174,12 @@ function isDynamicWorkflow() { return getWorkflowEventName() === "dynamic"; } function isDefaultSetup() { - return isDynamicWorkflow(); + return isDynamicWorkflow() && !isCCR(); +} +function isCCR() { + return isDynamicWorkflow() && process.env["CODEQL_ACTION_ANALYSIS_KEY"]?.startsWith( + "dynamic/copilot-pull-request-reviewer" + ) || false; } function prettyPrintInvocation(cmd, args) { return [cmd, ...args].map((x) => x.includes(" ") ? `'${x}'` : x).join(" "); @@ -87071,6 +87076,11 @@ var featureConfig = { legacyApi: true, minimumVersion: void 0 }, + ["ignore_generated_files" /* IgnoreGeneratedFiles */]: { + defaultValue: false, + envVar: "CODEQL_ACTION_IGNORE_GENERATED_FILES", + minimumVersion: void 0 + }, ["java_minimize_dependency_jars" /* JavaMinimizeDependencyJars */]: { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_MINIMIZE_DEPENDENCY_JARS", diff --git a/lib/upload-sarif-action-post.js b/lib/upload-sarif-action-post.js index 4e25e2b828..95ca9f3555 100644 --- a/lib/upload-sarif-action-post.js +++ b/lib/upload-sarif-action-post.js @@ -119646,6 +119646,11 @@ var featureConfig = { legacyApi: true, minimumVersion: void 0 }, + ["ignore_generated_files" /* IgnoreGeneratedFiles */]: { + defaultValue: false, + envVar: "CODEQL_ACTION_IGNORE_GENERATED_FILES", + minimumVersion: void 0 + }, ["java_minimize_dependency_jars" /* JavaMinimizeDependencyJars */]: { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_MINIMIZE_DEPENDENCY_JARS", diff --git a/lib/upload-sarif-action.js b/lib/upload-sarif-action.js index 103e1255c0..eb6a2f4911 100644 --- a/lib/upload-sarif-action.js +++ b/lib/upload-sarif-action.js @@ -86204,7 +86204,12 @@ function isDynamicWorkflow() { return getWorkflowEventName() === "dynamic"; } function isDefaultSetup() { - return isDynamicWorkflow(); + return isDynamicWorkflow() && !isCCR(); +} +function isCCR() { + return isDynamicWorkflow() && process.env["CODEQL_ACTION_ANALYSIS_KEY"]?.startsWith( + "dynamic/copilot-pull-request-reviewer" + ) || false; } function prettyPrintInvocation(cmd, args) { return [cmd, ...args].map((x) => x.includes(" ") ? `'${x}'` : x).join(" "); @@ -86867,6 +86872,11 @@ var featureConfig = { legacyApi: true, minimumVersion: void 0 }, + ["ignore_generated_files" /* IgnoreGeneratedFiles */]: { + defaultValue: false, + envVar: "CODEQL_ACTION_IGNORE_GENERATED_FILES", + minimumVersion: void 0 + }, ["java_minimize_dependency_jars" /* JavaMinimizeDependencyJars */]: { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_MINIMIZE_DEPENDENCY_JARS", diff --git a/src/feature-flags.ts b/src/feature-flags.ts index 10e2e296c3..b1c6313e03 100644 --- a/src/feature-flags.ts +++ b/src/feature-flags.ts @@ -53,6 +53,7 @@ export enum Feature { DisableJavaBuildlessEnabled = "disable_java_buildless_enabled", DisableKotlinAnalysisEnabled = "disable_kotlin_analysis_enabled", ExportDiagnosticsEnabled = "export_diagnostics_enabled", + IgnoreGeneratedFiles = "ignore_generated_files", JavaMinimizeDependencyJars = "java_minimize_dependency_jars", OverlayAnalysis = "overlay_analysis", OverlayAnalysisActions = "overlay_analysis_actions", @@ -167,6 +168,11 @@ export const featureConfig: Record< legacyApi: true, minimumVersion: undefined, }, + [Feature.IgnoreGeneratedFiles]: { + defaultValue: false, + envVar: "CODEQL_ACTION_IGNORE_GENERATED_FILES", + minimumVersion: undefined, + }, [Feature.JavaMinimizeDependencyJars]: { defaultValue: false, envVar: "CODEQL_ACTION_JAVA_MINIMIZE_DEPENDENCY_JARS", From b4db38273c358b2f7c2fce18d1f0d79bf685eb3b Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Wed, 19 Nov 2025 19:20:54 +0000 Subject: [PATCH 04/13] Add generated files to `paths-ignore`, if FF is enabled --- lib/init-action.js | 121 ++++++++++++++++++++++++++++---------------- src/config-utils.ts | 26 +++++++++- 2 files changed, 102 insertions(+), 45 deletions(-) diff --git a/lib/init-action.js b/lib/init-action.js index e79ca0a451..43aca1aef2 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -98,11 +98,11 @@ var require_command = __commonJS({ }; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.issue = exports2.issueCommand = void 0; - var os5 = __importStar4(require("os")); + var os6 = __importStar4(require("os")); var utils_1 = require_utils(); function issueCommand(command, properties, message) { const cmd = new Command(command, properties, message); - process.stdout.write(cmd.toString() + os5.EOL); + process.stdout.write(cmd.toString() + os6.EOL); } exports2.issueCommand = issueCommand; function issue(name, message = "") { @@ -186,7 +186,7 @@ var require_file_command = __commonJS({ exports2.prepareKeyValueMessage = exports2.issueFileCommand = void 0; var crypto2 = __importStar4(require("crypto")); var fs15 = __importStar4(require("fs")); - var os5 = __importStar4(require("os")); + var os6 = __importStar4(require("os")); var utils_1 = require_utils(); function issueFileCommand(command, message) { const filePath = process.env[`GITHUB_${command}`]; @@ -196,7 +196,7 @@ var require_file_command = __commonJS({ if (!fs15.existsSync(filePath)) { throw new Error(`Missing file at path: ${filePath}`); } - fs15.appendFileSync(filePath, `${(0, utils_1.toCommandValue)(message)}${os5.EOL}`, { + fs15.appendFileSync(filePath, `${(0, utils_1.toCommandValue)(message)}${os6.EOL}`, { encoding: "utf8" }); } @@ -210,7 +210,7 @@ var require_file_command = __commonJS({ if (convertedValue.includes(delimiter)) { throw new Error(`Unexpected input: value should not contain the delimiter "${delimiter}"`); } - return `${key}<<${delimiter}${os5.EOL}${convertedValue}${os5.EOL}${delimiter}`; + return `${key}<<${delimiter}${os6.EOL}${convertedValue}${os6.EOL}${delimiter}`; } exports2.prepareKeyValueMessage = prepareKeyValueMessage; } @@ -18933,7 +18933,7 @@ var require_toolrunner = __commonJS({ }; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.argStringToArray = exports2.ToolRunner = void 0; - var os5 = __importStar4(require("os")); + var os6 = __importStar4(require("os")); var events = __importStar4(require("events")); var child = __importStar4(require("child_process")); var path16 = __importStar4(require("path")); @@ -18988,12 +18988,12 @@ var require_toolrunner = __commonJS({ _processLineBuffer(data, strBuffer, onLine) { try { let s = strBuffer + data.toString(); - let n = s.indexOf(os5.EOL); + let n = s.indexOf(os6.EOL); while (n > -1) { const line = s.substring(0, n); onLine(line); - s = s.substring(n + os5.EOL.length); - n = s.indexOf(os5.EOL); + s = s.substring(n + os6.EOL.length); + n = s.indexOf(os6.EOL); } return s; } catch (err) { @@ -19162,7 +19162,7 @@ var require_toolrunner = __commonJS({ } const optionsNonNull = this._cloneExecOptions(this.options); if (!optionsNonNull.silent && optionsNonNull.outStream) { - optionsNonNull.outStream.write(this._getCommandString(optionsNonNull) + os5.EOL); + optionsNonNull.outStream.write(this._getCommandString(optionsNonNull) + os6.EOL); } const state = new ExecState(optionsNonNull, this.toolPath); state.on("debug", (message) => { @@ -19650,7 +19650,7 @@ var require_core = __commonJS({ var command_1 = require_command(); var file_command_1 = require_file_command(); var utils_1 = require_utils(); - var os5 = __importStar4(require("os")); + var os6 = __importStar4(require("os")); var path16 = __importStar4(require("path")); var oidc_utils_1 = require_oidc_utils(); var ExitCode; @@ -19718,7 +19718,7 @@ Support boolean input list: \`true | True | TRUE | false | False | FALSE\``); if (filePath) { return (0, file_command_1.issueFileCommand)("OUTPUT", (0, file_command_1.prepareKeyValueMessage)(name, value)); } - process.stdout.write(os5.EOL); + process.stdout.write(os6.EOL); (0, command_1.issueCommand)("set-output", { name }, (0, utils_1.toCommandValue)(value)); } exports2.setOutput = setOutput2; @@ -19752,7 +19752,7 @@ Support boolean input list: \`true | True | TRUE | false | False | FALSE\``); } exports2.notice = notice; function info6(message) { - process.stdout.write(message + os5.EOL); + process.stdout.write(message + os6.EOL); } exports2.info = info6; function startGroup4(name) { @@ -31906,7 +31906,7 @@ var require_internal_pattern = __commonJS({ }; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.Pattern = void 0; - var os5 = __importStar4(require("os")); + var os6 = __importStar4(require("os")); var path16 = __importStar4(require("path")); var pathHelper = __importStar4(require_internal_path_helper()); var assert_1 = __importDefault4(require("assert")); @@ -31999,7 +31999,7 @@ var require_internal_pattern = __commonJS({ if (pattern === "." || pattern.startsWith(`.${path16.sep}`)) { pattern = _Pattern.globEscape(process.cwd()) + pattern.substr(1); } else if (pattern === "~" || pattern.startsWith(`~${path16.sep}`)) { - homedir2 = homedir2 || os5.homedir(); + homedir2 = homedir2 || os6.homedir(); assert_1.default(homedir2, "Unable to determine HOME directory"); assert_1.default(pathHelper.hasAbsoluteRoot(homedir2), `Expected HOME directory to be a rooted path. Actual '${homedir2}'`); pattern = _Pattern.globEscape(homedir2) + pattern.substr(1); @@ -35242,14 +35242,14 @@ var require_dist = __commonJS({ "node_modules/@azure/logger/dist/index.js"(exports2) { "use strict"; Object.defineProperty(exports2, "__esModule", { value: true }); - var os5 = require("os"); + var os6 = require("os"); var util = require("util"); function _interopDefaultLegacy(e) { return e && typeof e === "object" && "default" in e ? e : { "default": e }; } var util__default = /* @__PURE__ */ _interopDefaultLegacy(util); function log(message, ...args) { - process.stderr.write(`${util__default["default"].format(message, ...args)}${os5.EOL}`); + process.stderr.write(`${util__default["default"].format(message, ...args)}${os6.EOL}`); } var debugEnvVariable = typeof process !== "undefined" && process.env && process.env.DEBUG || void 0; var enabledString; @@ -36516,7 +36516,7 @@ var require_userAgentPlatform = __commonJS({ exports2.getHeaderName = getHeaderName; exports2.setPlatformSpecificData = setPlatformSpecificData; var tslib_1 = (init_tslib_es6(), __toCommonJS(tslib_es6_exports)); - var os5 = tslib_1.__importStar(require("node:os")); + var os6 = tslib_1.__importStar(require("node:os")); var process2 = tslib_1.__importStar(require("node:process")); function getHeaderName() { return "User-Agent"; @@ -36532,7 +36532,7 @@ var require_userAgentPlatform = __commonJS({ map2.set("Node", versions.node); } } - map2.set("OS", `(${os5.arch()}-${os5.type()}-${os5.release()})`); + map2.set("OS", `(${os6.arch()}-${os6.type()}-${os6.release()})`); } } }); @@ -37854,7 +37854,7 @@ var require_has_flag = __commonJS({ var require_supports_color = __commonJS({ "node_modules/supports-color/index.js"(exports2, module2) { "use strict"; - var os5 = require("os"); + var os6 = require("os"); var tty = require("tty"); var hasFlag = require_has_flag(); var { env } = process; @@ -37902,7 +37902,7 @@ var require_supports_color = __commonJS({ return min; } if (process.platform === "win32") { - const osRelease = os5.release().split("."); + const osRelease = os6.release().split("."); if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) { return Number(osRelease[2]) >= 14931 ? 3 : 2; } @@ -45124,11 +45124,11 @@ var require_XMLParser = __commonJS({ // node_modules/fast-xml-parser/src/xmlbuilder/orderedJs2Xml.js var require_orderedJs2Xml = __commonJS({ "node_modules/fast-xml-parser/src/xmlbuilder/orderedJs2Xml.js"(exports2, module2) { - var EOL = "\n"; + var EOL2 = "\n"; function toXml(jArray, options) { let indentation = ""; if (options.format && options.indentBy.length > 0) { - indentation = EOL; + indentation = EOL2; } return arrToStr(jArray, options, "", indentation); } @@ -77691,7 +77691,7 @@ var require_internal_pattern2 = __commonJS({ }; Object.defineProperty(exports2, "__esModule", { value: true }); exports2.Pattern = void 0; - var os5 = __importStar4(require("os")); + var os6 = __importStar4(require("os")); var path16 = __importStar4(require("path")); var pathHelper = __importStar4(require_internal_path_helper2()); var assert_1 = __importDefault4(require("assert")); @@ -77784,7 +77784,7 @@ var require_internal_pattern2 = __commonJS({ if (pattern === "." || pattern.startsWith(`.${path16.sep}`)) { pattern = _Pattern.globEscape(process.cwd()) + pattern.substr(1); } else if (pattern === "~" || pattern.startsWith(`~${path16.sep}`)) { - homedir2 = homedir2 || os5.homedir(); + homedir2 = homedir2 || os6.homedir(); (0, assert_1.default)(homedir2, "Unable to determine HOME directory"); (0, assert_1.default)(pathHelper.hasAbsoluteRoot(homedir2), `Expected HOME directory to be a rooted path. Actual '${homedir2}'`); pattern = _Pattern.globEscape(homedir2) + pattern.substr(1); @@ -78826,12 +78826,12 @@ var require_manifest = __commonJS({ exports2._readLinuxVersionFile = exports2._getOsVersion = exports2._findMatch = void 0; var semver9 = __importStar4(require_semver2()); var core_1 = require_core(); - var os5 = require("os"); + var os6 = require("os"); var cp = require("child_process"); var fs15 = require("fs"); function _findMatch(versionSpec, stable, candidates, archFilter) { return __awaiter4(this, void 0, void 0, function* () { - const platFilter = os5.platform(); + const platFilter = os6.platform(); let result; let match; let file; @@ -78868,7 +78868,7 @@ var require_manifest = __commonJS({ } exports2._findMatch = _findMatch; function _getOsVersion() { - const plat = os5.platform(); + const plat = os6.platform(); let version = ""; if (plat === "darwin") { version = cp.execSync("sw_vers -productVersion").toString(); @@ -79775,7 +79775,7 @@ var require_tool_cache = __commonJS({ var crypto2 = __importStar4(require("crypto")); var fs15 = __importStar4(require("fs")); var mm = __importStar4(require_manifest()); - var os5 = __importStar4(require("os")); + var os6 = __importStar4(require("os")); var path16 = __importStar4(require("path")); var httpm = __importStar4(require_lib5()); var semver9 = __importStar4(require_semver2()); @@ -80053,7 +80053,7 @@ var require_tool_cache = __commonJS({ function cacheDir(sourceDir, tool, version, arch2) { return __awaiter4(this, void 0, void 0, function* () { version = semver9.clean(version) || version; - arch2 = arch2 || os5.arch(); + arch2 = arch2 || os6.arch(); core14.debug(`Caching tool ${tool} ${version} ${arch2}`); core14.debug(`source dir: ${sourceDir}`); if (!fs15.statSync(sourceDir).isDirectory()) { @@ -80072,7 +80072,7 @@ var require_tool_cache = __commonJS({ function cacheFile(sourceFile, targetFile, tool, version, arch2) { return __awaiter4(this, void 0, void 0, function* () { version = semver9.clean(version) || version; - arch2 = arch2 || os5.arch(); + arch2 = arch2 || os6.arch(); core14.debug(`Caching tool ${tool} ${version} ${arch2}`); core14.debug(`source file: ${sourceFile}`); if (!fs15.statSync(sourceFile).isFile()) { @@ -80094,7 +80094,7 @@ var require_tool_cache = __commonJS({ if (!versionSpec) { throw new Error("versionSpec parameter is required"); } - arch2 = arch2 || os5.arch(); + arch2 = arch2 || os6.arch(); if (!isExplicitVersion(versionSpec)) { const localVersions = findAllVersions2(toolName, arch2); const match = evaluateVersions(localVersions, versionSpec); @@ -80117,7 +80117,7 @@ var require_tool_cache = __commonJS({ exports2.find = find2; function findAllVersions2(toolName, arch2) { const versions = []; - arch2 = arch2 || os5.arch(); + arch2 = arch2 || os6.arch(); const toolPath = path16.join(_getCacheDirectory(), toolName); if (fs15.existsSync(toolPath)) { const children = fs15.readdirSync(toolPath); @@ -80168,7 +80168,7 @@ var require_tool_cache = __commonJS({ }); } exports2.getManifestFromRepo = getManifestFromRepo; - function findFromManifest(versionSpec, stable, manifest, archFilter = os5.arch()) { + function findFromManifest(versionSpec, stable, manifest, archFilter = os6.arch()) { return __awaiter4(this, void 0, void 0, function* () { const match = yield mm._findMatch(versionSpec, stable, manifest, archFilter); return match; @@ -85652,6 +85652,7 @@ var path4 = __toESM(require("path")); var actionsCache = __toESM(require_cache3()); // src/git-utils.ts +var os2 = __toESM(require("os")); var core7 = __toESM(require_core()); var toolrunner2 = __toESM(require_toolrunner()); var io3 = __toESM(require_io2()); @@ -85825,6 +85826,31 @@ async function isAnalyzingDefaultBranch() { } return currentRef === defaultBranch; } +async function listFiles(workingDirectory) { + const stdout = await runGitCommand( + workingDirectory, + ["ls-files"], + "Unable to list tracked files." + ); + return stdout.split(os2.EOL); +} +async function getGeneratedFiles(workingDirectory) { + const files = await listFiles(workingDirectory); + const stdout = await runGitCommand( + workingDirectory, + ["check-attr", "linguist-generated", "--", ...files], + "Unable to check attributes of files." + ); + const generatedFiles = []; + const regex = /^([^:]+): linguist-generated: true$/; + for (const result of stdout.split(os2.EOL)) { + const match = result.match(regex); + if (match) { + generatedFiles.push(match[1]); + } + } + return generatedFiles; +} // src/logging.ts var core8 = __toESM(require_core()); @@ -87042,6 +87068,15 @@ async function initConfig(features, inputs) { ); } const config = await initActionState(inputs, userConfig); + if (await features.getValue("ignore_generated_files" /* IgnoreGeneratedFiles */) || isCCR()) { + try { + const generatedFiles = await getGeneratedFiles(inputs.sourceRoot); + config.computedConfig["paths-ignore"] ??= []; + config.computedConfig["paths-ignore"].push(...generatedFiles); + } catch (error3) { + logger.info(`Cannot ignore generated files: ${getErrorMessage(error3)}`); + } + } if (config.analysisKinds.length === 1 && isCodeQualityEnabled(config)) { if (hasQueryCustomisation(config.computedConfig)) { throw new ConfigurationError( @@ -87264,7 +87299,7 @@ function isCodeQualityEnabled(config) { } // src/dependency-caching.ts -var os2 = __toESM(require("os")); +var os3 = __toESM(require("os")); var import_path = require("path"); var actionsCache3 = __toESM(require_cache3()); var glob = __toESM(require_glob2()); @@ -87276,9 +87311,9 @@ function getJavaTempDependencyDir() { function getJavaDependencyDirs() { return [ // Maven - (0, import_path.join)(os2.homedir(), ".m2", "repository"), + (0, import_path.join)(os3.homedir(), ".m2", "repository"), // Gradle - (0, import_path.join)(os2.homedir(), ".gradle", "caches"), + (0, import_path.join)(os3.homedir(), ".gradle", "caches"), // CodeQL Java build-mode: none getJavaTempDependencyDir() ]; @@ -87327,11 +87362,11 @@ var defaultCacheConfigs = { ]) }, csharp: { - getDependencyPaths: () => [(0, import_path.join)(os2.homedir(), ".nuget", "packages")], + getDependencyPaths: () => [(0, import_path.join)(os3.homedir(), ".nuget", "packages")], getHashPatterns: getCsharpHashPatterns }, go: { - getDependencyPaths: () => [(0, import_path.join)(os2.homedir(), "go", "pkg", "mod")], + getDependencyPaths: () => [(0, import_path.join)(os3.homedir(), "go", "pkg", "mod")], getHashPatterns: async () => internal.makePatternCheck(["**/go.sum"]) } }; @@ -87936,7 +87971,7 @@ function inferCompressionMethod(tarPath) { // src/tools-download.ts var fs8 = __toESM(require("fs")); -var os3 = __toESM(require("os")); +var os4 = __toESM(require("os")); var path9 = __toESM(require("path")); var import_perf_hooks2 = require("perf_hooks"); var core9 = __toESM(require_core()); @@ -88074,7 +88109,7 @@ function getToolcacheDirectory(version) { getRequiredEnvParam("RUNNER_TOOL_CACHE"), TOOLCACHE_TOOL_NAME, semver6.clean(version) || version, - os3.arch() || "" + os4.arch() || "" ); } function writeToolcacheMarkerFile(extractedPath, logger) { @@ -89412,7 +89447,7 @@ function cleanupDatabaseClusterDirectory(config, logger, options = {}, rmSync2 = } // src/status-report.ts -var os4 = __toESM(require("os")); +var os5 = __toESM(require("os")); var core11 = __toESM(require_core()); function isFirstPartyAnalysis(actionName) { if (actionName !== "upload-sarif" /* UploadSarif */) { @@ -89516,7 +89551,7 @@ async function createStatusReportBase(actionName, status, actionStartedAt, confi statusReport.runner_arch = process.env["RUNNER_ARCH"]; } if (!(runnerOs === "Linux" && isSelfHostedRunner())) { - statusReport.runner_os_release = os4.release(); + statusReport.runner_os_release = os5.release(); } if (codeQlCliVersion !== void 0) { statusReport.codeql_version = codeQlCliVersion.version; diff --git a/src/config-utils.ts b/src/config-utils.ts index cbfcb3b955..34382058fc 100644 --- a/src/config-utils.ts +++ b/src/config-utils.ts @@ -4,7 +4,11 @@ import { performance } from "perf_hooks"; import * as yaml from "js-yaml"; -import { getActionVersion, isAnalyzingPullRequest } from "./actions-util"; +import { + getActionVersion, + isAnalyzingPullRequest, + isCCR, +} from "./actions-util"; import { AnalysisConfig, AnalysisKind, @@ -26,7 +30,11 @@ import { shouldPerformDiffInformedAnalysis } from "./diff-informed-analysis-util import * as errorMessages from "./error-messages"; import { Feature, FeatureEnablement } from "./feature-flags"; import { RepositoryProperties } from "./feature-flags/properties"; -import { getGitRoot, isAnalyzingDefaultBranch } from "./git-utils"; +import { + getGeneratedFiles, + getGitRoot, + isAnalyzingDefaultBranch, +} from "./git-utils"; import { KnownLanguage, Language } from "./languages"; import { Logger } from "./logging"; import { @@ -44,6 +52,7 @@ import { cloneObject, isDefined, checkDiskUsage, + getErrorMessage, } from "./util"; export * from "./config/db-config"; @@ -845,6 +854,19 @@ export async function initConfig( const config = await initActionState(inputs, userConfig); + // If we are in CCR or the corresponding FF is enabled, try to determine + // which files in the repository are marked as generated and add them to + // the `paths-ignore` configuration. + if ((await features.getValue(Feature.IgnoreGeneratedFiles)) || isCCR()) { + try { + const generatedFiles = await getGeneratedFiles(inputs.sourceRoot); + config.computedConfig["paths-ignore"] ??= []; + config.computedConfig["paths-ignore"].push(...generatedFiles); + } catch (error) { + logger.info(`Cannot ignore generated files: ${getErrorMessage(error)}`); + } + } + // If Code Quality analysis is the only enabled analysis kind, then we will initialise // the database for Code Quality. That entails disabling the default queries and only // running quality queries. We do not currently support query customisations in that case. From 02b2c55c513594f8e6c07cca8da9ba7c3f1aac47 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Mon, 19 Jan 2026 13:18:48 +0000 Subject: [PATCH 05/13] Use `stdin` for files to query attributes of --- lib/analyze-action-post.js | 5 +++-- lib/analyze-action.js | 5 +++-- lib/autobuild-action.js | 5 +++-- lib/init-action-post.js | 5 +++-- lib/init-action.js | 10 ++++++---- lib/resolve-environment-action.js | 5 +++-- lib/setup-codeql-action.js | 5 +++-- lib/start-proxy-action.js | 5 +++-- lib/upload-lib.js | 5 +++-- lib/upload-sarif-action.js | 5 +++-- src/git-utils.ts | 6 +++++- 11 files changed, 38 insertions(+), 23 deletions(-) diff --git a/lib/analyze-action-post.js b/lib/analyze-action-post.js index e8715799ae..0ec7fed163 100644 --- a/lib/analyze-action-post.js +++ b/lib/analyze-action-post.js @@ -124002,7 +124002,7 @@ var core8 = __toESM(require_core()); var toolrunner2 = __toESM(require_toolrunner()); var io3 = __toESM(require_io()); var semver3 = __toESM(require_semver2()); -var runGitCommand = async function(workingDirectory, args, customErrorMessage) { +var runGitCommand = async function(workingDirectory, args, customErrorMessage, options) { let stdout = ""; let stderr = ""; core8.debug(`Running git command: git ${args.join(" ")}`); @@ -124017,7 +124017,8 @@ var runGitCommand = async function(workingDirectory, args, customErrorMessage) { stderr += data.toString(); } }, - cwd: workingDirectory + cwd: workingDirectory, + ...options }).exec(); return stdout; } catch (error3) { diff --git a/lib/analyze-action.js b/lib/analyze-action.js index 83ca07495c..5193a04153 100644 --- a/lib/analyze-action.js +++ b/lib/analyze-action.js @@ -91345,7 +91345,7 @@ var core8 = __toESM(require_core()); var toolrunner2 = __toESM(require_toolrunner()); var io3 = __toESM(require_io()); var semver3 = __toESM(require_semver2()); -var runGitCommand = async function(workingDirectory, args, customErrorMessage) { +var runGitCommand = async function(workingDirectory, args, customErrorMessage, options) { let stdout = ""; let stderr = ""; core8.debug(`Running git command: git ${args.join(" ")}`); @@ -91360,7 +91360,8 @@ var runGitCommand = async function(workingDirectory, args, customErrorMessage) { stderr += data.toString(); } }, - cwd: workingDirectory + cwd: workingDirectory, + ...options }).exec(); return stdout; } catch (error3) { diff --git a/lib/autobuild-action.js b/lib/autobuild-action.js index df5eff5916..da48d5f358 100644 --- a/lib/autobuild-action.js +++ b/lib/autobuild-action.js @@ -87861,7 +87861,7 @@ var core8 = __toESM(require_core()); var toolrunner2 = __toESM(require_toolrunner()); var io3 = __toESM(require_io()); var semver3 = __toESM(require_semver2()); -var runGitCommand = async function(workingDirectory, args, customErrorMessage) { +var runGitCommand = async function(workingDirectory, args, customErrorMessage, options) { let stdout = ""; let stderr = ""; core8.debug(`Running git command: git ${args.join(" ")}`); @@ -87876,7 +87876,8 @@ var runGitCommand = async function(workingDirectory, args, customErrorMessage) { stderr += data.toString(); } }, - cwd: workingDirectory + cwd: workingDirectory, + ...options }).exec(); return stdout; } catch (error3) { diff --git a/lib/init-action-post.js b/lib/init-action-post.js index 1f3e161d79..38418b1beb 100644 --- a/lib/init-action-post.js +++ b/lib/init-action-post.js @@ -127348,7 +127348,7 @@ var core8 = __toESM(require_core()); var toolrunner2 = __toESM(require_toolrunner()); var io3 = __toESM(require_io()); var semver3 = __toESM(require_semver2()); -var runGitCommand = async function(workingDirectory, args, customErrorMessage) { +var runGitCommand = async function(workingDirectory, args, customErrorMessage, options) { let stdout = ""; let stderr = ""; core8.debug(`Running git command: git ${args.join(" ")}`); @@ -127363,7 +127363,8 @@ var runGitCommand = async function(workingDirectory, args, customErrorMessage) { stderr += data.toString(); } }, - cwd: workingDirectory + cwd: workingDirectory, + ...options }).exec(); return stdout; } catch (error3) { diff --git a/lib/init-action.js b/lib/init-action.js index d9c327132e..6c746de708 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -88829,7 +88829,7 @@ async function getGitVersionOrThrow() { } throw new Error(`Could not parse Git version from output: ${stdout.trim()}`); } -var runGitCommand = async function(workingDirectory, args, customErrorMessage) { +var runGitCommand = async function(workingDirectory, args, customErrorMessage, options) { let stdout = ""; let stderr = ""; core8.debug(`Running git command: git ${args.join(" ")}`); @@ -88844,7 +88844,8 @@ var runGitCommand = async function(workingDirectory, args, customErrorMessage) { stderr += data.toString(); } }, - cwd: workingDirectory + cwd: workingDirectory, + ...options }).exec(); return stdout; } catch (error3) { @@ -89011,8 +89012,9 @@ async function getGeneratedFiles(workingDirectory) { const files = await listFiles(workingDirectory); const stdout = await runGitCommand( workingDirectory, - ["check-attr", "linguist-generated", "--", ...files], - "Unable to check attributes of files." + ["check-attr", "linguist-generated", "--stdin"], + "Unable to check attributes of files.", + { input: Buffer.from(files.join(" ")) } ); const generatedFiles = []; const regex = /^([^:]+): linguist-generated: true$/; diff --git a/lib/resolve-environment-action.js b/lib/resolve-environment-action.js index 8649365643..e17805fbe4 100644 --- a/lib/resolve-environment-action.js +++ b/lib/resolve-environment-action.js @@ -87854,7 +87854,7 @@ var core8 = __toESM(require_core()); var toolrunner2 = __toESM(require_toolrunner()); var io3 = __toESM(require_io()); var semver3 = __toESM(require_semver2()); -var runGitCommand = async function(workingDirectory, args, customErrorMessage) { +var runGitCommand = async function(workingDirectory, args, customErrorMessage, options) { let stdout = ""; let stderr = ""; core8.debug(`Running git command: git ${args.join(" ")}`); @@ -87869,7 +87869,8 @@ var runGitCommand = async function(workingDirectory, args, customErrorMessage) { stderr += data.toString(); } }, - cwd: workingDirectory + cwd: workingDirectory, + ...options }).exec(); return stdout; } catch (error3) { diff --git a/lib/setup-codeql-action.js b/lib/setup-codeql-action.js index 14955d0424..4dcf88da48 100644 --- a/lib/setup-codeql-action.js +++ b/lib/setup-codeql-action.js @@ -87738,7 +87738,7 @@ var core7 = __toESM(require_core()); var toolrunner2 = __toESM(require_toolrunner()); var io3 = __toESM(require_io()); var semver2 = __toESM(require_semver2()); -var runGitCommand = async function(workingDirectory, args, customErrorMessage) { +var runGitCommand = async function(workingDirectory, args, customErrorMessage, options) { let stdout = ""; let stderr = ""; core7.debug(`Running git command: git ${args.join(" ")}`); @@ -87753,7 +87753,8 @@ var runGitCommand = async function(workingDirectory, args, customErrorMessage) { stderr += data.toString(); } }, - cwd: workingDirectory + cwd: workingDirectory, + ...options }).exec(); return stdout; } catch (error3) { diff --git a/lib/start-proxy-action.js b/lib/start-proxy-action.js index 8d87490fdd..d159e3252d 100644 --- a/lib/start-proxy-action.js +++ b/lib/start-proxy-action.js @@ -104812,7 +104812,7 @@ var core9 = __toESM(require_core()); var toolrunner2 = __toESM(require_toolrunner()); var io3 = __toESM(require_io()); var semver3 = __toESM(require_semver2()); -var runGitCommand = async function(workingDirectory, args, customErrorMessage) { +var runGitCommand = async function(workingDirectory, args, customErrorMessage, options) { let stdout = ""; let stderr = ""; core9.debug(`Running git command: git ${args.join(" ")}`); @@ -104827,7 +104827,8 @@ var runGitCommand = async function(workingDirectory, args, customErrorMessage) { stderr += data.toString(); } }, - cwd: workingDirectory + cwd: workingDirectory, + ...options }).exec(); return stdout; } catch (error3) { diff --git a/lib/upload-lib.js b/lib/upload-lib.js index c6f1e860d3..8f926183db 100644 --- a/lib/upload-lib.js +++ b/lib/upload-lib.js @@ -90889,7 +90889,7 @@ var core8 = __toESM(require_core()); var toolrunner2 = __toESM(require_toolrunner()); var io3 = __toESM(require_io()); var semver3 = __toESM(require_semver2()); -var runGitCommand = async function(workingDirectory, args, customErrorMessage) { +var runGitCommand = async function(workingDirectory, args, customErrorMessage, options) { let stdout = ""; let stderr = ""; core8.debug(`Running git command: git ${args.join(" ")}`); @@ -90904,7 +90904,8 @@ var runGitCommand = async function(workingDirectory, args, customErrorMessage) { stderr += data.toString(); } }, - cwd: workingDirectory + cwd: workingDirectory, + ...options }).exec(); return stdout; } catch (error3) { diff --git a/lib/upload-sarif-action.js b/lib/upload-sarif-action.js index 420a2a6be4..ee32a9e3ea 100644 --- a/lib/upload-sarif-action.js +++ b/lib/upload-sarif-action.js @@ -90659,7 +90659,7 @@ var core7 = __toESM(require_core()); var toolrunner2 = __toESM(require_toolrunner()); var io3 = __toESM(require_io()); var semver2 = __toESM(require_semver2()); -var runGitCommand = async function(workingDirectory, args, customErrorMessage) { +var runGitCommand = async function(workingDirectory, args, customErrorMessage, options) { let stdout = ""; let stderr = ""; core7.debug(`Running git command: git ${args.join(" ")}`); @@ -90674,7 +90674,8 @@ var runGitCommand = async function(workingDirectory, args, customErrorMessage) { stderr += data.toString(); } }, - cwd: workingDirectory + cwd: workingDirectory, + ...options }).exec(); return stdout; } catch (error3) { diff --git a/src/git-utils.ts b/src/git-utils.ts index e16a95b379..1271ba8689 100644 --- a/src/git-utils.ts +++ b/src/git-utils.ts @@ -1,6 +1,7 @@ import * as os from "os"; import * as core from "@actions/core"; +import { ExecOptions } from "@actions/exec"; import * as toolrunner from "@actions/exec/lib/toolrunner"; import * as io from "@actions/io"; import * as semver from "semver"; @@ -62,6 +63,7 @@ export const runGitCommand = async function ( workingDirectory: string | undefined, args: string[], customErrorMessage: string, + options?: ExecOptions, ): Promise { let stdout = ""; let stderr = ""; @@ -78,6 +80,7 @@ export const runGitCommand = async function ( }, }, cwd: workingDirectory, + ...options, }).exec(); return stdout; } catch (error) { @@ -412,8 +415,9 @@ export async function getGeneratedFiles( const files = await listFiles(workingDirectory); const stdout = await runGitCommand( workingDirectory, - ["check-attr", "linguist-generated", "--", ...files], + ["check-attr", "linguist-generated", "--stdin"], "Unable to check attributes of files.", + { input: Buffer.from(files.join(" ")) }, ); const generatedFiles: string[] = []; From 644e2b9bd7d75884a05728138f2408a55aa8c691 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Mon, 19 Jan 2026 13:19:48 +0000 Subject: [PATCH 06/13] Restore condition for enablement --- lib/init-action.js | 2 +- src/config-utils.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/init-action.js b/lib/init-action.js index 6c746de708..58b85aa984 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -90262,7 +90262,7 @@ async function initConfig(features, inputs) { ); } const config = await initActionState(inputs, userConfig); - if (await features.getValue("ignore_generated_files" /* IgnoreGeneratedFiles */) || isCCR()) { + if (await features.getValue("ignore_generated_files" /* IgnoreGeneratedFiles */) && isCCR()) { try { const generatedFiles = await getGeneratedFiles(inputs.sourceRoot); config.computedConfig["paths-ignore"] ??= []; diff --git a/src/config-utils.ts b/src/config-utils.ts index a659c32315..5fb169b9b7 100644 --- a/src/config-utils.ts +++ b/src/config-utils.ts @@ -919,7 +919,7 @@ export async function initConfig( // If we are in CCR or the corresponding FF is enabled, try to determine // which files in the repository are marked as generated and add them to // the `paths-ignore` configuration. - if ((await features.getValue(Feature.IgnoreGeneratedFiles)) || isCCR()) { + if ((await features.getValue(Feature.IgnoreGeneratedFiles)) && isCCR()) { try { const generatedFiles = await getGeneratedFiles(inputs.sourceRoot); config.computedConfig["paths-ignore"] ??= []; From 055e6b6f363c1e073ebc82a2f590a00502b21657 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Mon, 19 Jan 2026 13:41:38 +0000 Subject: [PATCH 07/13] Add `EnvVar` constant for analysis key --- lib/analyze-action.js | 4 ++-- lib/autobuild-action.js | 2 +- lib/init-action-post.js | 4 ++-- lib/init-action.js | 4 ++-- lib/resolve-environment-action.js | 2 +- lib/setup-codeql-action.js | 2 +- lib/start-proxy-action.js | 2 +- lib/upload-lib.js | 4 ++-- lib/upload-sarif-action.js | 4 ++-- src/actions-util.test.ts | 5 ++--- src/actions-util.ts | 3 ++- src/api-client.ts | 3 ++- src/environment.ts | 6 ++++++ src/status-report.test.ts | 2 +- 14 files changed, 27 insertions(+), 20 deletions(-) diff --git a/lib/analyze-action.js b/lib/analyze-action.js index 5193a04153..3f06a642bd 100644 --- a/lib/analyze-action.js +++ b/lib/analyze-action.js @@ -90606,7 +90606,7 @@ function isDefaultSetup() { return isDynamicWorkflow() && !isCCR(); } function isCCR() { - return isDynamicWorkflow() && process.env["CODEQL_ACTION_ANALYSIS_KEY"]?.startsWith( + return isDynamicWorkflow() && process.env["CODEQL_ACTION_ANALYSIS_KEY" /* ANALYSIS_KEY */]?.startsWith( "dynamic/copilot-pull-request-reviewer" ) || false; } @@ -90876,7 +90876,7 @@ async function getWorkflowRelativePath() { return workflowResponse.data.path; } async function getAnalysisKey() { - const analysisKeyEnvVar = "CODEQL_ACTION_ANALYSIS_KEY"; + const analysisKeyEnvVar = "CODEQL_ACTION_ANALYSIS_KEY" /* ANALYSIS_KEY */; let analysisKey = process.env[analysisKeyEnvVar]; if (analysisKey !== void 0) { return analysisKey; diff --git a/lib/autobuild-action.js b/lib/autobuild-action.js index da48d5f358..65cf1c8239 100644 --- a/lib/autobuild-action.js +++ b/lib/autobuild-action.js @@ -87542,7 +87542,7 @@ async function getWorkflowRelativePath() { return workflowResponse.data.path; } async function getAnalysisKey() { - const analysisKeyEnvVar = "CODEQL_ACTION_ANALYSIS_KEY"; + const analysisKeyEnvVar = "CODEQL_ACTION_ANALYSIS_KEY" /* ANALYSIS_KEY */; let analysisKey = process.env[analysisKeyEnvVar]; if (analysisKey !== void 0) { return analysisKey; diff --git a/lib/init-action-post.js b/lib/init-action-post.js index 38418b1beb..3799a34ceb 100644 --- a/lib/init-action-post.js +++ b/lib/init-action-post.js @@ -126724,7 +126724,7 @@ function isDefaultSetup() { return isDynamicWorkflow() && !isCCR(); } function isCCR() { - return isDynamicWorkflow() && process.env["CODEQL_ACTION_ANALYSIS_KEY"]?.startsWith( + return isDynamicWorkflow() && process.env["CODEQL_ACTION_ANALYSIS_KEY" /* ANALYSIS_KEY */]?.startsWith( "dynamic/copilot-pull-request-reviewer" ) || false; } @@ -126928,7 +126928,7 @@ async function getWorkflowRelativePath() { return workflowResponse.data.path; } async function getAnalysisKey() { - const analysisKeyEnvVar = "CODEQL_ACTION_ANALYSIS_KEY"; + const analysisKeyEnvVar = "CODEQL_ACTION_ANALYSIS_KEY" /* ANALYSIS_KEY */; let analysisKey = process.env[analysisKeyEnvVar]; if (analysisKey !== void 0) { return analysisKey; diff --git a/lib/init-action.js b/lib/init-action.js index 58b85aa984..35972710a4 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -87955,7 +87955,7 @@ function isDefaultSetup() { return isDynamicWorkflow() && !isCCR(); } function isCCR() { - return isDynamicWorkflow() && process.env["CODEQL_ACTION_ANALYSIS_KEY"]?.startsWith( + return isDynamicWorkflow() && process.env["CODEQL_ACTION_ANALYSIS_KEY" /* ANALYSIS_KEY */]?.startsWith( "dynamic/copilot-pull-request-reviewer" ) || false; } @@ -88206,7 +88206,7 @@ async function getWorkflowRelativePath() { return workflowResponse.data.path; } async function getAnalysisKey() { - const analysisKeyEnvVar = "CODEQL_ACTION_ANALYSIS_KEY"; + const analysisKeyEnvVar = "CODEQL_ACTION_ANALYSIS_KEY" /* ANALYSIS_KEY */; let analysisKey = process.env[analysisKeyEnvVar]; if (analysisKey !== void 0) { return analysisKey; diff --git a/lib/resolve-environment-action.js b/lib/resolve-environment-action.js index e17805fbe4..14453cb818 100644 --- a/lib/resolve-environment-action.js +++ b/lib/resolve-environment-action.js @@ -87550,7 +87550,7 @@ async function getWorkflowRelativePath() { return workflowResponse.data.path; } async function getAnalysisKey() { - const analysisKeyEnvVar = "CODEQL_ACTION_ANALYSIS_KEY"; + const analysisKeyEnvVar = "CODEQL_ACTION_ANALYSIS_KEY" /* ANALYSIS_KEY */; let analysisKey = process.env[analysisKeyEnvVar]; if (analysisKey !== void 0) { return analysisKey; diff --git a/lib/setup-codeql-action.js b/lib/setup-codeql-action.js index 4dcf88da48..0a8e20cef7 100644 --- a/lib/setup-codeql-action.js +++ b/lib/setup-codeql-action.js @@ -87667,7 +87667,7 @@ async function getWorkflowRelativePath() { return workflowResponse.data.path; } async function getAnalysisKey() { - const analysisKeyEnvVar = "CODEQL_ACTION_ANALYSIS_KEY"; + const analysisKeyEnvVar = "CODEQL_ACTION_ANALYSIS_KEY" /* ANALYSIS_KEY */; let analysisKey = process.env[analysisKeyEnvVar]; if (analysisKey !== void 0) { return analysisKey; diff --git a/lib/start-proxy-action.js b/lib/start-proxy-action.js index d159e3252d..4ae2ce28af 100644 --- a/lib/start-proxy-action.js +++ b/lib/start-proxy-action.js @@ -104587,7 +104587,7 @@ async function getWorkflowRelativePath() { return workflowResponse.data.path; } async function getAnalysisKey() { - const analysisKeyEnvVar = "CODEQL_ACTION_ANALYSIS_KEY"; + const analysisKeyEnvVar = "CODEQL_ACTION_ANALYSIS_KEY" /* ANALYSIS_KEY */; let analysisKey = process.env[analysisKeyEnvVar]; if (analysisKey !== void 0) { return analysisKey; diff --git a/lib/upload-lib.js b/lib/upload-lib.js index 8f926183db..009a82d3a2 100644 --- a/lib/upload-lib.js +++ b/lib/upload-lib.js @@ -90306,7 +90306,7 @@ function isDefaultSetup() { return isDynamicWorkflow() && !isCCR(); } function isCCR() { - return isDynamicWorkflow() && process.env["CODEQL_ACTION_ANALYSIS_KEY"]?.startsWith( + return isDynamicWorkflow() && process.env["CODEQL_ACTION_ANALYSIS_KEY" /* ANALYSIS_KEY */]?.startsWith( "dynamic/copilot-pull-request-reviewer" ) || false; } @@ -90528,7 +90528,7 @@ async function getWorkflowRelativePath() { return workflowResponse.data.path; } async function getAnalysisKey() { - const analysisKeyEnvVar = "CODEQL_ACTION_ANALYSIS_KEY"; + const analysisKeyEnvVar = "CODEQL_ACTION_ANALYSIS_KEY" /* ANALYSIS_KEY */; let analysisKey = process.env[analysisKeyEnvVar]; if (analysisKey !== void 0) { return analysisKey; diff --git a/lib/upload-sarif-action.js b/lib/upload-sarif-action.js index ee32a9e3ea..9433fb57ae 100644 --- a/lib/upload-sarif-action.js +++ b/lib/upload-sarif-action.js @@ -90337,7 +90337,7 @@ function isDefaultSetup() { return isDynamicWorkflow() && !isCCR(); } function isCCR() { - return isDynamicWorkflow() && process.env["CODEQL_ACTION_ANALYSIS_KEY"]?.startsWith( + return isDynamicWorkflow() && process.env["CODEQL_ACTION_ANALYSIS_KEY" /* ANALYSIS_KEY */]?.startsWith( "dynamic/copilot-pull-request-reviewer" ) || false; } @@ -90574,7 +90574,7 @@ async function getWorkflowRelativePath() { return workflowResponse.data.path; } async function getAnalysisKey() { - const analysisKeyEnvVar = "CODEQL_ACTION_ANALYSIS_KEY"; + const analysisKeyEnvVar = "CODEQL_ACTION_ANALYSIS_KEY" /* ANALYSIS_KEY */; let analysisKey = process.env[analysisKeyEnvVar]; if (analysisKey !== void 0) { return analysisKey; diff --git a/src/actions-util.test.ts b/src/actions-util.test.ts index f613a4ed72..71a409da6d 100644 --- a/src/actions-util.test.ts +++ b/src/actions-util.test.ts @@ -259,15 +259,14 @@ test("isDynamicWorkflow() returns true if event name is `dynamic`", (t) => { test("isCCR() returns true when expected", (t) => { process.env.GITHUB_EVENT_NAME = "dynamic"; - process.env.CODEQL_ACTION_ANALYSIS_KEY = - "dynamic/copilot-pull-request-reviewer"; + process.env[EnvVar.ANALYSIS_KEY] = "dynamic/copilot-pull-request-reviewer"; t.assert(isCCR()); t.false(isDefaultSetup()); }); test("isDefaultSetup() returns true when expected", (t) => { process.env.GITHUB_EVENT_NAME = "dynamic"; - process.env.CODEQL_ACTION_ANALYSIS_KEY = "dynamic/github-code-scanning"; + process.env[EnvVar.ANALYSIS_KEY] = "dynamic/github-code-scanning"; t.assert(isDefaultSetup()); t.false(isCCR()); }); diff --git a/src/actions-util.ts b/src/actions-util.ts index 550d4a0353..b26ee2b1ff 100644 --- a/src/actions-util.ts +++ b/src/actions-util.ts @@ -8,6 +8,7 @@ import * as io from "@actions/io"; import { JSONSchemaForNPMPackageJsonFiles } from "@schemastore/package"; import type { Config } from "./config-utils"; +import { EnvVar } from "./environment"; import { Logger } from "./logging"; import { doesDirectoryExist, @@ -261,7 +262,7 @@ export function isDefaultSetup(): boolean { export function isCCR(): boolean { return ( (isDynamicWorkflow() && - process.env["CODEQL_ACTION_ANALYSIS_KEY"]?.startsWith( + process.env[EnvVar.ANALYSIS_KEY]?.startsWith( "dynamic/copilot-pull-request-reviewer", )) || false diff --git a/src/api-client.ts b/src/api-client.ts index 32a6a080b7..2f558d4582 100644 --- a/src/api-client.ts +++ b/src/api-client.ts @@ -3,6 +3,7 @@ import * as githubUtils from "@actions/github/lib/utils"; import * as retry from "@octokit/plugin-retry"; import { getActionVersion, getRequiredInput } from "./actions-util"; +import { EnvVar } from "./environment"; import { Logger } from "./logging"; import { getRepositoryNwo, RepositoryNwo } from "./repository"; import { @@ -189,7 +190,7 @@ export async function getWorkflowRelativePath(): Promise { * the GitHub API, but after that the result will be cached. */ export async function getAnalysisKey(): Promise { - const analysisKeyEnvVar = "CODEQL_ACTION_ANALYSIS_KEY"; + const analysisKeyEnvVar = EnvVar.ANALYSIS_KEY; let analysisKey = process.env[analysisKeyEnvVar]; if (analysisKey !== undefined) { diff --git a/src/environment.ts b/src/environment.ts index 16617c647b..4d7b44c808 100644 --- a/src/environment.ts +++ b/src/environment.ts @@ -135,4 +135,10 @@ export enum EnvVar { * Intended for use in environments where git may not be installed, such as Docker containers. */ TOLERATE_MISSING_GIT_VERSION = "CODEQL_ACTION_TOLERATE_MISSING_GIT_VERSION", + + /** + * Used to store the analysis key used by the CodeQL Action. This is normally populated by + * `getAnalysisKey`, but can also be set manually for testing and non-standard applications. + */ + ANALYSIS_KEY = "CODEQL_ACTION_ANALYSIS_KEY", } diff --git a/src/status-report.test.ts b/src/status-report.test.ts index 8421dcceef..e051c54a27 100644 --- a/src/status-report.test.ts +++ b/src/status-report.test.ts @@ -27,7 +27,7 @@ setupTests(test); function setupEnvironmentAndStub(tmpDir: string) { setupActionsVars(tmpDir, tmpDir); - process.env["CODEQL_ACTION_ANALYSIS_KEY"] = "analysis-key"; + process.env[EnvVar.ANALYSIS_KEY] = "analysis-key"; process.env["GITHUB_EVENT_NAME"] = "dynamic"; process.env["GITHUB_REF"] = "refs/heads/main"; process.env["GITHUB_REPOSITORY"] = "octocat/HelloWorld"; From c7d0b920947856bee79f245ce27a0ac708bf40d1 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Mon, 19 Jan 2026 13:47:50 +0000 Subject: [PATCH 08/13] Drop `isDynamic` check from `isCCR` The analysis key already tells us this under normal conditions --- lib/analyze-action.js | 5 ++--- lib/init-action-post.js | 5 ++--- lib/init-action.js | 5 ++--- lib/upload-lib.js | 5 ++--- lib/upload-sarif-action.js | 5 ++--- src/actions-util.ts | 11 ++++------- 6 files changed, 14 insertions(+), 22 deletions(-) diff --git a/lib/analyze-action.js b/lib/analyze-action.js index 3f06a642bd..2230704bcd 100644 --- a/lib/analyze-action.js +++ b/lib/analyze-action.js @@ -90605,10 +90605,9 @@ function isDynamicWorkflow() { function isDefaultSetup() { return isDynamicWorkflow() && !isCCR(); } +var CCR_KEY_PREFIX = "dynamic/copilot-pull-request-reviewer"; function isCCR() { - return isDynamicWorkflow() && process.env["CODEQL_ACTION_ANALYSIS_KEY" /* ANALYSIS_KEY */]?.startsWith( - "dynamic/copilot-pull-request-reviewer" - ) || false; + return process.env["CODEQL_ACTION_ANALYSIS_KEY" /* ANALYSIS_KEY */]?.startsWith(CCR_KEY_PREFIX) || false; } function prettyPrintInvocation(cmd, args) { return [cmd, ...args].map((x) => x.includes(" ") ? `'${x}'` : x).join(" "); diff --git a/lib/init-action-post.js b/lib/init-action-post.js index 3799a34ceb..30a200737f 100644 --- a/lib/init-action-post.js +++ b/lib/init-action-post.js @@ -126723,10 +126723,9 @@ function isDynamicWorkflow() { function isDefaultSetup() { return isDynamicWorkflow() && !isCCR(); } +var CCR_KEY_PREFIX = "dynamic/copilot-pull-request-reviewer"; function isCCR() { - return isDynamicWorkflow() && process.env["CODEQL_ACTION_ANALYSIS_KEY" /* ANALYSIS_KEY */]?.startsWith( - "dynamic/copilot-pull-request-reviewer" - ) || false; + return process.env["CODEQL_ACTION_ANALYSIS_KEY" /* ANALYSIS_KEY */]?.startsWith(CCR_KEY_PREFIX) || false; } function prettyPrintInvocation(cmd, args) { return [cmd, ...args].map((x) => x.includes(" ") ? `'${x}'` : x).join(" "); diff --git a/lib/init-action.js b/lib/init-action.js index 35972710a4..2047f28ab4 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -87954,10 +87954,9 @@ function isDynamicWorkflow() { function isDefaultSetup() { return isDynamicWorkflow() && !isCCR(); } +var CCR_KEY_PREFIX = "dynamic/copilot-pull-request-reviewer"; function isCCR() { - return isDynamicWorkflow() && process.env["CODEQL_ACTION_ANALYSIS_KEY" /* ANALYSIS_KEY */]?.startsWith( - "dynamic/copilot-pull-request-reviewer" - ) || false; + return process.env["CODEQL_ACTION_ANALYSIS_KEY" /* ANALYSIS_KEY */]?.startsWith(CCR_KEY_PREFIX) || false; } function prettyPrintInvocation(cmd, args) { return [cmd, ...args].map((x) => x.includes(" ") ? `'${x}'` : x).join(" "); diff --git a/lib/upload-lib.js b/lib/upload-lib.js index 009a82d3a2..d38a2a12fe 100644 --- a/lib/upload-lib.js +++ b/lib/upload-lib.js @@ -90305,10 +90305,9 @@ function isDynamicWorkflow() { function isDefaultSetup() { return isDynamicWorkflow() && !isCCR(); } +var CCR_KEY_PREFIX = "dynamic/copilot-pull-request-reviewer"; function isCCR() { - return isDynamicWorkflow() && process.env["CODEQL_ACTION_ANALYSIS_KEY" /* ANALYSIS_KEY */]?.startsWith( - "dynamic/copilot-pull-request-reviewer" - ) || false; + return process.env["CODEQL_ACTION_ANALYSIS_KEY" /* ANALYSIS_KEY */]?.startsWith(CCR_KEY_PREFIX) || false; } function prettyPrintInvocation(cmd, args) { return [cmd, ...args].map((x) => x.includes(" ") ? `'${x}'` : x).join(" "); diff --git a/lib/upload-sarif-action.js b/lib/upload-sarif-action.js index 9433fb57ae..92712c2ece 100644 --- a/lib/upload-sarif-action.js +++ b/lib/upload-sarif-action.js @@ -90336,10 +90336,9 @@ function isDynamicWorkflow() { function isDefaultSetup() { return isDynamicWorkflow() && !isCCR(); } +var CCR_KEY_PREFIX = "dynamic/copilot-pull-request-reviewer"; function isCCR() { - return isDynamicWorkflow() && process.env["CODEQL_ACTION_ANALYSIS_KEY" /* ANALYSIS_KEY */]?.startsWith( - "dynamic/copilot-pull-request-reviewer" - ) || false; + return process.env["CODEQL_ACTION_ANALYSIS_KEY" /* ANALYSIS_KEY */]?.startsWith(CCR_KEY_PREFIX) || false; } function prettyPrintInvocation(cmd, args) { return [cmd, ...args].map((x) => x.includes(" ") ? `'${x}'` : x).join(" "); diff --git a/src/actions-util.ts b/src/actions-util.ts index b26ee2b1ff..25f08359f1 100644 --- a/src/actions-util.ts +++ b/src/actions-util.ts @@ -258,15 +258,12 @@ export function isDefaultSetup(): boolean { return isDynamicWorkflow() && !isCCR(); } +/* The analysis key prefix used for CCR. */ +const CCR_KEY_PREFIX = "dynamic/copilot-pull-request-reviewer"; + /** Determines whether we are running in CCR. */ export function isCCR(): boolean { - return ( - (isDynamicWorkflow() && - process.env[EnvVar.ANALYSIS_KEY]?.startsWith( - "dynamic/copilot-pull-request-reviewer", - )) || - false - ); + return process.env[EnvVar.ANALYSIS_KEY]?.startsWith(CCR_KEY_PREFIX) || false; } export function prettyPrintInvocation(cmd: string, args: string[]): string { From 5f5c095469c54b1bbbac13a8f1d2bc1007ab2e17 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Mon, 19 Jan 2026 13:49:42 +0000 Subject: [PATCH 09/13] Add docs comments for `listFiles` and `getGeneratedFiles` --- src/git-utils.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/git-utils.ts b/src/git-utils.ts index 1271ba8689..6f41983cb4 100644 --- a/src/git-utils.ts +++ b/src/git-utils.ts @@ -400,6 +400,11 @@ export async function isAnalyzingDefaultBranch(): Promise { return currentRef === defaultBranch; } +/** + * Gets a list of all tracked files in the repository. + * + * @param workingDirectory The working directory, which is part of a Git repository. + */ export async function listFiles(workingDirectory: string): Promise { const stdout = await runGitCommand( workingDirectory, @@ -409,6 +414,11 @@ export async function listFiles(workingDirectory: string): Promise { return stdout.split(os.EOL); } +/** + * Gets a list of files that have the `linguist-generated: true` attribute. + * + * @param workingDirectory The working directory, which is part of a Git repository. + */ export async function getGeneratedFiles( workingDirectory: string, ): Promise { From 9c3f69d7a39b0af2d5c0907cdc54bed571039527 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Mon, 19 Jan 2026 14:04:41 +0000 Subject: [PATCH 10/13] Add some logging --- lib/init-action.js | 11 +++++++++-- src/config-utils.ts | 12 ++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/init-action.js b/lib/init-action.js index 2047f28ab4..53c1de2653 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -90264,11 +90264,18 @@ async function initConfig(features, inputs) { if (await features.getValue("ignore_generated_files" /* IgnoreGeneratedFiles */) && isCCR()) { try { const generatedFiles = await getGeneratedFiles(inputs.sourceRoot); - config.computedConfig["paths-ignore"] ??= []; - config.computedConfig["paths-ignore"].push(...generatedFiles); + if (generatedFiles.length > 0) { + config.computedConfig["paths-ignore"] ??= []; + config.computedConfig["paths-ignore"].push(...generatedFiles); + logger.info( + `Detected ${generatedFiles.length} generated file(s), which will be excluded from analysis: ${generatedFiles.join(", ")}` + ); + } } catch (error3) { logger.info(`Cannot ignore generated files: ${getErrorMessage(error3)}`); } + } else { + logger.debug(`Skipping check for generated files.`); } if (config.analysisKinds.length === 1 && isCodeQualityEnabled(config)) { if (hasQueryCustomisation(config.computedConfig)) { diff --git a/src/config-utils.ts b/src/config-utils.ts index 5fb169b9b7..55d369de46 100644 --- a/src/config-utils.ts +++ b/src/config-utils.ts @@ -922,11 +922,19 @@ export async function initConfig( if ((await features.getValue(Feature.IgnoreGeneratedFiles)) && isCCR()) { try { const generatedFiles = await getGeneratedFiles(inputs.sourceRoot); - config.computedConfig["paths-ignore"] ??= []; - config.computedConfig["paths-ignore"].push(...generatedFiles); + + if (generatedFiles.length > 0) { + config.computedConfig["paths-ignore"] ??= []; + config.computedConfig["paths-ignore"].push(...generatedFiles); + logger.info( + `Detected ${generatedFiles.length} generated file(s), which will be excluded from analysis: ${generatedFiles.join(", ")}`, + ); + } } catch (error) { logger.info(`Cannot ignore generated files: ${getErrorMessage(error)}`); } + } else { + logger.debug(`Skipping check for generated files.`); } // If Code Quality analysis is the only enabled analysis kind, then we will initialise From 546ea0730332d288b75c12e49f6a859a537b667d Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Mon, 19 Jan 2026 14:11:11 +0000 Subject: [PATCH 11/13] Use linebreaks --- lib/init-action.js | 2 +- src/git-utils.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/init-action.js b/lib/init-action.js index 53c1de2653..3cd5e42061 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -89013,7 +89013,7 @@ async function getGeneratedFiles(workingDirectory) { workingDirectory, ["check-attr", "linguist-generated", "--stdin"], "Unable to check attributes of files.", - { input: Buffer.from(files.join(" ")) } + { input: Buffer.from(files.join(os2.EOL)) } ); const generatedFiles = []; const regex = /^([^:]+): linguist-generated: true$/; diff --git a/src/git-utils.ts b/src/git-utils.ts index 6f41983cb4..002f6f0560 100644 --- a/src/git-utils.ts +++ b/src/git-utils.ts @@ -427,7 +427,7 @@ export async function getGeneratedFiles( workingDirectory, ["check-attr", "linguist-generated", "--stdin"], "Unable to check attributes of files.", - { input: Buffer.from(files.join(" ")) }, + { input: Buffer.from(files.join(os.EOL)) }, ); const generatedFiles: string[] = []; From 7beb64218af173e365ec6a6b56c7471fb377f434 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Mon, 19 Jan 2026 14:12:04 +0000 Subject: [PATCH 12/13] Move after Git version check --- lib/init-action.js | 32 ++++++++++++++++---------------- src/config-utils.ts | 42 +++++++++++++++++++++--------------------- 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/lib/init-action.js b/lib/init-action.js index 3cd5e42061..60390ec111 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -90261,22 +90261,6 @@ async function initConfig(features, inputs) { ); } const config = await initActionState(inputs, userConfig); - if (await features.getValue("ignore_generated_files" /* IgnoreGeneratedFiles */) && isCCR()) { - try { - const generatedFiles = await getGeneratedFiles(inputs.sourceRoot); - if (generatedFiles.length > 0) { - config.computedConfig["paths-ignore"] ??= []; - config.computedConfig["paths-ignore"].push(...generatedFiles); - logger.info( - `Detected ${generatedFiles.length} generated file(s), which will be excluded from analysis: ${generatedFiles.join(", ")}` - ); - } - } catch (error3) { - logger.info(`Cannot ignore generated files: ${getErrorMessage(error3)}`); - } - } else { - logger.debug(`Skipping check for generated files.`); - } if (config.analysisKinds.length === 1 && isCodeQualityEnabled(config)) { if (hasQueryCustomisation(config.computedConfig)) { throw new ConfigurationError( @@ -90299,6 +90283,22 @@ async function initConfig(features, inputs) { throw e; } } + if (await features.getValue("ignore_generated_files" /* IgnoreGeneratedFiles */) && isCCR()) { + try { + const generatedFiles = await getGeneratedFiles(inputs.sourceRoot); + if (generatedFiles.length > 0) { + config.computedConfig["paths-ignore"] ??= []; + config.computedConfig["paths-ignore"].push(...generatedFiles); + logger.info( + `Detected ${generatedFiles.length} generated file(s), which will be excluded from analysis: ${generatedFiles.join(", ")}` + ); + } + } catch (error3) { + logger.info(`Cannot ignore generated files: ${getErrorMessage(error3)}`); + } + } else { + logger.debug(`Skipping check for generated files.`); + } const { overlayDatabaseMode, useOverlayDatabaseCaching } = await getOverlayDatabaseMode( inputs.codeql, inputs.features, diff --git a/src/config-utils.ts b/src/config-utils.ts index 55d369de46..7ebda7032c 100644 --- a/src/config-utils.ts +++ b/src/config-utils.ts @@ -916,27 +916,6 @@ export async function initConfig( const config = await initActionState(inputs, userConfig); - // If we are in CCR or the corresponding FF is enabled, try to determine - // which files in the repository are marked as generated and add them to - // the `paths-ignore` configuration. - if ((await features.getValue(Feature.IgnoreGeneratedFiles)) && isCCR()) { - try { - const generatedFiles = await getGeneratedFiles(inputs.sourceRoot); - - if (generatedFiles.length > 0) { - config.computedConfig["paths-ignore"] ??= []; - config.computedConfig["paths-ignore"].push(...generatedFiles); - logger.info( - `Detected ${generatedFiles.length} generated file(s), which will be excluded from analysis: ${generatedFiles.join(", ")}`, - ); - } - } catch (error) { - logger.info(`Cannot ignore generated files: ${getErrorMessage(error)}`); - } - } else { - logger.debug(`Skipping check for generated files.`); - } - // If Code Quality analysis is the only enabled analysis kind, then we will initialise // the database for Code Quality. That entails disabling the default queries and only // running quality queries. We do not currently support query customisations in that case. @@ -974,6 +953,27 @@ export async function initConfig( } } + // If we are in CCR or the corresponding FF is enabled, try to determine + // which files in the repository are marked as generated and add them to + // the `paths-ignore` configuration. + if ((await features.getValue(Feature.IgnoreGeneratedFiles)) && isCCR()) { + try { + const generatedFiles = await getGeneratedFiles(inputs.sourceRoot); + + if (generatedFiles.length > 0) { + config.computedConfig["paths-ignore"] ??= []; + config.computedConfig["paths-ignore"].push(...generatedFiles); + logger.info( + `Detected ${generatedFiles.length} generated file(s), which will be excluded from analysis: ${generatedFiles.join(", ")}`, + ); + } + } catch (error) { + logger.info(`Cannot ignore generated files: ${getErrorMessage(error)}`); + } + } else { + logger.debug(`Skipping check for generated files.`); + } + // 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 From 4bd7556a48e59b58f21cbe29893608330813be9b Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Mon, 19 Jan 2026 14:12:57 +0000 Subject: [PATCH 13/13] Log when there are no generated files --- lib/init-action.js | 2 ++ src/config-utils.ts | 2 ++ 2 files changed, 4 insertions(+) diff --git a/lib/init-action.js b/lib/init-action.js index 60390ec111..046c40c3e0 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -90292,6 +90292,8 @@ async function initConfig(features, inputs) { logger.info( `Detected ${generatedFiles.length} generated file(s), which will be excluded from analysis: ${generatedFiles.join(", ")}` ); + } else { + logger.info(`Found no generated files.`); } } catch (error3) { logger.info(`Cannot ignore generated files: ${getErrorMessage(error3)}`); diff --git a/src/config-utils.ts b/src/config-utils.ts index 7ebda7032c..cadd45356e 100644 --- a/src/config-utils.ts +++ b/src/config-utils.ts @@ -966,6 +966,8 @@ export async function initConfig( logger.info( `Detected ${generatedFiles.length} generated file(s), which will be excluded from analysis: ${generatedFiles.join(", ")}`, ); + } else { + logger.info(`Found no generated files.`); } } catch (error) { logger.info(`Cannot ignore generated files: ${getErrorMessage(error)}`);