Content-Length: 510240 | pFad | http://github.com/github/codeql-action/commit/2fc04c80cc3220d7f4758050cc5ef4cd11024e41

9C Download overlay-base database from actions cache · github/codeql-action@2fc04c8 · GitHub
Skip to content

Commit 2fc04c8

Browse files
committed
Download overlay-base database from actions cache
1 parent b95402d commit 2fc04c8

File tree

2 files changed

+116
-1
lines changed

2 files changed

+116
-1
lines changed

src/init-action.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ import {
4242
} from "./init";
4343
import { Language } from "./languages";
4444
import { getActionsLogger, Logger } from "./logging";
45-
import { OverlayDatabaseMode } from "./overlay-database-utils";
45+
import {
46+
downloadOverlayBaseDatabaseFromCache,
47+
OverlayDatabaseMode,
48+
} from "./overlay-database-utils";
4649
import { getRepositoryNwo } from "./repository";
4750
import { ToolsSource } from "./setup-codeql";
4851
import {
@@ -398,6 +401,34 @@ async function run() {
398401
}
399402

400403
try {
404+
if (
405+
config.augmentationProperties.overlayDatabaseMode ===
406+
OverlayDatabaseMode.Overlay &&
407+
config.augmentationProperties.useOverlayDatabaseCaching
408+
) {
409+
// OverlayDatabaseMode.Overlay comes in two flavors: with database
410+
// caching, or without. The flavor with database caching is intended to be
411+
// an "automatic control" mode, which is supposed to be fail-safe. If we
412+
// cannot download an overlay-base database, we revert to
413+
// OverlayDatabaseMode.None so that the workflow can continue to run.
414+
//
415+
// The flavor without database caching is intended to be a "manual
416+
// control" mode, where the workflow is supposed to make all the
417+
// necessary preparations. So, in that mode, we would assume that
418+
// everything is in order and let the analysis fail if that turns out not
419+
// to be the case.
420+
const overlayDatabaseDownloaded =
421+
await downloadOverlayBaseDatabaseFromCache(codeql, config, logger);
422+
if (!overlayDatabaseDownloaded) {
423+
config.augmentationProperties.overlayDatabaseMode =
424+
OverlayDatabaseMode.None;
425+
logger.info(
426+
"No overlay-base database found in cache, " +
427+
`reverting overlay database mode to ${OverlayDatabaseMode.None}.`,
428+
);
429+
}
430+
}
431+
401432
if (
402433
config.augmentationProperties.overlayDatabaseMode !==
403434
OverlayDatabaseMode.Overlay

src/overlay-database-utils.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
238322
async function generateCacheKey(
239323
config: Config,
240324
codeQlVersion: string,

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/github/codeql-action/commit/2fc04c80cc3220d7f4758050cc5ef4cd11024e41

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy