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