@@ -10,6 +10,7 @@ import { getRequiredInput } from "./actions-util";
1010import { dbIsFinalized } from "./analyze" ;
1111import { getCodeQL } from "./codeql" ;
1212import { Config } from "./config-utils" ;
13+ import { EnvVar } from "./environment" ;
1314import { Language } from "./languages" ;
1415import { Logger } from "./logging" ;
1516import {
@@ -23,6 +24,67 @@ export function sanitizeArifactName(name: string): string {
2324 return name . replace ( / [ ^ a - z A - Z 0 - 9 _ \\ - ] + / g, "" ) ;
2425}
2526
27+ export async function uploadAllAvailableDebugArtifacts (
28+ config : Config ,
29+ logger : Logger ,
30+ ) {
31+ let filesToUpload : string [ ] = [ ] ;
32+
33+ const analyzeActionOutputDir = process . env [ EnvVar . SARIF_RESULTS_OUTPUT_DIR ] ;
34+ for ( const lang of config . languages ) {
35+ // Add any SARIF files, if they exist
36+ if (
37+ analyzeActionOutputDir !== undefined &&
38+ fs . existsSync ( analyzeActionOutputDir ) &&
39+ fs . lstatSync ( analyzeActionOutputDir ) . isDirectory ( )
40+ ) {
41+ const sarifFile = path . resolve ( analyzeActionOutputDir , `${ lang } .sarif` ) ;
42+ // Move SARIF to DB location so that they can be uploaded with the same root directory as the other artifacts.
43+ if ( fs . existsSync ( sarifFile ) ) {
44+ const sarifInDbLocation = path . resolve (
45+ config . dbLocation ,
46+ `${ lang } .sarif` ,
47+ ) ;
48+ fs . renameSync ( sarifFile , sarifInDbLocation ) ;
49+ filesToUpload = filesToUpload . concat ( sarifInDbLocation ) ;
50+ }
51+ }
52+
53+ // Add any log files
54+ const databaseDirectory = getCodeQLDatabasePath ( config , lang ) ;
55+ const logsDirectory = path . resolve ( databaseDirectory , "log" ) ;
56+ if ( doesDirectoryExist ( logsDirectory ) ) {
57+ filesToUpload = filesToUpload . concat ( listFolder ( logsDirectory ) ) ;
58+ }
59+
60+ // Multilanguage tracing: there are additional logs in the root of the cluster
61+ const multiLanguageTracingLogsDirectory = path . resolve (
62+ config . dbLocation ,
63+ "log" ,
64+ ) ;
65+ if ( doesDirectoryExist ( multiLanguageTracingLogsDirectory ) ) {
66+ filesToUpload = filesToUpload . concat (
67+ listFolder ( multiLanguageTracingLogsDirectory ) ,
68+ ) ;
69+ }
70+
71+ // Add database bundle
72+ let databaseBundlePath : string ;
73+ if ( ! dbIsFinalized ( config , lang , logger ) ) {
74+ databaseBundlePath = await createPartialDatabaseBundle ( config , lang ) ;
75+ } else {
76+ databaseBundlePath = await createDatabaseBundleCli ( config , lang ) ;
77+ }
78+ filesToUpload = filesToUpload . concat ( databaseBundlePath ) ;
79+ }
80+
81+ await uploadDebugArtifacts (
82+ filesToUpload ,
83+ config . dbLocation ,
84+ config . debugArtifactName ,
85+ ) ;
86+ }
87+
2688export async function uploadDebugArtifacts (
2789 toUpload : string [ ] ,
2890 rootDir : string ,
@@ -63,50 +125,6 @@ export async function uploadDebugArtifacts(
63125 }
64126}
65127
66- export async function uploadSarifDebugArtifact (
67- config : Config ,
68- outputDir : string ,
69- ) {
70- if ( ! doesDirectoryExist ( outputDir ) ) {
71- return ;
72- }
73-
74- let toUpload : string [ ] = [ ] ;
75- for ( const lang of config . languages ) {
76- const sarifFile = path . resolve ( outputDir , `${ lang } .sarif` ) ;
77- if ( fs . existsSync ( sarifFile ) ) {
78- toUpload = toUpload . concat ( sarifFile ) ;
79- }
80- }
81- await uploadDebugArtifacts ( toUpload , outputDir , config . debugArtifactName ) ;
82- }
83-
84- export async function uploadLogsDebugArtifact ( config : Config ) {
85- let toUpload : string [ ] = [ ] ;
86- for ( const language of config . languages ) {
87- const databaseDirectory = getCodeQLDatabasePath ( config , language ) ;
88- const logsDirectory = path . resolve ( databaseDirectory , "log" ) ;
89- if ( doesDirectoryExist ( logsDirectory ) ) {
90- toUpload = toUpload . concat ( listFolder ( logsDirectory ) ) ;
91- }
92- }
93-
94- // Multilanguage tracing: there are additional logs in the root of the cluster
95- const multiLanguageTracingLogsDirectory = path . resolve (
96- config . dbLocation ,
97- "log" ,
98- ) ;
99- if ( doesDirectoryExist ( multiLanguageTracingLogsDirectory ) ) {
100- toUpload = toUpload . concat ( listFolder ( multiLanguageTracingLogsDirectory ) ) ;
101- }
102-
103- await uploadDebugArtifacts (
104- toUpload ,
105- config . dbLocation ,
106- config . debugArtifactName ,
107- ) ;
108- }
109-
110128/**
111129 * If a database has not been finalized, we cannot run the `codeql database bundle`
112130 * command in the CLI because it will return an error. Instead we directly zip
@@ -150,31 +168,3 @@ async function createDatabaseBundleCli(
150168 ) ;
151169 return databaseBundlePath ;
152170}
153-
154- export async function uploadDatabaseBundleDebugArtifact (
155- config : Config ,
156- logger : Logger ,
157- ) {
158- for ( const language of config . languages ) {
159- try {
160- let databaseBundlePath : string ;
161- if ( ! dbIsFinalized ( config , language , logger ) ) {
162- databaseBundlePath = await createPartialDatabaseBundle (
163- config ,
164- language ,
165- ) ;
166- } else {
167- databaseBundlePath = await createDatabaseBundleCli ( config , language ) ;
168- }
169- await uploadDebugArtifacts (
170- [ databaseBundlePath ] ,
171- config . dbLocation ,
172- config . debugArtifactName ,
173- ) ;
174- } catch ( error ) {
175- core . info (
176- `Failed to upload database debug bundle for ${ config . debugDatabaseName } -${ language } : ${ error } ` ,
177- ) ;
178- }
179- }
180- }
0 commit comments