@@ -231,6 +231,90 @@ export async function uploadOverlayBaseDatabaseToCache(
231231 return true ;
232232}
233233
234+ /**
235+ * Downloads the overlay-base database from the GitHub Actions cache. If conditions
236+ * for downloading are not met, the function does nothing and returns false.
237+ *
238+ * @param codeql The CodeQL instance
239+ * @param config The configuration object
240+ * @param logger The logger instance
241+ * @returns A promise that resolves to true if the download was performed and
242+ * successfully completed, or false otherwise
243+ */
244+ export async function downloadOverlayBaseDatabaseFromCache (
245+ codeql : CodeQL ,
246+ config : Config ,
247+ logger : Logger ,
248+ ) : Promise < boolean > {
249+ const overlayDatabaseMode = config . augmentationProperties . overlayDatabaseMode ;
250+ if ( overlayDatabaseMode !== OverlayDatabaseMode . Overlay ) {
251+ logger . debug (
252+ `Overlay database mode is ${ overlayDatabaseMode } . ` +
253+ "Skip downloading overlay-base database from cache." ,
254+ ) ;
255+ return false ;
256+ }
257+ if ( ! config . augmentationProperties . useOverlayDatabaseCaching ) {
258+ logger . debug (
259+ "Overlay database caching is disabled. " +
260+ "Skip downloading overlay-base database from cache." ,
261+ ) ;
262+ return false ;
263+ }
264+ if ( isInTestMode ( ) ) {
265+ logger . debug (
266+ "In test mode. Skip downloading overlay-base database from cache." ,
267+ ) ;
268+ return false ;
269+ }
270+
271+ const dbLocation = config . dbLocation ;
272+ const codeQlVersion = ( await codeql . getVersion ( ) ) . version ;
273+ const restoreKey = getCacheRestoreKey ( config , codeQlVersion ) ;
274+
275+ logger . info (
276+ `Looking in Actions cache for overlay-base database with restore key ${ restoreKey } ` ,
277+ ) ;
278+
279+ try {
280+ const foundKey = await withTimeout (
281+ MAX_CACHE_OPERATION_MS ,
282+ actionsCache . restoreCache ( [ dbLocation ] , restoreKey ) ,
283+ ( ) => {
284+ logger . info ( "Timed out downloading overlay-base database from cache" ) ;
285+ } ,
286+ ) ;
287+
288+ if ( foundKey === undefined ) {
289+ logger . info ( "No overlay-base database found in Actions cache" ) ;
290+ return false ;
291+ }
292+
293+ logger . info (
294+ `Downloaded overlay-base database in cache with key ${ foundKey } ` ,
295+ ) ;
296+ } catch ( error ) {
297+ logger . warning (
298+ "Failed to download overlay-base database from cache: " +
299+ `${ error instanceof Error ? error . message : String ( error ) } ` ,
300+ ) ;
301+ return false ;
302+ }
303+
304+ const databaseIsValid = checkOverlayBaseDatabase (
305+ config ,
306+ logger ,
307+ "Downloaded overlay-base database is invalid" ,
308+ ) ;
309+ if ( ! databaseIsValid ) {
310+ logger . warning ( "Downloaded overlay-base database failed validation" ) ;
311+ return false ;
312+ }
313+
314+ logger . info ( `Successfully downloaded overlay-base database to ${ dbLocation } ` ) ;
315+ return true ;
316+ }
317+
234318function generateCacheKey ( config : Config , codeQlVersion : string ) : string {
235319 const sha = process . env . GITHUB_SHA || "unknown" ;
236320 return `${ getCacheRestoreKey ( config , codeQlVersion ) } ${ sha } ` ;
0 commit comments