Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
16 changes: 16 additions & 0 deletions lib/init-action.js

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

4 changes: 4 additions & 0 deletions src/diff-informed-analysis-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ export function writeDiffRangesJsonFile(
);
}

export function hasDiffRangesJsonFile(): boolean {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Minor: Adding a JSDoc comment here would be nice.

return fs.existsSync(actionsUtil.getDiffRangesJsonFilePath());
}

export function readDiffRangesJsonFile(
logger: Logger,
): DiffThunkRange[] | undefined {
Expand Down
26 changes: 26 additions & 0 deletions src/init-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import {
import {
getDiffInformedAnalysisBranches,
getPullRequestEditedDiffRanges,
hasDiffRangesJsonFile,
shouldPerformDiffInformedAnalysis,
writeDiffRangesJsonFile,
} from "./diff-informed-analysis-utils";
import { EnvVar } from "./environment";
Expand Down Expand Up @@ -438,6 +440,30 @@ async function run(startedAt: Date) {
return;
}

// If overlay is enabled and diff-informed analysis should have run but
// failed to produce output, revert to non-overlay analysis. Overlay
// without diff-informed is an untested combination that can produce
// inaccurate results.
try {
if (
config.overlayDatabaseMode === OverlayDatabaseMode.Overlay &&
(await shouldPerformDiffInformedAnalysis(codeql, features, logger)) &&
!hasDiffRangesJsonFile()
) {
logger.warning(
"Diff-informed analysis is not available for this pull request. " +
`Reverting overlay database mode to ${OverlayDatabaseMode.None}.`,
);
config.overlayDatabaseMode = OverlayDatabaseMode.None;
}
} catch (e) {
logger.warning(
`Failed to determine diff-informed analysis availability, ` +
`reverting overlay database mode to ${OverlayDatabaseMode.None}: ${getErrorMessage(e)}`,
);
config.overlayDatabaseMode = OverlayDatabaseMode.None;
}

Comment on lines +443 to +466
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be good to move this out of init-action.ts and into one of the overlay-specific modules if possible.

There's already a bunch of logic around overlay enablement there, so spreading that out across different locations isn't good.

We also have some frameworks for tests/diagnostics/telemetry there that this could factor into. In any case, this should have test coverage.

let overlayBaseDatabaseStats: OverlayBaseDatabaseDownloadStats | undefined;
let dependencyCachingStatus: DependencyCacheRestoreStatusReport | undefined;
try {
Expand Down
Loading