@@ -18,6 +18,7 @@ import {
18
18
doesDirectoryExist ,
19
19
getCodeQLDatabasePath ,
20
20
listFolder ,
21
+ wrapError ,
21
22
} from "./util" ;
22
23
23
24
export function sanitizeArifactName ( name : string ) : string {
@@ -65,34 +66,70 @@ export async function uploadCombinedSarifArtifacts() {
65
66
}
66
67
}
67
68
68
- export async function uploadAllAvailableDebugArtifacts (
69
+ function tryGetSarifResultPath (
69
70
config : Config ,
71
+ language : Language ,
70
72
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 ] ;
77
76
if (
78
77
analyzeActionOutputDir !== undefined &&
79
78
fs . existsSync ( analyzeActionOutputDir ) &&
80
79
fs . lstatSync ( analyzeActionOutputDir ) . isDirectory ( )
81
80
) {
82
- const sarifFile = path . resolve ( analyzeActionOutputDir , `${ lang } .sarif` ) ;
81
+ const sarifFile = path . resolve (
82
+ analyzeActionOutputDir ,
83
+ `${ language } .sarif` ,
84
+ ) ;
83
85
// Move SARIF to DB location so that they can be uploaded with the same root directory as the other artifacts.
84
86
if ( fs . existsSync ( sarifFile ) ) {
85
87
const sarifInDbLocation = path . resolve (
86
88
config . dbLocation ,
87
- `${ lang } .sarif` ,
89
+ `${ language } .sarif` ,
88
90
) ;
89
91
fs . copyFileSync ( sarifFile , sarifInDbLocation ) ;
90
- filesToUpload . push ( sarifInDbLocation ) ;
92
+ return [ sarifInDbLocation ] ;
91
93
}
92
94
}
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 ) ) ;
93
130
94
131
// Add any log files
95
- const databaseDirectory = getCodeQLDatabasePath ( config , lang ) ;
132
+ const databaseDirectory = getCodeQLDatabasePath ( config , language ) ;
96
133
const logsDirectory = path . resolve ( databaseDirectory , "log" ) ;
97
134
if ( doesDirectoryExist ( logsDirectory ) ) {
98
135
filesToUpload . push ( ...listFolder ( logsDirectory ) ) ;
@@ -108,13 +145,7 @@ export async function uploadAllAvailableDebugArtifacts(
108
145
}
109
146
110
147
// 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 ) ) ) ;
118
149
}
119
150
120
151
await uploadDebugArtifacts (
0 commit comments