Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
5 changes: 2 additions & 3 deletions lib/analyze-action.js

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

5 changes: 2 additions & 3 deletions lib/autobuild-action.js

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

5 changes: 2 additions & 3 deletions lib/init-action-post.js

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

48 changes: 41 additions & 7 deletions lib/init-action.js

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

5 changes: 2 additions & 3 deletions lib/resolve-environment-action.js

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

5 changes: 2 additions & 3 deletions lib/setup-codeql-action.js

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

5 changes: 2 additions & 3 deletions lib/start-proxy-action.js

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

5 changes: 2 additions & 3 deletions lib/upload-lib.js

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

5 changes: 2 additions & 3 deletions lib/upload-sarif-action.js

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

6 changes: 2 additions & 4 deletions src/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,7 @@ export async function getWorkflowRelativePath(): Promise<string> {
* the GitHub API, but after that the result will be cached.
*/
export async function getAnalysisKey(): Promise<string> {
const analysisKeyEnvVar = EnvVar.ANALYSIS_KEY;

let analysisKey = process.env[analysisKeyEnvVar];
let analysisKey = process.env[EnvVar.ANALYSIS_KEY];
if (analysisKey !== undefined) {
return analysisKey;
}
Expand All @@ -201,7 +199,7 @@ export async function getAnalysisKey(): Promise<string> {
const jobName = getRequiredEnvParam("GITHUB_JOB");

analysisKey = `${workflowPath}:${jobName}`;
core.exportVariable(analysisKeyEnvVar, analysisKey);
core.exportVariable(EnvVar.ANALYSIS_KEY, analysisKey);
return analysisKey;
}

Expand Down
42 changes: 41 additions & 1 deletion src/config-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import {
getCodeQLMemoryLimit,
getErrorMessage,
isInTestMode,
joinAtMost,
} from "./util";

export * from "./config/db-config";
Expand Down Expand Up @@ -958,17 +959,27 @@ export async function initConfig(
// the `paths-ignore` configuration.
if ((await features.getValue(Feature.IgnoreGeneratedFiles)) && isCCR()) {
try {
const generatedFilesCheckStartedAt = performance.now();
const generatedFiles = await getGeneratedFiles(inputs.sourceRoot);
const generatedFilesDuration = Math.round(
performance.now() - generatedFilesCheckStartedAt,
);

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(", ")}`,
`Detected ${generatedFiles.length} generated file(s), which will be excluded from analysis: ${joinAtMost(generatedFiles, ", ", 10)}`,
);
} else {
logger.info(`Found no generated files.`);
}

await logGeneratedFilesTelemetry(
config,
generatedFilesDuration,
generatedFiles.length,
);
} catch (error) {
logger.info(`Cannot ignore generated files: ${getErrorMessage(error)}`);
}
Expand Down Expand Up @@ -1413,3 +1424,32 @@ async function logGitVersionTelemetry(
);
}
}

/**
* Logs the time it took to identify generated files and how many were discovered as
* a telemetry diagnostic.
* */
async function logGeneratedFilesTelemetry(
config: Config,
duration: number,
generatedFilesCount: number,
): Promise<void> {
if (config.languages.length < 1) {
return;
}

addDiagnostic(
config,
// Arbitrarily choose the first language. We could also choose all languages, but that
// increases the risk of misinterpreting the data.
Comment on lines +1443 to +1444
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer arbitrary ;)

config.languages[0],
makeTelemetryDiagnostic(
"codeql-action/generated-files-telemetry",
"Generated files telemetry",
{
duration,
generatedFilesCount,
},
),
);
}
5 changes: 3 additions & 2 deletions src/git-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ test("GitVersionInfo.isAtLeast correctly compares versions", async (t) => {
test("listFiles returns array of file paths", async (t) => {
sinon
.stub(gitUtils, "runGitCommand")
.resolves(["dir/file.txt", "README.txt"].join(os.EOL));
.resolves(["dir/file.txt", "README.txt", ""].join(os.EOL));

await t.notThrowsAsync(async () => {
const result = await gitUtils.listFiles("/some/path");
Expand All @@ -453,14 +453,15 @@ test("getGeneratedFiles returns generated files only", async (t) => {

runGitCommandStub
.onFirstCall()
.resolves(["dir/file.txt", "test.json", "README.txt"].join(os.EOL));
.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),
);

Expand Down
6 changes: 3 additions & 3 deletions src/git-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ export async function listFiles(workingDirectory: string): Promise<string[]> {
["ls-files"],
"Unable to list tracked files.",
);
return stdout.split(os.EOL);
return stdout.split(os.EOL).filter((line) => line.trim().length > 0);
}

/**
Expand All @@ -434,8 +434,8 @@ export async function getGeneratedFiles(
const regex = /^([^:]+): linguist-generated: true$/;
for (const result of stdout.split(os.EOL)) {
const match = result.match(regex);
if (match) {
generatedFiles.push(match[1]);
if (match && match[1].trim().length > 0) {
generatedFiles.push(match[1].trim());
}
}

Expand Down
Loading