Send job_run_uuid to status report telemetry (#1685)
This commit is contained in:
parent
8ba77ef4d3
commit
4385ad5563
12 changed files with 126 additions and 11 deletions
10
lib/actions-util.js
generated
10
lib/actions-util.js
generated
|
|
@ -42,9 +42,9 @@ const pkg = require("../package.json");
|
|||
*
|
||||
* This allows us to get stronger type checking of required/optional inputs.
|
||||
*/
|
||||
function getRequiredInput(name) {
|
||||
const getRequiredInput = function (name) {
|
||||
return core.getInput(name, { required: true });
|
||||
}
|
||||
};
|
||||
exports.getRequiredInput = getRequiredInput;
|
||||
/**
|
||||
* Wrapper around core.getInput that converts empty inputs to undefined.
|
||||
|
|
@ -172,7 +172,7 @@ async function getAnalysisKey() {
|
|||
exports.getAnalysisKey = getAnalysisKey;
|
||||
async function getAutomationID() {
|
||||
const analysis_key = await getAnalysisKey();
|
||||
const environment = getRequiredInput("matrix");
|
||||
const environment = (0, exports.getRequiredInput)("matrix");
|
||||
return computeAutomationID(analysis_key, environment);
|
||||
}
|
||||
exports.getAutomationID = getAutomationID;
|
||||
|
|
@ -290,6 +290,7 @@ exports.getActionVersion = getActionVersion;
|
|||
async function createStatusReportBase(actionName, status, actionStartedAt, cause, exception) {
|
||||
const commitOid = (0, exports.getOptionalInput)("sha") || process.env["GITHUB_SHA"] || "";
|
||||
const ref = await getRef();
|
||||
const jobRunUUID = process.env[sharedEnv.JOB_RUN_UUID] || "";
|
||||
const workflowRunID = (0, workflow_1.getWorkflowRunID)();
|
||||
const workflowRunAttempt = (0, workflow_1.getWorkflowRunAttempt)();
|
||||
const workflowName = process.env["GITHUB_WORKFLOW"] || "";
|
||||
|
|
@ -310,6 +311,7 @@ async function createStatusReportBase(actionName, status, actionStartedAt, cause
|
|||
core.exportVariable(sharedEnv.CODEQL_ACTION_TESTING_ENVIRONMENT, testingEnvironment);
|
||||
}
|
||||
const statusReport = {
|
||||
job_run_uuid: jobRunUUID,
|
||||
workflow_run_id: workflowRunID,
|
||||
workflow_run_attempt: workflowRunAttempt,
|
||||
workflow_name: workflowName,
|
||||
|
|
@ -340,7 +342,7 @@ async function createStatusReportBase(actionName, status, actionStartedAt, cause
|
|||
status === "user-error") {
|
||||
statusReport.completed_at = new Date().toISOString();
|
||||
}
|
||||
const matrix = getRequiredInput("matrix");
|
||||
const matrix = (0, exports.getRequiredInput)("matrix");
|
||||
if (matrix) {
|
||||
statusReport.matrix_vars = matrix;
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
35
lib/actions-util.test.js
generated
35
lib/actions-util.test.js
generated
|
|
@ -31,6 +31,7 @@ const path = __importStar(require("path"));
|
|||
const ava_1 = __importDefault(require("ava"));
|
||||
const sinon = __importStar(require("sinon"));
|
||||
const actionsutil = __importStar(require("./actions-util"));
|
||||
const sharedEnv = __importStar(require("./shared-environment"));
|
||||
const testing_utils_1 = require("./testing-utils");
|
||||
const util_1 = require("./util");
|
||||
(0, testing_utils_1.setupTests)(ava_1.default);
|
||||
|
|
@ -211,4 +212,38 @@ const util_1 = require("./util");
|
|||
getAdditionalInputStub.restore();
|
||||
});
|
||||
});
|
||||
(0, ava_1.default)("createStatusReportBase", async (t) => {
|
||||
await (0, util_1.withTmpDir)(async (tmpDir) => {
|
||||
(0, testing_utils_1.setupActionsVars)(tmpDir, tmpDir);
|
||||
process.env["GITHUB_REF"] = "refs/heads/main";
|
||||
process.env["GITHUB_SHA"] = "a".repeat(40);
|
||||
process.env["GITHUB_RUN_ID"] = "100";
|
||||
process.env["GITHUB_RUN_ATTEMPT"] = "2";
|
||||
process.env["GITHUB_REPOSITORY"] = "octocat/HelloWorld";
|
||||
process.env["CODEQL_ACTION_ANALYSIS_KEY"] = "analysis-key";
|
||||
process.env["RUNNER_OS"] = "macOS";
|
||||
const getRequiredInput = sinon.stub(actionsutil, "getRequiredInput");
|
||||
getRequiredInput.withArgs("matrix").resolves("input/matrix");
|
||||
const statusReport = await actionsutil.createStatusReportBase("init", "failure", new Date("May 19, 2023 05:19:00"), "failure cause", "exception stack trace");
|
||||
t.assert(typeof statusReport.job_run_uuid === "string");
|
||||
t.assert(statusReport.workflow_run_id === 100);
|
||||
t.assert(statusReport.workflow_run_attempt === 2);
|
||||
t.assert(statusReport.workflow_name === (process.env["GITHUB_WORKFLOW"] || ""));
|
||||
t.assert(statusReport.job_name === (process.env["GITHUB_JOB"] || ""));
|
||||
t.assert(statusReport.analysis_key === "analysis-key");
|
||||
t.assert(statusReport.commit_oid === process.env["GITHUB_SHA"]);
|
||||
t.assert(statusReport.ref === process.env["GITHUB_REF"]);
|
||||
t.assert(statusReport.action_name === "init");
|
||||
t.assert(statusReport.action_oid === "unknown");
|
||||
t.assert(statusReport.started_at ===
|
||||
process.env[sharedEnv.CODEQL_WORKFLOW_STARTED_AT]);
|
||||
t.assert(statusReport.action_started_at ===
|
||||
new Date("May 19, 2023 05:19:00").toISOString());
|
||||
t.assert(statusReport.status === "failure");
|
||||
t.assert(statusReport.cause === "failure cause");
|
||||
t.assert(statusReport.exception === "exception stack trace");
|
||||
t.assert(statusReport.runner_os === process.env["RUNNER_OS"]);
|
||||
t.assert(typeof statusReport.action_version === "string");
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=actions-util.test.js.map
|
||||
File diff suppressed because one or more lines are too long
3
lib/init-action.js
generated
3
lib/init-action.js
generated
|
|
@ -25,6 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const path = __importStar(require("path"));
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const uuid_1 = require("uuid");
|
||||
const actions_util_1 = require("./actions-util");
|
||||
const api_client_1 = require("./api-client");
|
||||
const feature_flags_1 = require("./feature-flags");
|
||||
|
|
@ -32,6 +33,7 @@ const init_1 = require("./init");
|
|||
const languages_1 = require("./languages");
|
||||
const logging_1 = require("./logging");
|
||||
const repository_1 = require("./repository");
|
||||
const sharedEnv = __importStar(require("./shared-environment"));
|
||||
const trap_caching_1 = require("./trap-caching");
|
||||
const util_1 = require("./util");
|
||||
const workflow_1 = require("./workflow");
|
||||
|
|
@ -114,6 +116,7 @@ async function run() {
|
|||
const repositoryNwo = (0, repository_1.parseRepositoryNwo)((0, util_1.getRequiredEnvParam)("GITHUB_REPOSITORY"));
|
||||
const registriesInput = (0, actions_util_1.getOptionalInput)("registries");
|
||||
const features = new feature_flags_1.Features(gitHubVersion, repositoryNwo, (0, actions_util_1.getTemporaryDirectory)(), logger);
|
||||
core.exportVariable(sharedEnv.JOB_RUN_UUID, (0, uuid_1.v4)());
|
||||
try {
|
||||
const workflowErrors = await (0, workflow_1.validateWorkflow)(logger);
|
||||
if (!(await (0, actions_util_1.sendStatusReport)(await (0, actions_util_1.createStatusReportBase)("init", "starting", startedAt, workflowErrors)))) {
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
4
lib/shared-environment.js
generated
4
lib/shared-environment.js
generated
|
|
@ -1,6 +1,6 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ODASA_TRACER_CONFIGURATION = exports.CODEQL_WORKFLOW_STARTED_AT = exports.CODEQL_ACTION_DISABLE_DUPLICATE_LOCATION_FIX = exports.CODEQL_ACTION_TEST_MODE = exports.CODEQL_ACTION_TESTING_ENVIRONMENT = exports.CODEQL_ACTION_ANALYZE_DID_COMPLETE_SUCCESSFULLY = exports.CODEQL_ACTION_DID_AUTOBUILD_GOLANG = exports.EnvVar = void 0;
|
||||
exports.JOB_RUN_UUID = exports.ODASA_TRACER_CONFIGURATION = exports.CODEQL_WORKFLOW_STARTED_AT = exports.CODEQL_ACTION_DISABLE_DUPLICATE_LOCATION_FIX = exports.CODEQL_ACTION_TEST_MODE = exports.CODEQL_ACTION_TESTING_ENVIRONMENT = exports.CODEQL_ACTION_ANALYZE_DID_COMPLETE_SUCCESSFULLY = exports.CODEQL_ACTION_DID_AUTOBUILD_GOLANG = exports.EnvVar = void 0;
|
||||
/**
|
||||
* Environment variables to be set by codeql-action and used by the
|
||||
* CLI.
|
||||
|
|
@ -60,4 +60,6 @@ exports.CODEQL_ACTION_DISABLE_DUPLICATE_LOCATION_FIX = "CODEQL_ACTION_DISABLE_DU
|
|||
*/
|
||||
exports.CODEQL_WORKFLOW_STARTED_AT = "CODEQL_WORKFLOW_STARTED_AT";
|
||||
exports.ODASA_TRACER_CONFIGURATION = "ODASA_TRACER_CONFIGURATION";
|
||||
/** UUID representing the current job run. */
|
||||
exports.JOB_RUN_UUID = "JOB_RUN_UUID";
|
||||
//# sourceMappingURL=shared-environment.js.map
|
||||
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"shared-environment.js","sourceRoot":"","sources":["../src/shared-environment.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,IAAY,MA8BX;AA9BD,WAAY,MAAM;IAChB;;OAEG;IACH,2CAAiC,CAAA;IAEjC;;;OAGG;IACH,uEAA6D,CAAA;IAE7D;;;OAGG;IACH,mEAAyD,CAAA;IAEzD;;;;OAIG;IACH,yEAA+D,CAAA;IAE/D;;;OAGG;IACH,6DAAmD,CAAA;AACrD,CAAC,EA9BW,MAAM,GAAN,cAAM,KAAN,cAAM,QA8BjB;AAED;;;GAGG;AACU,QAAA,kCAAkC,GAC7C,oCAAoC,CAAC;AAEvC;;;GAGG;AACU,QAAA,+CAA+C,GAC1D,iDAAiD,CAAC;AAEvC,QAAA,iCAAiC,GAC5C,mCAAmC,CAAC;AAEtC,kFAAkF;AACrE,QAAA,uBAAuB,GAAG,yBAAyB,CAAC;AAEjE;;;GAGG;AACU,QAAA,4CAA4C,GACvD,8CAA8C,CAAC;AAEjD;;;;;;GAMG;AACU,QAAA,0BAA0B,GAAG,4BAA4B,CAAC;AAE1D,QAAA,0BAA0B,GAAG,4BAA4B,CAAC"}
|
||||
{"version":3,"file":"shared-environment.js","sourceRoot":"","sources":["../src/shared-environment.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,IAAY,MA8BX;AA9BD,WAAY,MAAM;IAChB;;OAEG;IACH,2CAAiC,CAAA;IAEjC;;;OAGG;IACH,uEAA6D,CAAA;IAE7D;;;OAGG;IACH,mEAAyD,CAAA;IAEzD;;;;OAIG;IACH,yEAA+D,CAAA;IAE/D;;;OAGG;IACH,6DAAmD,CAAA;AACrD,CAAC,EA9BW,MAAM,GAAN,cAAM,KAAN,cAAM,QA8BjB;AAED;;;GAGG;AACU,QAAA,kCAAkC,GAC7C,oCAAoC,CAAC;AAEvC;;;GAGG;AACU,QAAA,+CAA+C,GAC1D,iDAAiD,CAAC;AAEvC,QAAA,iCAAiC,GAC5C,mCAAmC,CAAC;AAEtC,kFAAkF;AACrE,QAAA,uBAAuB,GAAG,yBAAyB,CAAC;AAEjE;;;GAGG;AACU,QAAA,4CAA4C,GACvD,8CAA8C,CAAC;AAEjD;;;;;;GAMG;AACU,QAAA,0BAA0B,GAAG,4BAA4B,CAAC;AAE1D,QAAA,0BAA0B,GAAG,4BAA4B,CAAC;AAEvE,6CAA6C;AAChC,QAAA,YAAY,GAAG,cAAc,CAAC"}
|
||||
|
|
@ -5,6 +5,7 @@ import test from "ava";
|
|||
import * as sinon from "sinon";
|
||||
|
||||
import * as actionsutil from "./actions-util";
|
||||
import * as sharedEnv from "./shared-environment";
|
||||
import { setupActionsVars, setupTests } from "./testing-utils";
|
||||
import { initializeEnvironment, withTmpDir } from "./util";
|
||||
|
||||
|
|
@ -265,3 +266,54 @@ test("isAnalyzingDefaultBranch()", async (t) => {
|
|||
getAdditionalInputStub.restore();
|
||||
});
|
||||
});
|
||||
|
||||
test("createStatusReportBase", async (t) => {
|
||||
await withTmpDir(async (tmpDir: string) => {
|
||||
setupActionsVars(tmpDir, tmpDir);
|
||||
|
||||
process.env["GITHUB_REF"] = "refs/heads/main";
|
||||
process.env["GITHUB_SHA"] = "a".repeat(40);
|
||||
process.env["GITHUB_RUN_ID"] = "100";
|
||||
process.env["GITHUB_RUN_ATTEMPT"] = "2";
|
||||
process.env["GITHUB_REPOSITORY"] = "octocat/HelloWorld";
|
||||
process.env["CODEQL_ACTION_ANALYSIS_KEY"] = "analysis-key";
|
||||
process.env["RUNNER_OS"] = "macOS";
|
||||
|
||||
const getRequiredInput = sinon.stub(actionsutil, "getRequiredInput");
|
||||
getRequiredInput.withArgs("matrix").resolves("input/matrix");
|
||||
|
||||
const statusReport = await actionsutil.createStatusReportBase(
|
||||
"init",
|
||||
"failure",
|
||||
new Date("May 19, 2023 05:19:00"),
|
||||
"failure cause",
|
||||
"exception stack trace"
|
||||
);
|
||||
|
||||
t.assert(typeof statusReport.job_run_uuid === "string");
|
||||
t.assert(statusReport.workflow_run_id === 100);
|
||||
t.assert(statusReport.workflow_run_attempt === 2);
|
||||
t.assert(
|
||||
statusReport.workflow_name === (process.env["GITHUB_WORKFLOW"] || "")
|
||||
);
|
||||
t.assert(statusReport.job_name === (process.env["GITHUB_JOB"] || ""));
|
||||
t.assert(statusReport.analysis_key === "analysis-key");
|
||||
t.assert(statusReport.commit_oid === process.env["GITHUB_SHA"]);
|
||||
t.assert(statusReport.ref === process.env["GITHUB_REF"]);
|
||||
t.assert(statusReport.action_name === "init");
|
||||
t.assert(statusReport.action_oid === "unknown");
|
||||
t.assert(
|
||||
statusReport.started_at ===
|
||||
process.env[sharedEnv.CODEQL_WORKFLOW_STARTED_AT]
|
||||
);
|
||||
t.assert(
|
||||
statusReport.action_started_at ===
|
||||
new Date("May 19, 2023 05:19:00").toISOString()
|
||||
);
|
||||
t.assert(statusReport.status === "failure");
|
||||
t.assert(statusReport.cause === "failure cause");
|
||||
t.assert(statusReport.exception === "exception stack trace");
|
||||
t.assert(statusReport.runner_os === process.env["RUNNER_OS"]);
|
||||
t.assert(typeof statusReport.action_version === "string");
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -36,9 +36,9 @@ const pkg = require("../package.json") as JSONSchemaForNPMPackageJsonFiles;
|
|||
*
|
||||
* This allows us to get stronger type checking of required/optional inputs.
|
||||
*/
|
||||
export function getRequiredInput(name: string): string {
|
||||
export const getRequiredInput = function (name: string): string {
|
||||
return core.getInput(name, { required: true });
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Wrapper around core.getInput that converts empty inputs to undefined.
|
||||
|
|
@ -316,6 +316,18 @@ export type ActionStatus =
|
|||
| "user-error";
|
||||
|
||||
export interface StatusReportBase {
|
||||
/**
|
||||
* UUID representing the job run that this status report belongs to. We
|
||||
* generate our own UUID here because Actions currently does not expose a
|
||||
* unique job run identifier. This UUID will allow us to more easily match
|
||||
* reports from different steps in the same workflow job.
|
||||
*
|
||||
* If and when Actions does expose a unique job ID, we plan to populate a
|
||||
* separate int field, `job_run_id`, with the Actions-generated identifier,
|
||||
* as it will allow us to more easily join our telemetry data with Actions
|
||||
* telemetry tables.
|
||||
*/
|
||||
job_run_uuid: string;
|
||||
/** ID of the workflow run containing the action run. */
|
||||
workflow_run_id: number;
|
||||
/** Attempt number of the run containing the action run. */
|
||||
|
|
@ -412,6 +424,7 @@ export async function createStatusReportBase(
|
|||
): Promise<StatusReportBase> {
|
||||
const commitOid = getOptionalInput("sha") || process.env["GITHUB_SHA"] || "";
|
||||
const ref = await getRef();
|
||||
const jobRunUUID = process.env[sharedEnv.JOB_RUN_UUID] || "";
|
||||
const workflowRunID = getWorkflowRunID();
|
||||
const workflowRunAttempt = getWorkflowRunAttempt();
|
||||
const workflowName = process.env["GITHUB_WORKFLOW"] || "";
|
||||
|
|
@ -440,6 +453,7 @@ export async function createStatusReportBase(
|
|||
}
|
||||
|
||||
const statusReport: StatusReportBase = {
|
||||
job_run_uuid: jobRunUUID,
|
||||
workflow_run_id: workflowRunID,
|
||||
workflow_run_attempt: workflowRunAttempt,
|
||||
workflow_name: workflowName,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import * as path from "path";
|
||||
|
||||
import * as core from "@actions/core";
|
||||
import { v4 as uuidV4 } from "uuid";
|
||||
|
||||
import {
|
||||
createStatusReportBase,
|
||||
|
|
@ -26,6 +27,7 @@ import {
|
|||
import { Language } from "./languages";
|
||||
import { getActionsLogger, Logger } from "./logging";
|
||||
import { parseRepositoryNwo } from "./repository";
|
||||
import * as sharedEnv from "./shared-environment";
|
||||
import { getTotalCacheSize } from "./trap-caching";
|
||||
import {
|
||||
checkForTimeout,
|
||||
|
|
@ -212,6 +214,8 @@ async function run() {
|
|||
logger
|
||||
);
|
||||
|
||||
core.exportVariable(sharedEnv.JOB_RUN_UUID, uuidV4());
|
||||
|
||||
try {
|
||||
const workflowErrors = await validateWorkflow(logger);
|
||||
|
||||
|
|
|
|||
|
|
@ -71,3 +71,6 @@ export const CODEQL_ACTION_DISABLE_DUPLICATE_LOCATION_FIX =
|
|||
export const CODEQL_WORKFLOW_STARTED_AT = "CODEQL_WORKFLOW_STARTED_AT";
|
||||
|
||||
export const ODASA_TRACER_CONFIGURATION = "ODASA_TRACER_CONFIGURATION";
|
||||
|
||||
/** UUID representing the current job run. */
|
||||
export const JOB_RUN_UUID = "JOB_RUN_UUID";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue