@@ -18,6 +18,7 @@ import {
1818 doesDirectoryExist ,
1919 getCodeQLDatabasePath ,
2020 listFolder ,
21+ wrapError ,
2122} from "./util" ;
2223
2324export function sanitizeArifactName ( name : string ) : string {
@@ -65,34 +66,70 @@ export async function uploadCombinedSarifArtifacts() {
6566 }
6667}
6768
68- export async function uploadAllAvailableDebugArtifacts (
69+ function tryGetSarifResultPath (
6970 config : Config ,
71+ language : Language ,
7072 logger : Logger ,
71- ) {
72- const filesToUpload : string [ ] = [ ] ;
73-
74- const analyzeActionOutputDir = process . env [ EnvVar . SARIF_RESULTS_OUTPUT_DIR ] ;
75- for ( const lang of config . languages ) {
76- // Add any SARIF files, if they exist
73+ ) : string [ ] {
74+ try {
75+ const analyzeActionOutputDir = process . env [ EnvVar . SARIF_RESULTS_OUTPUT_DIR ] ;
7776 if (
7877 analyzeActionOutputDir !== undefined &&
7978 fs . existsSync ( analyzeActionOutputDir ) &&
8079 fs . lstatSync ( analyzeActionOutputDir ) . isDirectory ( )
8180 ) {
82- const sarifFile = path . resolve ( analyzeActionOutputDir , `${ lang } .sarif` ) ;
81+ const sarifFile = path . resolve (
82+ analyzeActionOutputDir ,
83+ `${ language } .sarif` ,
84+ ) ;
8385 // Move SARIF to DB location so that they can be uploaded with the same root directory as the other artifacts.
8486 if ( fs . existsSync ( sarifFile ) ) {
8587 const sarifInDbLocation = path . resolve (
8688 config . dbLocation ,
87- `${ lang } .sarif` ,
89+ `${ language } .sarif` ,
8890 ) ;
8991 fs . copyFileSync ( sarifFile , sarifInDbLocation ) ;
90- filesToUpload . push ( sarifInDbLocation ) ;
92+ return [ sarifInDbLocation ] ;
9193 }
9294 }
95+ } catch ( e ) {
96+ logger . warning (
97+ `Failed to find SARIF results path for ${ language } . ${ wrapError ( e ) } ` ,
98+ ) ;
99+ }
100+ return [ ] ;
101+ }
102+
103+ async function tryBundleDatabase (
104+ config : Config ,
105+ language : Language ,
106+ logger : Logger ,
107+ ) : Promise < string [ ] > {
108+ try {
109+ if ( ! dbIsFinalized ( config , language , logger ) ) {
110+ return [ await createPartialDatabaseBundle ( config , language ) ] ;
111+ } else {
112+ return [ await createDatabaseBundleCli ( config , language ) ] ;
113+ }
114+ } catch ( e ) {
115+ logger . warning (
116+ `Failed to bundle database for ${ language } . ${ wrapError ( e ) } ` ,
117+ ) ;
118+ return [ ] ;
119+ }
120+ }
121+
122+ export async function uploadAllAvailableDebugArtifacts (
123+ config : Config ,
124+ logger : Logger ,
125+ ) {
126+ const filesToUpload : string [ ] = [ ] ;
127+
128+ for ( const language of config . languages ) {
129+ filesToUpload . push ( ...tryGetSarifResultPath ( config , language , logger ) ) ;
93130
94131 // Add any log files
95- const databaseDirectory = getCodeQLDatabasePath ( config , lang ) ;
132+ const databaseDirectory = getCodeQLDatabasePath ( config , language ) ;
96133 const logsDirectory = path . resolve ( databaseDirectory , "log" ) ;
97134 if ( doesDirectoryExist ( logsDirectory ) ) {
98135 filesToUpload . push ( ...listFolder ( logsDirectory ) ) ;
@@ -108,13 +145,7 @@ export async function uploadAllAvailableDebugArtifacts(
108145 }
109146
110147 // Add database bundle
111- let databaseBundlePath : string ;
112- if ( ! dbIsFinalized ( config , lang , logger ) ) {
113- databaseBundlePath = await createPartialDatabaseBundle ( config , lang ) ;
114- } else {
115- databaseBundlePath = await createDatabaseBundleCli ( config , lang ) ;
116- }
117- filesToUpload . push ( databaseBundlePath ) ;
148+ filesToUpload . push ( ...( await tryBundleDatabase ( config , language , logger ) ) ) ;
118149 }
119150
120151 await uploadDebugArtifacts (
0 commit comments