@@ -17,17 +17,36 @@ import {
1717} from "./workflow" ;
1818
1919export interface UploadFailedSarifResult {
20- /** Size in bytes of the unzipped SARIF payload uploaded for the failed run. */
20+ /**
21+ * If a SARIF file was uploaded for a failed run, this is the size in bytes of the unzipped
22+ * SARIF payload.
23+ */
2124 upload_failed_run_raw_upload_size_bytes ?: number ;
22- /** Size in bytes of actual SARIF payload uploaded for the failed run. */
25+ /**
26+ * If a SARIF file was uploaded for a failed run, this is the size in bytes of the actual
27+ * zipped payload.
28+ */
2329 upload_failed_run_zipped_upload_size_bytes ?: number ;
2430
25- /** Error encountered during uploading the failed run. */
31+ /** If there was an error while uploading a failed run, this is its message . */
2632 upload_failed_run_error ?: string ;
33+ /** If there was an error while uploading a failed run, this is its stack trace. */
34+ upload_failed_run_stack_trace ?: string ;
2735 /** Reason why we did not upload a SARIF payload with `executionSuccessful: false`. */
2836 upload_failed_run_skipped_because ?: string ;
2937}
3038
39+ function createFailedUploadFailedSarifResult (
40+ error : unknown
41+ ) : UploadFailedSarifResult {
42+ return {
43+ upload_failed_run_error :
44+ error instanceof Error ? error . message : String ( error ) ,
45+ upload_failed_run_stack_trace :
46+ error instanceof Error ? error . stack : undefined ,
47+ } ;
48+ }
49+
3150export async function uploadFailedSarif (
3251 config : Config ,
3352 repositoryNwo : RepositoryNwo ,
@@ -89,31 +108,19 @@ export async function uploadFailedSarif(
89108 } ;
90109}
91110
92- export async function run (
93- uploadDatabaseBundleDebugArtifact : Function ,
94- uploadLogsDebugArtifact : Function ,
95- printDebugLogs : Function ,
111+ export async function uploadSarifIfRunFailed (
112+ config : Config ,
96113 repositoryNwo : RepositoryNwo ,
97114 featureEnablement : FeatureEnablement ,
98115 logger : Logger
99- ) {
100- const config = await getConfig ( actionsUtil . getTemporaryDirectory ( ) , logger ) ;
101- if ( config === undefined ) {
102- logger . warning (
103- "Debugging artifacts are unavailable since the 'init' Action failed before it could produce any."
104- ) ;
105- return ;
106- }
107-
116+ ) : Promise < UploadFailedSarifResult > {
108117 // Environment variable used to integration test uploading a SARIF file for failed runs
109118 const expectFailedSarifUpload =
110119 process . env [ "CODEQL_ACTION_EXPECT_UPLOAD_FAILED_SARIF" ] === "true" ;
111120
112- let uploadFailedSarifResult : UploadFailedSarifResult ;
113-
114121 if ( process . env [ CODEQL_ACTION_ANALYZE_DID_UPLOAD_SARIF ] !== "true" ) {
115122 try {
116- uploadFailedSarifResult = await uploadFailedSarif (
123+ return await uploadFailedSarif (
117124 config ,
118125 repositoryNwo ,
119126 featureEnablement ,
@@ -129,19 +136,41 @@ export async function run(
129136 logger . info (
130137 `Failed to upload a SARIF file for the failed run. Error: ${ e } `
131138 ) ;
132- uploadFailedSarifResult = {
133- upload_failed_run_error : e instanceof Error ? e . message : String ( e ) ,
134- } ;
139+ return createFailedUploadFailedSarifResult ( e ) ;
135140 }
136141 } else if ( expectFailedSarifUpload ) {
137142 throw new Error (
138143 "Expected to upload a SARIF file for the failed run, but didn't."
139144 ) ;
140145 } else {
141- uploadFailedSarifResult = {
146+ return {
142147 upload_failed_run_skipped_because : "SARIF file already uploaded" ,
143148 } ;
144149 }
150+ }
151+
152+ export async function run (
153+ uploadDatabaseBundleDebugArtifact : Function ,
154+ uploadLogsDebugArtifact : Function ,
155+ printDebugLogs : Function ,
156+ repositoryNwo : RepositoryNwo ,
157+ featureEnablement : FeatureEnablement ,
158+ logger : Logger
159+ ) {
160+ const config = await getConfig ( actionsUtil . getTemporaryDirectory ( ) , logger ) ;
161+ if ( config === undefined ) {
162+ logger . warning (
163+ "Debugging artifacts are unavailable since the 'init' Action failed before it could produce any."
164+ ) ;
165+ return ;
166+ }
167+
168+ const uploadFailedSarifResult = await uploadSarifIfRunFailed (
169+ config ,
170+ repositoryNwo ,
171+ featureEnablement ,
172+ logger
173+ ) ;
145174
146175 // Upload appropriate Actions artifacts for debugging
147176 if ( config . debugMode ) {
0 commit comments