@@ -13,29 +13,43 @@ import { RepositoryNwo } from "./repository";
1313import * as util from "./util" ;
1414import { bundleDb , CleanupLevel , parseGitHubUrl } from "./util" ;
1515
16+ /** Information about a database upload. */
17+ export interface DatabaseUploadResult {
18+ /** Language of the database. */
19+ language : string ;
20+ /** Size of the zipped database in bytes. */
21+ zipped_upload_size_bytes ?: number ;
22+ /** Whether the uploaded database is an overlay base. */
23+ is_overlay_base ?: boolean ;
24+ /** Time taken to upload database in milliseconds. */
25+ upload_duration_ms ?: number ;
26+ /** If there was an error during database upload, this is its message. */
27+ error ?: string ;
28+ }
29+
1630export async function cleanupAndUploadDatabases (
1731 repositoryNwo : RepositoryNwo ,
1832 codeql : CodeQL ,
1933 config : Config ,
2034 apiDetails : GitHubApiDetails ,
2135 features : FeatureEnablement ,
2236 logger : Logger ,
23- ) : Promise < void > {
37+ ) : Promise < DatabaseUploadResult [ ] > {
2438 if ( actionsUtil . getRequiredInput ( "upload-database" ) !== "true" ) {
2539 logger . debug ( "Database upload disabled in workflow. Skipping upload." ) ;
26- return ;
40+ return [ ] ;
2741 }
2842
2943 if ( ! config . analysisKinds . includes ( AnalysisKind . CodeScanning ) ) {
3044 logger . debug (
3145 `Not uploading database because 'analysis-kinds: ${ AnalysisKind . CodeScanning } ' is not enabled.` ,
3246 ) ;
33- return ;
47+ return [ ] ;
3448 }
3549
3650 if ( util . isInTestMode ( ) ) {
3751 logger . debug ( "In test mode. Skipping database upload." ) ;
38- return ;
52+ return [ ] ;
3953 }
4054
4155 // Do nothing when not running against github.com
@@ -44,20 +58,22 @@ export async function cleanupAndUploadDatabases(
4458 config . gitHubVersion . type !== util . GitHubVariant . GHEC_DR
4559 ) {
4660 logger . debug ( "Not running against github.com or GHEC-DR. Skipping upload." ) ;
47- return ;
61+ return [ ] ;
4862 }
4963
5064 if ( ! ( await gitUtils . isAnalyzingDefaultBranch ( ) ) ) {
5165 // We only want to upload a database if we are analyzing the default branch.
5266 logger . debug ( "Not analyzing default branch. Skipping upload." ) ;
53- return ;
67+ return [ ] ;
5468 }
5569
56- const cleanupLevel =
70+ // If config.overlayDatabaseMode is OverlayBase, then we have overlay base databases for all languages.
71+ const shouldUploadOverlayBase =
5772 config . overlayDatabaseMode === OverlayDatabaseMode . OverlayBase &&
58- ( await features . getValue ( Feature . UploadOverlayDbToApi ) )
59- ? CleanupLevel . Overlay
60- : CleanupLevel . Clear ;
73+ ( await features . getValue ( Feature . UploadOverlayDbToApi ) ) ;
74+ const cleanupLevel = shouldUploadOverlayBase
75+ ? CleanupLevel . Overlay
76+ : CleanupLevel . Clear ;
6177
6278 // Clean up the database, since intermediate results may still be written to the
6379 // database if there is high RAM pressure.
@@ -77,6 +93,7 @@ export async function cleanupAndUploadDatabases(
7793 uploadsBaseUrl = uploadsBaseUrl . slice ( 0 , - 1 ) ;
7894 }
7995
96+ const reports : DatabaseUploadResult [ ] = [ ] ;
8097 for ( const language of config . languages ) {
8198 try {
8299 // Upload the database bundle.
@@ -90,6 +107,7 @@ export async function cleanupAndUploadDatabases(
90107 actionsUtil . getRequiredInput ( "checkout_path" ) ,
91108 ) ;
92109 try {
110+ const startTime = performance . now ( ) ;
93111 await client . request (
94112 `POST /repos/:owner/:repo/code-scanning/codeql/databases/:language?name=:name&commit_oid=:commit_oid` ,
95113 {
@@ -107,13 +125,27 @@ export async function cleanupAndUploadDatabases(
107125 } ,
108126 } ,
109127 ) ;
128+ const endTime = performance . now ( ) ;
129+ reports . push ( {
130+ language,
131+ zipped_upload_size_bytes : bundledDbSize ,
132+ is_overlay_base : shouldUploadOverlayBase ,
133+ upload_duration_ms : endTime - startTime ,
134+ } ) ;
110135 logger . debug ( `Successfully uploaded database for ${ language } ` ) ;
111136 } finally {
112137 bundledDbReadStream . close ( ) ;
113138 }
114139 } catch ( e ) {
115140 // Log a warning but don't fail the workflow
116- logger . warning ( `Failed to upload database for ${ language } : ${ e } ` ) ;
141+ logger . warning (
142+ `Failed to upload database for ${ language } : ${ util . getErrorMessage ( e ) } ` ,
143+ ) ;
144+ reports . push ( {
145+ language,
146+ error : util . getErrorMessage ( e ) ,
147+ } ) ;
117148 }
118149 }
150+ return reports ;
119151}
0 commit comments