Skip to content

Commit 4c0acfe

Browse files
author
Alex Eyers-Taylor
committed
Consume precomputed diff ranges in analyze and avoid getting them from the API.
1 parent 9bb8375 commit 4c0acfe

File tree

4 files changed

+45
-197
lines changed

4 files changed

+45
-197
lines changed

lib/analyze-action.js

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

lib/init-action.js

Lines changed: 0 additions & 6 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";
@@ -299,14 +298,8 @@ async function run() {
299298
logger,
300299
);
301300

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

311304
await warnIfGoInstalledAfterInit(config, logger);
312305
await runAutobuildIfLegacyGoWorkflow(config, logger);

src/analyze.ts

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,15 @@ 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
// (getApiClient import removed; no longer needed after diff refactor)
1212
import { setupCppAutobuild } from "./autobuild";
1313
import { type CodeQL } from "./codeql";
1414
import * as configUtils from "./config-utils";
1515
import { getJavaTempDependencyDir } from "./dependency-caching";
1616
import { addDiagnostic, makeDiagnostic } from "./diagnostics";
17-
import {
18-
DiffThunkRange,
19-
writeDiffRangesJsonFile,
20-
getPullRequestEditedDiffRanges,
21-
} from "./diff-informed-analysis-utils";
17+
import { DiffThunkRange, readDiffRangesJsonFile } from "./diff-informed-analysis-utils";
2218
import { EnvVar } from "./environment";
2319
import { FeatureEnablement, Feature } from "./feature-flags";
2420
import { KnownLanguage, Language } from "./languages";
@@ -284,17 +280,35 @@ async function finalizeDatabaseCreation(
284280
* the diff range information, or `undefined` if the feature is disabled.
285281
*/
286282
export async function setupDiffInformedQueryRun(
287-
branches: PullRequestBranches,
288283
logger: Logger,
289284
): Promise<string | undefined> {
290285
return await withGroupAsync(
291286
"Generating diff range extension pack",
292287
async () => {
288+
// Only use precomputed diff ranges; never recompute here.
289+
let diffRanges: DiffThunkRange[] | undefined;
290+
try {
291+
diffRanges = readDiffRangesJsonFile(logger);
292+
} catch (e) {
293+
logger.debug(
294+
`Failed to read precomputed diff ranges: ${util.getErrorMessage(e)}`,
295+
);
296+
diffRanges = undefined;
297+
}
298+
299+
if (diffRanges === undefined) {
300+
logger.info(
301+
"No precomputed diff ranges found; skipping diff-informed analysis stage.",
302+
);
303+
return undefined;
304+
}
305+
306+
const fileCount = new Set(diffRanges.filter((r) => r.path).map((r) => r.path)).size;
293307
logger.info(
294-
`Calculating diff ranges for ${branches.base}...${branches.head}`,
308+
`Using precomputed diff ranges (${diffRanges.length} ranges across ${fileCount} files).`,
295309
);
296-
const diffRanges = await getPullRequestEditedDiffRanges(branches, logger);
297-
const packDir = writeDiffRangeDataExtensionPack(logger, diffRanges);
310+
311+
const packDir = writeDiffRangeDataExtensionPack(logger, diffRanges);
298312
if (packDir === undefined) {
299313
logger.warning(
300314
"Cannot create diff range extension pack for diff-informed queries; " +
@@ -392,9 +406,6 @@ extensions:
392406
`Wrote pr-diff-range extension pack to ${extensionFilePath}:\n${extensionContents}`,
393407
);
394408

395-
// Write the diff ranges to a JSON file, for action-side alert filtering by the
396-
// upload-lib module.
397-
writeDiffRangesJsonFile(logger, ranges);
398409

399410
return diffRangeDir;
400411
}

0 commit comments

Comments
 (0)