Add languages to the status report for all jobs

This commit is contained in:
Henry Mercer
2024-02-26 19:03:28 +00:00
parent 905ae4af53
commit 28b564f8c6
30 changed files with 135 additions and 96 deletions

View File

@@ -67,6 +67,7 @@ async function sendStatusReport(
"finish",
status,
startedAt,
config,
await util.checkDiskUsage(),
error?.message,
error?.stack,
@@ -192,6 +193,7 @@ async function run() {
"finish",
"starting",
startedAt,
undefined,
await util.checkDiskUsage(logger),
),
);

View File

@@ -8,7 +8,7 @@ import {
import { getGitHubVersion } from "./api-client";
import { determineAutobuildLanguages, runAutobuild } from "./autobuild";
import { getCodeQL } from "./codeql";
import * as configUtils from "./config-utils";
import { Config, getConfig } from "./config-utils";
import { EnvVar } from "./environment";
import { Language } from "./languages";
import { Logger, getActionsLogger } from "./logging";
@@ -34,6 +34,7 @@ interface AutobuildStatusReport extends StatusReportBase {
}
async function sendCompletedStatusReport(
config: Config | undefined,
logger: Logger,
startedAt: Date,
allLanguages: string[],
@@ -47,6 +48,7 @@ async function sendCompletedStatusReport(
"autobuild",
status,
startedAt,
config,
await checkDiskUsage(logger),
cause?.message,
cause?.stack,
@@ -62,14 +64,16 @@ async function sendCompletedStatusReport(
async function run() {
const startedAt = new Date();
const logger = getActionsLogger();
let currentLanguage: Language | undefined = undefined;
let languages: Language[] | undefined = undefined;
let config: Config | undefined;
let currentLanguage: Language | undefined;
let languages: Language[] | undefined;
try {
await sendStatusReport(
await createStatusReportBase(
"autobuild",
"starting",
startedAt,
undefined,
await checkDiskUsage(logger),
),
);
@@ -78,7 +82,7 @@ async function run() {
checkGitHubVersionInRange(gitHubVersion, logger);
checkActionVersion(getActionVersion(), gitHubVersion);
const config = await configUtils.getConfig(getTemporaryDirectory(), logger);
config = await getConfig(getTemporaryDirectory(), logger);
if (config === undefined) {
throw new Error(
"Config file could not be found at expected location. Has the 'init' action been called?",
@@ -107,6 +111,7 @@ async function run() {
`We were unable to automatically build your code. Please replace the call to the autobuild action with your custom build steps. ${error.message}`,
);
await sendCompletedStatusReport(
config,
logger,
startedAt,
languages ?? [],
@@ -118,7 +123,7 @@ async function run() {
core.exportVariable(EnvVar.AUTOBUILD_DID_COMPLETE_SUCCESSFULLY, "true");
await sendCompletedStatusReport(logger, startedAt, languages ?? []);
await sendCompletedStatusReport(config, logger, startedAt, languages ?? []);
}
async function runWrapper() {

View File

@@ -8,7 +8,12 @@ import { Feature } from "./feature-flags";
import * as initActionPostHelper from "./init-action-post-helper";
import { getRunnerLogger } from "./logging";
import { parseRepositoryNwo } from "./repository";
import { createFeatures, makeVersionInfo, setupTests } from "./testing-utils";
import {
createFeatures,
createTestConfig,
makeVersionInfo,
setupTests,
} from "./testing-utils";
import * as uploadLib from "./upload-lib";
import * as util from "./util";
import * as workflow from "./workflow";
@@ -38,6 +43,7 @@ test("post: init action with debug mode off", async (t) => {
uploadDatabaseBundleSpy,
uploadLogsSpy,
printDebugLogsSpy,
createTestConfig({ debugMode: false }),
parseRepositoryNwo("github/codeql-action"),
createFeatures([]),
getRunnerLogger(true),
@@ -54,16 +60,6 @@ test("post: init action with debug mode on", async (t) => {
process.env["GITHUB_REPOSITORY"] = "github/codeql-action-fake-repository";
process.env["RUNNER_TEMP"] = tmpDir;
const gitHubVersion: util.GitHubVersion = {
type: util.GitHubVariant.DOTCOM,
};
sinon.stub(configUtils, "getConfig").resolves({
debugMode: true,
gitHubVersion,
languages: [],
packs: [],
} as unknown as configUtils.Config);
const uploadDatabaseBundleSpy = sinon.spy();
const uploadLogsSpy = sinon.spy();
const printDebugLogsSpy = sinon.spy();
@@ -72,6 +68,7 @@ test("post: init action with debug mode on", async (t) => {
uploadDatabaseBundleSpy,
uploadLogsSpy,
printDebugLogsSpy,
createTestConfig({ debugMode: true }),
parseRepositoryNwo("github/codeql-action"),
createFeatures([]),
getRunnerLogger(true),

View File

@@ -4,7 +4,7 @@ import * as github from "@actions/github";
import * as actionsUtil from "./actions-util";
import { getApiClient } from "./api-client";
import { getCodeQL } from "./codeql";
import { Config, getConfig } from "./config-utils";
import { Config } from "./config-utils";
import { EnvVar } from "./environment";
import { Feature, FeatureEnablement } from "./feature-flags";
import { Logger } from "./logging";
@@ -165,18 +165,11 @@ export async function run(
uploadDatabaseBundleDebugArtifact: Function,
uploadLogsDebugArtifact: Function,
printDebugLogs: Function,
config: Config,
repositoryNwo: RepositoryNwo,
features: FeatureEnablement,
logger: Logger,
) {
const config = await getConfig(actionsUtil.getTemporaryDirectory(), logger);
if (config === undefined) {
logger.warning(
"Debugging artifacts are unavailable since the 'init' Action failed before it could produce any.",
);
return;
}
const uploadFailedSarifResult = await tryUploadSarifIfRunFailed(
config,
repositoryNwo,

View File

@@ -8,6 +8,7 @@ import * as core from "@actions/core";
import { getTemporaryDirectory, printDebugLogs } from "./actions-util";
import { getGitHubVersion } from "./api-client";
import { Config, getConfig } from "./config-utils";
import * as debugArtifacts from "./debug-artifacts";
import { Features } from "./feature-flags";
import * as initActionPostHelper from "./init-action-post-helper";
@@ -33,6 +34,7 @@ interface InitPostStatusReport
async function runWrapper() {
const startedAt = new Date();
let config: Config | undefined;
let uploadFailedSarifResult:
| initActionPostHelper.UploadFailedSarifResult
| undefined;
@@ -51,10 +53,19 @@ async function runWrapper() {
logger,
);
config = await getConfig(getTemporaryDirectory(), logger);
if (config === undefined) {
logger.warning(
"Debugging artifacts are unavailable since the 'init' Action failed before it could produce any.",
);
return;
}
uploadFailedSarifResult = await initActionPostHelper.run(
debugArtifacts.uploadDatabaseBundleDebugArtifact,
debugArtifacts.uploadLogsDebugArtifact,
printDebugLogs,
config,
repositoryNwo,
features,
logger,
@@ -68,6 +79,7 @@ async function runWrapper() {
"init-post",
getActionsStatus(error),
startedAt,
config,
await checkDiskUsage(),
error.message,
error.stack,
@@ -79,6 +91,7 @@ async function runWrapper() {
"init-post",
"success",
startedAt,
config,
await checkDiskUsage(),
);
const statusReport: InitPostStatusReport = {

View File

@@ -74,12 +74,6 @@ interface InitStatusReport extends StatusReportBase {
interface InitWithConfigStatusReport extends InitStatusReport {
/** Comma-separated list of languages where the default queries are disabled. */
disable_default_queries: string;
/**
* Comma-separated list of languages that analysis was run for.
*
* This may be from the workflow file or may be calculated from repository contents
*/
languages: string;
/** Comma-separated list of paths, from the 'paths' config field. */
paths: string;
/** Comma-separated list of paths, from the 'paths-ignore' config field. */
@@ -118,6 +112,7 @@ async function sendCompletedStatusReport(
"init",
getActionsStatus(error),
startedAt,
undefined,
await checkDiskUsage(logger),
error?.message,
error?.stack,
@@ -197,7 +192,7 @@ async function run() {
const logger = getActionsLogger();
initializeEnvironment(getActionVersion());
let config: configUtils.Config;
let config: configUtils.Config | undefined;
let codeql: CodeQL;
let toolsDownloadDurationMs: number | undefined;
let toolsFeatureFlagsValid: boolean | undefined;
@@ -235,6 +230,7 @@ async function run() {
"init",
"starting",
startedAt,
undefined,
await checkDiskUsage(logger),
),
);
@@ -317,6 +313,7 @@ async function run() {
"init",
error instanceof ConfigurationError ? "user-error" : "aborted",
startedAt,
config,
await checkDiskUsage(),
error.message,
error.stack,

View File

@@ -8,7 +8,7 @@ import {
} from "./actions-util";
import { getGitHubVersion } from "./api-client";
import { CommandInvocationError } from "./cli-errors";
import * as configUtils from "./config-utils";
import { Config, getConfig } from "./config-utils";
import { getActionsLogger } from "./logging";
import { runResolveBuildEnvironment } from "./resolve-environment";
import {
@@ -31,12 +31,15 @@ async function run() {
const startedAt = new Date();
const logger = getActionsLogger();
let config: Config | undefined;
try {
await sendStatusReport(
await createStatusReportBase(
ACTION_NAME,
"starting",
startedAt,
undefined,
await checkDiskUsage(logger),
),
);
@@ -45,7 +48,7 @@ async function run() {
checkGitHubVersionInRange(gitHubVersion, logger);
checkActionVersion(getActionVersion(), gitHubVersion);
const config = await configUtils.getConfig(getTemporaryDirectory(), logger);
config = await getConfig(getTemporaryDirectory(), logger);
if (config === undefined) {
throw new Error(
"Config file could not be found at expected location. Has the 'init' action been called?",
@@ -81,6 +84,7 @@ async function run() {
ACTION_NAME,
getActionsStatus(error),
startedAt,
config,
await checkDiskUsage(),
error.message,
error.stack,
@@ -96,6 +100,7 @@ async function run() {
ACTION_NAME,
"success",
startedAt,
config,
await checkDiskUsage(),
),
);

View File

@@ -3,8 +3,13 @@ import * as sinon from "sinon";
import * as actionsUtil from "./actions-util";
import { EnvVar } from "./environment";
import { Language } from "./languages";
import { createStatusReportBase } from "./status-report";
import { setupTests, setupActionsVars } from "./testing-utils";
import {
setupTests,
setupActionsVars,
createTestConfig,
} from "./testing-utils";
import { withTmpDir } from "./util";
setupTests(test);
@@ -34,6 +39,7 @@ test("createStatusReportBase", async (t) => {
"init",
"failure",
new Date("May 19, 2023 05:19:00"),
createTestConfig({ languages: [Language.java, Language.swift] }),
{ numAvailableBytes: 100, numTotalBytes: 500 },
"failure cause",
"exception stack trace",
@@ -52,6 +58,7 @@ test("createStatusReportBase", async (t) => {
t.is(statusReport.exception, "exception stack trace");
t.is(statusReport.job_name, process.env["GITHUB_JOB"] || "");
t.is(typeof statusReport.job_run_uuid, "string");
t.is(statusReport.languages, "java swift");
t.is(statusReport.ref, process.env["GITHUB_REF"]!);
t.is(statusReport.runner_available_disk_space_bytes, 100);
t.is(statusReport.runner_image_version, process.env["ImageVersion"]);
@@ -74,6 +81,7 @@ test("createStatusReportBase_firstParty", async (t) => {
"upload-sarif",
"failure",
new Date("May 19, 2023 05:19:00"),
createTestConfig({}),
{ numAvailableBytes: 100, numTotalBytes: 500 },
"failure cause",
"exception stack trace",
@@ -88,6 +96,7 @@ test("createStatusReportBase_firstParty", async (t) => {
"autobuild",
"failure",
new Date("May 19, 2023 05:19:00"),
createTestConfig({}),
{ numAvailableBytes: 100, numTotalBytes: 500 },
"failure cause",
"exception stack trace",
@@ -103,6 +112,7 @@ test("createStatusReportBase_firstParty", async (t) => {
"upload-sarif",
"failure",
new Date("May 19, 2023 05:19:00"),
createTestConfig({}),
{ numAvailableBytes: 100, numTotalBytes: 500 },
"failure cause",
"exception stack trace",
@@ -117,6 +127,7 @@ test("createStatusReportBase_firstParty", async (t) => {
"init",
"failure",
new Date("May 19, 2023 05:19:00"),
createTestConfig({}),
{ numAvailableBytes: 100, numTotalBytes: 500 },
"failure cause",
"exception stack trace",
@@ -132,6 +143,7 @@ test("createStatusReportBase_firstParty", async (t) => {
"upload-sarif",
"failure",
new Date("May 19, 2023 05:19:00"),
createTestConfig({}),
{ numAvailableBytes: 100, numTotalBytes: 500 },
"failure cause",
"exception stack trace",
@@ -146,6 +158,7 @@ test("createStatusReportBase_firstParty", async (t) => {
"finish",
"failure",
new Date("May 19, 2023 05:19:00"),
createTestConfig({}),
{ numAvailableBytes: 100, numTotalBytes: 500 },
"failure cause",
"exception stack trace",

View File

@@ -14,6 +14,7 @@ import {
ActionName,
} from "./actions-util";
import { getAnalysisKey, getApiClient } from "./api-client";
import { Config } from "./config-utils";
import { EnvVar } from "./environment";
import {
ConfigurationError,
@@ -79,6 +80,12 @@ export interface StatusReportBase {
* telemetry tables.
*/
job_run_uuid: string;
/**
* Comma-separated list of languages that analysis was run for.
*
* This may be from the workflow file or may be calculated from the contents of the repository.
*/
languages?: string;
/** Value of the matrix for this instantiation of the job. */
matrix_vars?: string;
/**
@@ -188,6 +195,7 @@ export async function createStatusReportBase(
actionName: ActionName,
status: ActionStatus,
actionStartedAt: Date,
config: Config | undefined,
diskInfo: DiskUsage | undefined,
cause?: string,
exception?: string,
@@ -236,6 +244,10 @@ export async function createStatusReportBase(
workflow_run_id: workflowRunID,
};
if (config) {
statusReport.languages = config.languages.join(" ");
}
if (diskInfo) {
statusReport.runner_available_disk_space_bytes = diskInfo.numAvailableBytes;
statusReport.runner_total_disk_space_bytes = diskInfo.numTotalBytes;

View File

@@ -33,6 +33,7 @@ async function sendSuccessStatusReport(
"upload-sarif",
"success",
startedAt,
undefined,
await checkDiskUsage(),
);
const statusReport: UploadSarifStatusReport = {
@@ -55,6 +56,7 @@ async function run() {
"upload-sarif",
"starting",
startedAt,
undefined,
await checkDiskUsage(),
),
);
@@ -90,6 +92,7 @@ async function run() {
"upload-sarif",
getActionsStatus(error),
startedAt,
undefined,
await checkDiskUsage(),
message,
error.stack,