@@ -5,6 +5,7 @@ import test from "ava";
55import * as sinon from "sinon" ;
66
77import * as actionsutil from "./actions-util" ;
8+ import * as sharedEnv from "./shared-environment" ;
89import { setupActionsVars , setupTests } from "./testing-utils" ;
910import { initializeEnvironment , withTmpDir } from "./util" ;
1011
@@ -275,3 +276,54 @@ test("workflowEventName()", async (t) => {
275276 process . env [ "CODESCANNING_EVENT_NAME" ] = "push" ;
276277 t . deepEqual ( actionsutil . workflowEventName ( ) , "push" ) ;
277278} ) ;
279+
280+ test ( "createStatusReportBase" , async ( t ) => {
281+ await withTmpDir ( async ( tmpDir : string ) => {
282+ setupActionsVars ( tmpDir , tmpDir ) ;
283+
284+ process . env [ "GITHUB_REF" ] = "refs/heads/main" ;
285+ process . env [ "GITHUB_SHA" ] = "a" . repeat ( 40 ) ;
286+ process . env [ "GITHUB_RUN_ID" ] = "100" ;
287+ process . env [ "GITHUB_RUN_ATTEMPT" ] = "2" ;
288+ process . env [ "GITHUB_REPOSITORY" ] = "octocat/HelloWorld" ;
289+ process . env [ "CODEQL_ACTION_ANALYSIS_KEY" ] = "analysis-key" ;
290+ process . env [ "RUNNER_OS" ] = "macOS" ;
291+
292+ const getRequiredInput = sinon . stub ( actionsutil , "getRequiredInput" ) ;
293+ getRequiredInput . withArgs ( "matrix" ) . resolves ( "input/matrix" ) ;
294+
295+ const statusReport = await actionsutil . createStatusReportBase (
296+ "init" ,
297+ "failure" ,
298+ new Date ( "May 19, 2023 05:19:00" ) ,
299+ "failure cause" ,
300+ "exception stack trace"
301+ ) ;
302+
303+ t . assert ( typeof statusReport . job_run_uuid === "string" ) ;
304+ t . assert ( statusReport . workflow_run_id === 100 ) ;
305+ t . assert ( statusReport . workflow_run_attempt === 2 ) ;
306+ t . assert (
307+ statusReport . workflow_name === ( process . env [ "GITHUB_WORKFLOW" ] || "" )
308+ ) ;
309+ t . assert ( statusReport . job_name === ( process . env [ "GITHUB_JOB" ] || "" ) ) ;
310+ t . assert ( statusReport . analysis_key === "analysis-key" ) ;
311+ t . assert ( statusReport . commit_oid === process . env [ "GITHUB_SHA" ] ) ;
312+ t . assert ( statusReport . ref === process . env [ "GITHUB_REF" ] ) ;
313+ t . assert ( statusReport . action_name === "init" ) ;
314+ t . assert ( statusReport . action_oid === "unknown" ) ;
315+ t . assert (
316+ statusReport . started_at ===
317+ process . env [ sharedEnv . CODEQL_WORKFLOW_STARTED_AT ]
318+ ) ;
319+ t . assert (
320+ statusReport . action_started_at ===
321+ new Date ( "May 19, 2023 05:19:00" ) . toISOString ( )
322+ ) ;
323+ t . assert ( statusReport . status === "failure" ) ;
324+ t . assert ( statusReport . cause === "failure cause" ) ;
325+ t . assert ( statusReport . exception === "exception stack trace" ) ;
326+ t . assert ( statusReport . runner_os === process . env [ "RUNNER_OS" ] ) ;
327+ t . assert ( typeof statusReport . action_version === "string" ) ;
328+ } ) ;
329+ } ) ;
0 commit comments