mirror of
https://github.com/github/codeql-action.git
synced 2026-04-27 01:08:46 +00:00
Merge pull request #3537 from github/henrymercer/overlay-status-record-job
Record the job that published an overlay status
This commit is contained in:
@@ -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,14 @@ 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",
|
||||
},
|
||||
},
|
||||
"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",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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,17 @@ async function recordOverlayStatus(
|
||||
return;
|
||||
}
|
||||
|
||||
const overlayStatus: OverlayStatus = {
|
||||
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,
|
||||
},
|
||||
checkRunId !== undefined && checkRunId >= 0 ? checkRunId : undefined,
|
||||
);
|
||||
|
||||
const diskUsage = await checkDiskUsage(logger);
|
||||
if (diskUsage === undefined) {
|
||||
|
||||
+37
-1
@@ -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,43 @@ 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. */
|
||||
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, "job">,
|
||||
checkRunId?: number,
|
||||
): OverlayStatus {
|
||||
const job: JobInfo = {
|
||||
workflowRunId: getWorkflowRunID(),
|
||||
workflowRunAttempt: getWorkflowRunAttempt(),
|
||||
name: getRequiredEnvParam("GITHUB_JOB"),
|
||||
checkRunId,
|
||||
};
|
||||
return {
|
||||
...attributes,
|
||||
job,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user