Skip to content

Commit 5e51e6e

Browse files
alexetkaspersv
authored andcommitted
Consume precomputed diff ranges in analyze
1 parent 7329c84 commit 5e51e6e

File tree

3 files changed

+48
-188
lines changed

3 files changed

+48
-188
lines changed

lib/analyze-action.js

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

src/analyze-action.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import {
3030
DependencyCacheUploadStatusReport,
3131
uploadDependencyCaches,
3232
} from "./dependency-caching";
33-
import { getDiffInformedAnalysisBranches } from "./diff-informed-analysis-utils";
3433
import { EnvVar } from "./environment";
3534
import { Feature, Features } from "./feature-flags";
3635
import { KnownLanguage } from "./languages";
@@ -302,14 +301,8 @@ async function run() {
302301
logger,
303302
);
304303

305-
const branches = await getDiffInformedAnalysisBranches(
306-
codeql,
307-
features,
308-
logger,
309-
);
310-
const diffRangePackDir = branches
311-
? await setupDiffInformedQueryRun(branches, logger)
312-
: undefined;
304+
// Setup diff informed analysis if needed (based on whether init created the file)
305+
const diffRangePackDir = await setupDiffInformedQueryRun(logger);
313306

314307
await warnIfGoInstalledAfterInit(config, logger);
315308
await runAutobuildIfLegacyGoWorkflow(config, logger);

src/analyze.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as io from "@actions/io";
66
import * as del from "del";
77
import * as yaml from "js-yaml";
88

9-
import { getTemporaryDirectory, PullRequestBranches } from "./actions-util";
9+
import { getTemporaryDirectory } from "./actions-util";
1010
import * as analyses from "./analyses";
1111
import { setupCppAutobuild } from "./autobuild";
1212
import { type CodeQL } from "./codeql";
@@ -15,8 +15,7 @@ import { getJavaTempDependencyDir } from "./dependency-caching";
1515
import { addDiagnostic, makeDiagnostic } from "./diagnostics";
1616
import {
1717
DiffThunkRange,
18-
writeDiffRangesJsonFile,
19-
getPullRequestEditedDiffRanges,
18+
readDiffRangesJsonFile,
2019
} from "./diff-informed-analysis-utils";
2120
import { EnvVar } from "./environment";
2221
import { FeatureEnablement, Feature } from "./feature-flags";
@@ -282,16 +281,36 @@ async function finalizeDatabaseCreation(
282281
* the diff range information, or `undefined` if the feature is disabled.
283282
*/
284283
export async function setupDiffInformedQueryRun(
285-
branches: PullRequestBranches,
286284
logger: Logger,
287285
): Promise<string | undefined> {
288286
return await withGroupAsync(
289287
"Generating diff range extension pack",
290288
async () => {
289+
// Only use precomputed diff ranges; never recompute here.
290+
let diffRanges: DiffThunkRange[] | undefined;
291+
try {
292+
diffRanges = readDiffRangesJsonFile(logger);
293+
} catch (e) {
294+
logger.debug(
295+
`Failed to read precomputed diff ranges: ${util.getErrorMessage(e)}`,
296+
);
297+
diffRanges = undefined;
298+
}
299+
300+
if (diffRanges === undefined) {
301+
logger.info(
302+
"No precomputed diff ranges found; skipping diff-informed analysis stage.",
303+
);
304+
return undefined;
305+
}
306+
307+
const fileCount = new Set(
308+
diffRanges.filter((r) => r.path).map((r) => r.path),
309+
).size;
291310
logger.info(
292-
`Calculating diff ranges for ${branches.base}...${branches.head}`,
311+
`Using precomputed diff ranges (${diffRanges.length} ranges across ${fileCount} files).`,
293312
);
294-
const diffRanges = await getPullRequestEditedDiffRanges(branches, logger);
313+
295314
const packDir = writeDiffRangeDataExtensionPack(logger, diffRanges);
296315
if (packDir === undefined) {
297316
logger.warning(
@@ -388,10 +407,6 @@ extensions:
388407
`Wrote pr-diff-range extension pack to ${extensionFilePath}:\n${extensionContents}`,
389408
);
390409

391-
// Write the diff ranges to a JSON file, for action-side alert filtering by the
392-
// upload-lib module.
393-
writeDiffRangesJsonFile(logger, ranges);
394-
395410
return diffRangeDir;
396411
}
397412

0 commit comments

Comments
 (0)