@@ -19,10 +19,13 @@ import * as uploadLib from "./upload-lib";
1919import {
2020 checkDiskUsage ,
2121 delay ,
22+ Failure ,
2223 getErrorMessage ,
2324 getRequiredEnvParam ,
2425 parseMatrixInput ,
26+ Result ,
2527 shouldSkipSarifUpload ,
28+ Success ,
2629 wrapError ,
2730} from "./util" ;
2831import {
@@ -62,18 +65,27 @@ function createFailedUploadFailedSarifResult(
6265 } ;
6366}
6467
68+ /** Records details about a SARIF file that can contains information about a failed analysis. */
69+ interface FailedSarifInfo {
70+ sarifFile : string ;
71+ category : string | undefined ;
72+ checkoutPath : string ;
73+ }
74+
6575/**
66- * Upload a failed SARIF file if we can verify that SARIF upload is enabled and determine the SARIF
67- * category for the workflow.
76+ * Tries to prepare a SARIF file that can contains information about a failed analysis.
77+ *
78+ * @returns Either information about the SARIF file that was produced, or a reason why it couldn't be produced.
6879 */
69- async function maybeUploadFailedSarif (
70- config : Config ,
71- repositoryNwo : RepositoryNwo ,
72- features : FeatureEnablement ,
80+ async function prepareFailedSarif (
7381 logger : Logger ,
74- ) : Promise < UploadFailedSarifResult > {
82+ features : FeatureEnablement ,
83+ config : Config ,
84+ ) : Promise < Result < FailedSarifInfo , UploadFailedSarifResult > > {
7585 if ( ! config . codeQLCmd ) {
76- return { upload_failed_run_skipped_because : "CodeQL command not found" } ;
86+ return new Failure ( {
87+ upload_failed_run_skipped_because : "CodeQL command not found" ,
88+ } ) ;
7789 }
7890 const workflow = await getWorkflow ( logger ) ;
7991 const jobName = getRequiredEnvParam ( "GITHUB_JOB" ) ;
@@ -85,7 +97,9 @@ async function maybeUploadFailedSarif(
8597 ) ||
8698 shouldSkipSarifUpload ( )
8799 ) {
88- return { upload_failed_run_skipped_because : "SARIF upload is disabled" } ;
100+ return new Failure ( {
101+ upload_failed_run_skipped_because : "SARIF upload is disabled" ,
102+ } ) ;
89103 }
90104 const category = getCategoryInputOrThrow ( workflow , jobName , matrix ) ;
91105 const checkoutPath = getCheckoutPathInputOrThrow ( workflow , jobName , matrix ) ;
@@ -105,11 +119,32 @@ async function maybeUploadFailedSarif(
105119 await codeql . databaseExportDiagnostics ( databasePath , sarifFile , category ) ;
106120 }
107121
108- logger . info ( `Uploading failed SARIF file ${ sarifFile } ` ) ;
122+ return new Success ( { sarifFile, category, checkoutPath } ) ;
123+ }
124+
125+ /**
126+ * Upload a failed SARIF file if we can verify that SARIF upload is enabled and determine the SARIF
127+ * category for the workflow.
128+ */
129+ async function maybeUploadFailedSarif (
130+ config : Config ,
131+ repositoryNwo : RepositoryNwo ,
132+ features : FeatureEnablement ,
133+ logger : Logger ,
134+ ) : Promise < UploadFailedSarifResult > {
135+ const failedSarifResult = await prepareFailedSarif ( logger , features , config ) ;
136+
137+ if ( failedSarifResult . isFailure ( ) ) {
138+ return failedSarifResult . value ;
139+ }
140+
141+ const failedSarif = failedSarifResult . value ;
142+
143+ logger . info ( `Uploading failed SARIF file ${ failedSarif . sarifFile } ` ) ;
109144 const uploadResult = await uploadLib . uploadFiles (
110- sarifFile ,
111- checkoutPath ,
112- category ,
145+ failedSarif . sarifFile ,
146+ failedSarif . checkoutPath ,
147+ failedSarif . category ,
113148 features ,
114149 logger ,
115150 CodeScanning ,
0 commit comments