Skip to content

Commit 6c405c2

Browse files
committed
Be more explicit about attempt to build overlay DB
1 parent 827bba6 commit 6c405c2

File tree

5 files changed

+33
-14
lines changed

5 files changed

+33
-14
lines changed

lib/init-action-post.js

Lines changed: 3 additions & 2 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: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/init-action-post-helper.test.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,11 @@ test("saves overlay status when overlay-base analysis did not complete successfu
365365
);
366366
t.deepEqual(
367367
saveOverlayStatusStub.firstCall.args[3],
368-
{ builtOverlayBaseDatabase: false },
369-
"fourth arg should be the overlay status with builtOverlayBaseDatabase: false",
368+
{
369+
attemptedToBuildOverlayBaseDatabase: true,
370+
builtOverlayBaseDatabase: false,
371+
},
372+
"fourth arg should be the overlay status recording an unsuccessful build attempt",
370373
);
371374
});
372375
});
@@ -408,17 +411,18 @@ test("does not save overlay status when OverlayAnalysisStatusSave feature flag i
408411
});
409412
});
410413

411-
test("does not save overlay status when analysis completed successfully", async (t) => {
414+
test("saves overlay status recording successful build when analysis completed successfully", async (t) => {
412415
return await util.withTmpDir(async (tmpDir) => {
413416
process.env["GITHUB_REPOSITORY"] = "github/codeql-action-fake-repository";
414417
process.env["RUNNER_TEMP"] = tmpDir;
415418
// Mark analyze as having completed successfully.
416419
process.env[EnvVar.ANALYZE_DID_COMPLETE_SUCCESSFULLY] = "true";
417420

418-
sinon.stub(util, "checkDiskUsage").resolves({
421+
const diskUsage: util.DiskUsage = {
419422
numAvailableBytes: 100 * 1024 * 1024 * 1024,
420423
numTotalBytes: 200 * 1024 * 1024 * 1024,
421-
});
424+
};
425+
sinon.stub(util, "checkDiskUsage").resolves(diskUsage);
422426

423427
const saveOverlayStatusStub = sinon
424428
.stub(overlayStatus, "saveOverlayStatus")
@@ -434,13 +438,21 @@ test("does not save overlay status when analysis completed successfully", async
434438
overlayDatabaseMode: OverlayDatabaseMode.OverlayBase,
435439
}),
436440
parseRepositoryNwo("github/codeql-action"),
437-
createFeatures([]),
441+
createFeatures([Feature.OverlayAnalysisStatusSave]),
438442
getRunnerLogger(true),
439443
);
440444

441445
t.true(
442-
saveOverlayStatusStub.notCalled,
443-
"saveOverlayStatus should not be called when analysis completed successfully",
446+
saveOverlayStatusStub.calledOnce,
447+
"saveOverlayStatus should be called exactly once",
448+
);
449+
t.deepEqual(
450+
saveOverlayStatusStub.firstCall.args[3],
451+
{
452+
attemptedToBuildOverlayBaseDatabase: true,
453+
builtOverlayBaseDatabase: true,
454+
},
455+
"fourth arg should be the overlay status recording a successful build attempt",
444456
);
445457
});
446458
});

src/init-action-post-helper.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,12 @@ async function recordOverlayStatus(
259259
) {
260260
if (
261261
config.overlayDatabaseMode === OverlayDatabaseMode.OverlayBase &&
262-
process.env[EnvVar.ANALYZE_DID_COMPLETE_SUCCESSFULLY] !== "true" &&
263262
(await features.getValue(Feature.OverlayAnalysisStatusSave))
264263
) {
265264
const overlayStatus = {
266-
builtOverlayBaseDatabase: false,
265+
attemptedToBuildOverlayBaseDatabase: true,
266+
builtOverlayBaseDatabase:
267+
process.env[EnvVar.ANALYZE_DID_COMPLETE_SUCCESSFULLY] === "true",
267268
} satisfies OverlayStatus;
268269

269270
const diskUsage = await checkDiskUsage(logger);

src/overlay/status.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ const STATUS_FILE_NAME = "overlay-status.json";
3030

3131
/** Status of an overlay analysis for a set of languages. */
3232
export interface OverlayStatus {
33+
/** Whether the job attempted to build an overlay base database. */
34+
attemptedToBuildOverlayBaseDatabase: boolean;
3335
/** Whether the job successfully built an overlay base database. */
3436
builtOverlayBaseDatabase: boolean;
3537
}
@@ -48,7 +50,10 @@ export async function shouldSkipOverlayAnalysis(
4850
logger.debug("No cached overlay status found.");
4951
return false;
5052
}
51-
if (!status.builtOverlayBaseDatabase) {
53+
if (
54+
status.attemptedToBuildOverlayBaseDatabase &&
55+
!status.builtOverlayBaseDatabase
56+
) {
5257
logger.info(
5358
"Cached overlay status indicates that building an overlay base database was unsuccessful, so will skip overlay analysis.",
5459
);

0 commit comments

Comments
 (0)