Skip to content

Commit 4dbec94

Browse files
authored
Merge pull request #3537 from github/henrymercer/overlay-status-record-job
Record the job that published an overlay status
2 parents 40f0fa9 + a05f541 commit 4dbec94

File tree

4 files changed

+60
-7
lines changed

4 files changed

+60
-7
lines changed

lib/init-action-post.js

Lines changed: 12 additions & 2 deletions
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: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@ test("not uploading failed SARIF when `code-scanning` is not an enabled analysis
316316
test("saves overlay status when overlay-base analysis did not complete successfully", async (t) => {
317317
return await util.withTmpDir(async (tmpDir) => {
318318
process.env["GITHUB_REPOSITORY"] = "github/codeql-action-fake-repository";
319+
process.env["GITHUB_RUN_ID"] = "12345";
320+
process.env["GITHUB_RUN_ATTEMPT"] = "1";
321+
process.env["GITHUB_JOB"] = "analyze";
319322
process.env["RUNNER_TEMP"] = tmpDir;
320323
// Ensure analyze did not complete successfully.
321324
delete process.env[EnvVar.ANALYZE_DID_COMPLETE_SUCCESSFULLY];
@@ -370,8 +373,13 @@ test("saves overlay status when overlay-base analysis did not complete successfu
370373
{
371374
attemptedToBuildOverlayBaseDatabase: true,
372375
builtOverlayBaseDatabase: false,
376+
job: {
377+
workflowRunId: 12345,
378+
workflowRunAttempt: 1,
379+
name: "analyze",
380+
},
373381
},
374-
"fourth arg should be the overlay status recording an unsuccessful build attempt",
382+
"fourth arg should be the overlay status recording an unsuccessful build attempt with job details",
375383
);
376384
});
377385
});

src/init-action-post-helper.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import { EnvVar } from "./environment";
1212
import { Feature, FeatureEnablement } from "./feature-flags";
1313
import { Logger } from "./logging";
1414
import { OverlayDatabaseMode } from "./overlay";
15-
import { OverlayStatus, saveOverlayStatus } from "./overlay/status";
15+
import {
16+
createOverlayStatus,
17+
OverlayStatus,
18+
saveOverlayStatus,
19+
} from "./overlay/status";
1620
import { RepositoryNwo, getRepositoryNwo } from "./repository";
1721
import { JobStatus } from "./status-report";
1822
import * as uploadLib from "./upload-lib";
@@ -270,10 +274,10 @@ async function recordOverlayStatus(
270274
return;
271275
}
272276

273-
const overlayStatus: OverlayStatus = {
277+
const overlayStatus: OverlayStatus = createOverlayStatus({
274278
attemptedToBuildOverlayBaseDatabase: true,
275279
builtOverlayBaseDatabase: false,
276-
};
280+
});
277281

278282
const diskUsage = await checkDiskUsage(logger);
279283
if (diskUsage === undefined) {

src/overlay/status.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,17 @@ import * as path from "path";
1313

1414
import * as actionsCache from "@actions/cache";
1515

16-
import { getTemporaryDirectory } from "../actions-util";
16+
import {
17+
getTemporaryDirectory,
18+
getWorkflowRunAttempt,
19+
getWorkflowRunID,
20+
} from "../actions-util";
1721
import { type CodeQL } from "../codeql";
1822
import { Logger } from "../logging";
1923
import {
2024
DiskUsage,
2125
getErrorMessage,
26+
getRequiredEnvParam,
2227
waitForResultWithTimeLimit,
2328
} from "../util";
2429

@@ -38,12 +43,38 @@ function getStatusFilePath(languages: string[]): string {
3843
);
3944
}
4045

46+
/** Details of the job that recorded an overlay status. */
47+
interface JobInfo {
48+
/** The workflow run ID. */
49+
workflowRunId: number;
50+
/** The workflow run attempt number. */
51+
workflowRunAttempt: number;
52+
/** The name of the job (from GITHUB_JOB). */
53+
name: string;
54+
}
55+
4156
/** Status of an overlay analysis for a group of languages. */
4257
export interface OverlayStatus {
4358
/** Whether the job attempted to build an overlay base database. */
4459
attemptedToBuildOverlayBaseDatabase: boolean;
4560
/** Whether the job successfully built an overlay base database. */
4661
builtOverlayBaseDatabase: boolean;
62+
/** Details of the job that recorded this status. */
63+
job?: JobInfo;
64+
}
65+
66+
/** Creates an `OverlayStatus` populated with the details of the current job. */
67+
export function createOverlayStatus(
68+
attributes: Omit<OverlayStatus, "job">,
69+
): OverlayStatus {
70+
return {
71+
...attributes,
72+
job: {
73+
workflowRunId: getWorkflowRunID(),
74+
workflowRunAttempt: getWorkflowRunAttempt(),
75+
name: getRequiredEnvParam("GITHUB_JOB"),
76+
},
77+
};
4778
}
4879

4980
/**

0 commit comments

Comments
 (0)