From a05f541a6e1ac408807eeb89b778c3e7970b3e5e Mon Sep 17 00:00:00 2001 From: Henry Mercer Date: Tue, 3 Mar 2026 16:56:18 +0100 Subject: [PATCH 1/3] Record the job that published an overlay status This makes it easier to find the job that produced the status. --- lib/init-action-post.js | 14 ++++++++++-- src/init-action-post-helper.test.ts | 10 ++++++++- src/init-action-post-helper.ts | 10 ++++++--- src/overlay/status.ts | 33 ++++++++++++++++++++++++++++- 4 files changed, 60 insertions(+), 7 deletions(-) diff --git a/lib/init-action-post.js b/lib/init-action-post.js index 67322ea200..233ae9be0b 100644 --- a/lib/init-action-post.js +++ b/lib/init-action-post.js @@ -166091,6 +166091,16 @@ function getStatusFilePath(languages) { STATUS_FILE_NAME ); } +function createOverlayStatus(attributes) { + return { + ...attributes, + job: { + workflowRunId: getWorkflowRunID(), + workflowRunAttempt: getWorkflowRunAttempt(), + name: getRequiredEnvParam("GITHUB_JOB") + } + }; +} async function saveOverlayStatus(codeql, languages, diskUsage, status, logger) { const cacheKey = await getCacheKey(codeql, languages, diskUsage); const statusFile = getStatusFilePath(languages); @@ -170355,10 +170365,10 @@ async function recordOverlayStatus(codeql, config, features, logger) { if (config.overlayDatabaseMode !== "overlay-base" /* OverlayBase */ || process.env["CODEQL_ACTION_ANALYZE_DID_COMPLETE_SUCCESSFULLY" /* ANALYZE_DID_COMPLETE_SUCCESSFULLY */] === "true" || !await features.getValue("overlay_analysis_status_save" /* OverlayAnalysisStatusSave */)) { return; } - const overlayStatus = { + const overlayStatus = createOverlayStatus({ attemptedToBuildOverlayBaseDatabase: true, builtOverlayBaseDatabase: false - }; + }); const diskUsage = await checkDiskUsage(logger); if (diskUsage === void 0) { logger.warning( diff --git a/src/init-action-post-helper.test.ts b/src/init-action-post-helper.test.ts index 1ddb702872..039c96ef75 100644 --- a/src/init-action-post-helper.test.ts +++ b/src/init-action-post-helper.test.ts @@ -316,6 +316,9 @@ test("not uploading failed SARIF when `code-scanning` is not an enabled analysis test("saves overlay status when overlay-base analysis did not complete successfully", async (t) => { return await util.withTmpDir(async (tmpDir) => { process.env["GITHUB_REPOSITORY"] = "github/codeql-action-fake-repository"; + process.env["GITHUB_RUN_ID"] = "12345"; + process.env["GITHUB_RUN_ATTEMPT"] = "1"; + process.env["GITHUB_JOB"] = "analyze"; process.env["RUNNER_TEMP"] = tmpDir; // Ensure analyze did not complete successfully. delete process.env[EnvVar.ANALYZE_DID_COMPLETE_SUCCESSFULLY]; @@ -370,8 +373,13 @@ test("saves overlay status when overlay-base analysis did not complete successfu { attemptedToBuildOverlayBaseDatabase: true, builtOverlayBaseDatabase: false, + job: { + workflowRunId: 12345, + workflowRunAttempt: 1, + name: "analyze", + }, }, - "fourth arg should be the overlay status recording an unsuccessful build attempt", + "fourth arg should be the overlay status recording an unsuccessful build attempt with job details", ); }); }); diff --git a/src/init-action-post-helper.ts b/src/init-action-post-helper.ts index 90a4626654..328c639516 100644 --- a/src/init-action-post-helper.ts +++ b/src/init-action-post-helper.ts @@ -12,7 +12,11 @@ import { EnvVar } from "./environment"; import { Feature, FeatureEnablement } from "./feature-flags"; import { Logger } from "./logging"; import { OverlayDatabaseMode } from "./overlay"; -import { OverlayStatus, saveOverlayStatus } from "./overlay/status"; +import { + createOverlayStatus, + OverlayStatus, + saveOverlayStatus, +} from "./overlay/status"; import { RepositoryNwo, getRepositoryNwo } from "./repository"; import { JobStatus } from "./status-report"; import * as uploadLib from "./upload-lib"; @@ -270,10 +274,10 @@ async function recordOverlayStatus( return; } - const overlayStatus: OverlayStatus = { + const overlayStatus: OverlayStatus = createOverlayStatus({ attemptedToBuildOverlayBaseDatabase: true, builtOverlayBaseDatabase: false, - }; + }); const diskUsage = await checkDiskUsage(logger); if (diskUsage === undefined) { diff --git a/src/overlay/status.ts b/src/overlay/status.ts index ac3d6e7476..9e6d844edf 100644 --- a/src/overlay/status.ts +++ b/src/overlay/status.ts @@ -13,12 +13,17 @@ import * as path from "path"; import * as actionsCache from "@actions/cache"; -import { getTemporaryDirectory } from "../actions-util"; +import { + getTemporaryDirectory, + getWorkflowRunAttempt, + getWorkflowRunID, +} from "../actions-util"; import { type CodeQL } from "../codeql"; import { Logger } from "../logging"; import { DiskUsage, getErrorMessage, + getRequiredEnvParam, waitForResultWithTimeLimit, } from "../util"; @@ -38,12 +43,38 @@ function getStatusFilePath(languages: string[]): string { ); } +/** Details of the job that recorded an overlay status. */ +interface JobInfo { + /** The workflow run ID. */ + workflowRunId: number; + /** The workflow run attempt number. */ + workflowRunAttempt: number; + /** The name of the job (from GITHUB_JOB). */ + name: string; +} + /** Status of an overlay analysis for a group of languages. */ export interface OverlayStatus { /** Whether the job attempted to build an overlay base database. */ attemptedToBuildOverlayBaseDatabase: boolean; /** Whether the job successfully built an overlay base database. */ builtOverlayBaseDatabase: boolean; + /** Details of the job that recorded this status. */ + job?: JobInfo; +} + +/** Creates an `OverlayStatus` populated with the details of the current job. */ +export function createOverlayStatus( + attributes: Omit, +): OverlayStatus { + return { + ...attributes, + job: { + workflowRunId: getWorkflowRunID(), + workflowRunAttempt: getWorkflowRunAttempt(), + name: getRequiredEnvParam("GITHUB_JOB"), + }, + }; } /** From 129d771399bd55c4200933e39540ef3dd4f66479 Mon Sep 17 00:00:00 2001 From: Henry Mercer Date: Tue, 3 Mar 2026 19:04:04 +0100 Subject: [PATCH 2/3] Add check run ID --- init/action.yml | 5 +++++ lib/init-action-post.js | 27 +++++++++++++++++---------- src/init-action-post-helper.ts | 15 +++++++++++---- src/overlay/status.ts | 15 ++++++++++----- 4 files changed, 43 insertions(+), 19 deletions(-) diff --git a/init/action.yml b/init/action.yml index 57d5a99402..6c36f79bc4 100644 --- a/init/action.yml +++ b/init/action.yml @@ -159,6 +159,11 @@ inputs: description: >- Explicitly enable or disable caching of project build dependencies. required: false + check-run-id: + description: >- + [Internal] The ID of the check run, as provided by the Actions runtime environment. Do not set this value manually. + default: ${{ job.check_run_id }} + required: false outputs: codeql-path: description: The path of the CodeQL binary used for analysis diff --git a/lib/init-action-post.js b/lib/init-action-post.js index 233ae9be0b..e1b1f04e5c 100644 --- a/lib/init-action-post.js +++ b/lib/init-action-post.js @@ -166091,14 +166091,16 @@ function getStatusFilePath(languages) { STATUS_FILE_NAME ); } -function createOverlayStatus(attributes) { +function createOverlayStatus(attributes, checkRunId) { + const job = { + workflowRunId: getWorkflowRunID(), + workflowRunAttempt: getWorkflowRunAttempt(), + name: getRequiredEnvParam("GITHUB_JOB"), + ...checkRunId !== void 0 && { checkRunId } + }; return { ...attributes, - job: { - workflowRunId: getWorkflowRunID(), - workflowRunAttempt: getWorkflowRunAttempt(), - name: getRequiredEnvParam("GITHUB_JOB") - } + job }; } async function saveOverlayStatus(codeql, languages, diskUsage, status, logger) { @@ -170365,10 +170367,15 @@ async function recordOverlayStatus(codeql, config, features, logger) { if (config.overlayDatabaseMode !== "overlay-base" /* OverlayBase */ || process.env["CODEQL_ACTION_ANALYZE_DID_COMPLETE_SUCCESSFULLY" /* ANALYZE_DID_COMPLETE_SUCCESSFULLY */] === "true" || !await features.getValue("overlay_analysis_status_save" /* OverlayAnalysisStatusSave */)) { return; } - const overlayStatus = createOverlayStatus({ - attemptedToBuildOverlayBaseDatabase: true, - builtOverlayBaseDatabase: false - }); + const checkRunIdInput = getOptionalInput("check-run-id"); + const checkRunId = checkRunIdInput !== void 0 ? parseInt(checkRunIdInput, 10) : void 0; + const overlayStatus = createOverlayStatus( + { + attemptedToBuildOverlayBaseDatabase: true, + builtOverlayBaseDatabase: false + }, + Number.isNaN(checkRunId) ? void 0 : checkRunId + ); const diskUsage = await checkDiskUsage(logger); if (diskUsage === void 0) { logger.warning( diff --git a/src/init-action-post-helper.ts b/src/init-action-post-helper.ts index 328c639516..b1fb968c07 100644 --- a/src/init-action-post-helper.ts +++ b/src/init-action-post-helper.ts @@ -274,10 +274,17 @@ async function recordOverlayStatus( return; } - const overlayStatus: OverlayStatus = createOverlayStatus({ - attemptedToBuildOverlayBaseDatabase: true, - builtOverlayBaseDatabase: false, - }); + const checkRunIdInput = actionsUtil.getOptionalInput("check-run-id"); + const checkRunId = + checkRunIdInput !== undefined ? parseInt(checkRunIdInput, 10) : undefined; + + const overlayStatus: OverlayStatus = createOverlayStatus( + { + attemptedToBuildOverlayBaseDatabase: true, + builtOverlayBaseDatabase: false, + }, + Number.isNaN(checkRunId) ? undefined : checkRunId, + ); const diskUsage = await checkDiskUsage(logger); if (diskUsage === undefined) { diff --git a/src/overlay/status.ts b/src/overlay/status.ts index 9e6d844edf..73f4260599 100644 --- a/src/overlay/status.ts +++ b/src/overlay/status.ts @@ -45,6 +45,8 @@ function getStatusFilePath(languages: string[]): string { /** Details of the job that recorded an overlay status. */ interface JobInfo { + /** The check run ID. This is optional since it is not always available. */ + checkRunId?: number; /** The workflow run ID. */ workflowRunId: number; /** The workflow run attempt number. */ @@ -66,14 +68,17 @@ export interface OverlayStatus { /** Creates an `OverlayStatus` populated with the details of the current job. */ export function createOverlayStatus( attributes: Omit, + checkRunId?: number, ): OverlayStatus { + const job: JobInfo = { + workflowRunId: getWorkflowRunID(), + workflowRunAttempt: getWorkflowRunAttempt(), + name: getRequiredEnvParam("GITHUB_JOB"), + ...(checkRunId !== undefined && { checkRunId }), + }; return { ...attributes, - job: { - workflowRunId: getWorkflowRunID(), - workflowRunAttempt: getWorkflowRunAttempt(), - name: getRequiredEnvParam("GITHUB_JOB"), - }, + job, }; } From 281b26524519cd6b03046f2a5dfed913c1eb99aa Mon Sep 17 00:00:00 2001 From: Henry Mercer Date: Wed, 4 Mar 2026 12:16:54 +0100 Subject: [PATCH 3/3] Address review comments --- lib/init-action-post.js | 4 ++-- src/init-action-post-helper.test.ts | 1 + src/init-action-post-helper.ts | 2 +- src/overlay/status.ts | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/init-action-post.js b/lib/init-action-post.js index e1b1f04e5c..cd49ab720a 100644 --- a/lib/init-action-post.js +++ b/lib/init-action-post.js @@ -166096,7 +166096,7 @@ function createOverlayStatus(attributes, checkRunId) { workflowRunId: getWorkflowRunID(), workflowRunAttempt: getWorkflowRunAttempt(), name: getRequiredEnvParam("GITHUB_JOB"), - ...checkRunId !== void 0 && { checkRunId } + checkRunId }; return { ...attributes, @@ -170374,7 +170374,7 @@ async function recordOverlayStatus(codeql, config, features, logger) { attemptedToBuildOverlayBaseDatabase: true, builtOverlayBaseDatabase: false }, - Number.isNaN(checkRunId) ? void 0 : checkRunId + checkRunId !== void 0 && checkRunId >= 0 ? checkRunId : void 0 ); const diskUsage = await checkDiskUsage(logger); if (diskUsage === void 0) { diff --git a/src/init-action-post-helper.test.ts b/src/init-action-post-helper.test.ts index 039c96ef75..5bdb674a14 100644 --- a/src/init-action-post-helper.test.ts +++ b/src/init-action-post-helper.test.ts @@ -374,6 +374,7 @@ test("saves overlay status when overlay-base analysis did not complete successfu attemptedToBuildOverlayBaseDatabase: true, builtOverlayBaseDatabase: false, job: { + checkRunId: undefined, workflowRunId: 12345, workflowRunAttempt: 1, name: "analyze", diff --git a/src/init-action-post-helper.ts b/src/init-action-post-helper.ts index b1fb968c07..a8f7a8731d 100644 --- a/src/init-action-post-helper.ts +++ b/src/init-action-post-helper.ts @@ -283,7 +283,7 @@ async function recordOverlayStatus( attemptedToBuildOverlayBaseDatabase: true, builtOverlayBaseDatabase: false, }, - Number.isNaN(checkRunId) ? undefined : checkRunId, + checkRunId !== undefined && checkRunId >= 0 ? checkRunId : undefined, ); const diskUsage = await checkDiskUsage(logger); diff --git a/src/overlay/status.ts b/src/overlay/status.ts index 73f4260599..a57835ed1b 100644 --- a/src/overlay/status.ts +++ b/src/overlay/status.ts @@ -74,7 +74,7 @@ export function createOverlayStatus( workflowRunId: getWorkflowRunID(), workflowRunAttempt: getWorkflowRunAttempt(), name: getRequiredEnvParam("GITHUB_JOB"), - ...(checkRunId !== undefined && { checkRunId }), + checkRunId, }; return { ...attributes,