@@ -201,6 +201,18 @@ export interface AugmentationProperties {
201201 * The overlay database mode to use.
202202 */
203203 overlayDatabaseMode : OverlayDatabaseMode ;
204+
205+ /**
206+ * Whether to use caching for overlay databases. If it is true, the action
207+ * will upload the created overlay-base database to the actions cache, and
208+ * download an overlay-base database from the actions cache before it creates
209+ * a new overlay database. If it is false, the action assumes that the
210+ * workflow will be responsible for managing database storage and retrieval.
211+ *
212+ * This property has no effect unless `overlayDatabaseMode` is `Overlay` or
213+ * `OverlayBase`.
214+ */
215+ useOverlayDatabaseCaching : boolean ;
204216}
205217
206218/**
@@ -215,6 +227,7 @@ export const defaultAugmentationProperties: AugmentationProperties = {
215227 qualityQueriesInput : undefined ,
216228 extraQueryExclusions : [ ] ,
217229 overlayDatabaseMode : OverlayDatabaseMode . None ,
230+ useOverlayDatabaseCaching : false ,
218231} ;
219232export type Packs = Partial < Record < Language , string [ ] > > ;
220233
@@ -693,16 +706,20 @@ export async function calculateAugmentation(
693706 rawQueriesInput ,
694707 queriesInputCombines ,
695708 ) ;
696- const overlayDatabaseMode = await getOverlayDatabaseMode (
697- codeql ,
698- repository ,
699- features ,
700- languages ,
701- sourceRoot ,
702- buildMode ,
703- logger ,
709+ const { overlayDatabaseMode, useOverlayDatabaseCaching } =
710+ await getOverlayDatabaseMode (
711+ codeql ,
712+ repository ,
713+ features ,
714+ languages ,
715+ sourceRoot ,
716+ buildMode ,
717+ logger ,
718+ ) ;
719+ logger . info (
720+ `Using overlay database mode: ${ overlayDatabaseMode } ` +
721+ `${ useOverlayDatabaseCaching ? "with" : "without" } caching.` ,
704722 ) ;
705- logger . info ( `Using overlay database mode: ${ overlayDatabaseMode } ` ) ;
706723
707724 const qualityQueriesInput = parseQueriesFromInput (
708725 rawQualityQueriesInput ,
@@ -724,6 +741,7 @@ export async function calculateAugmentation(
724741 qualityQueriesInput,
725742 extraQueryExclusions,
726743 overlayDatabaseMode,
744+ useOverlayDatabaseCaching,
727745 } ;
728746}
729747
@@ -751,17 +769,25 @@ function parseQueriesFromInput(
751769}
752770
753771/**
754- * Calculate and validate the overlay database mode to use.
772+ * Calculate and validate the overlay database mode and caching to use.
755773 *
756774 * - If the environment variable `CODEQL_OVERLAY_DATABASE_MODE` is set, use it.
775+ * In this case, the workflow is responsible for managing database storage and
776+ * retrieval, and the action will not perform overlay database caching. Think
777+ * of it as a "manual control" mode where the calling workflow is responsible
778+ * for making sure that everything is set up correctly.
757779 * - Otherwise, if `Feature.OverlayAnalysis` is enabled, calculate the mode
758- * based on what we are analyzing.
759- * - If we are analyzing a pull request, use `Overlay`.
760- * - If we are analyzing the default branch, use `OverlayBase`.
780+ * based on what we are analyzing. Think of it as a "automatic control" mode
781+ * where the action will do the right thing by itself.
782+ * - If we are analyzing a pull request, use `Overlay` with caching.
783+ * - If we are analyzing the default branch, use `OverlayBase` with caching.
761784 * - Otherwise, use `None`.
762785 *
763786 * For `Overlay` and `OverlayBase`, the function performs further checks and
764787 * reverts to `None` if any check should fail.
788+ *
789+ * @returns An object containing the overlay database mode and whether the
790+ * action should perform overlay-base database caching.
765791 */
766792async function getOverlayDatabaseMode (
767793 codeql : CodeQL ,
@@ -771,8 +797,12 @@ async function getOverlayDatabaseMode(
771797 sourceRoot : string ,
772798 buildMode : BuildMode | undefined ,
773799 logger : Logger ,
774- ) : Promise < OverlayDatabaseMode > {
800+ ) : Promise < {
801+ overlayDatabaseMode : OverlayDatabaseMode ;
802+ useOverlayDatabaseCaching : boolean ;
803+ } > {
775804 let overlayDatabaseMode = OverlayDatabaseMode . None ;
805+ let useOverlayDatabaseCaching = false ;
776806
777807 const modeEnv = process . env . CODEQL_OVERLAY_DATABASE_MODE ;
778808 // Any unrecognized CODEQL_OVERLAY_DATABASE_MODE value will be ignored and
@@ -795,21 +825,28 @@ async function getOverlayDatabaseMode(
795825 ) {
796826 if ( isAnalyzingPullRequest ( ) ) {
797827 overlayDatabaseMode = OverlayDatabaseMode . Overlay ;
828+ useOverlayDatabaseCaching = true ;
798829 logger . info (
799830 `Setting overlay database mode to ${ overlayDatabaseMode } ` +
800- "because we are analyzing a pull request." ,
831+ "with caching because we are analyzing a pull request." ,
801832 ) ;
802833 } else if ( await isAnalyzingDefaultBranch ( ) ) {
803834 overlayDatabaseMode = OverlayDatabaseMode . OverlayBase ;
835+ useOverlayDatabaseCaching = true ;
804836 logger . info (
805837 `Setting overlay database mode to ${ overlayDatabaseMode } ` +
806- "because we are analyzing the default branch." ,
838+ "with caching because we are analyzing the default branch." ,
807839 ) ;
808840 }
809841 }
810842
843+ const nonOverlayAnalysis = {
844+ overlayDatabaseMode : OverlayDatabaseMode . None ,
845+ useOverlayDatabaseCaching : false ,
846+ } ;
847+
811848 if ( overlayDatabaseMode === OverlayDatabaseMode . None ) {
812- return OverlayDatabaseMode . None ;
849+ return nonOverlayAnalysis ;
813850 }
814851
815852 if ( buildMode !== BuildMode . None && languages . some ( isTracedLanguage ) ) {
@@ -818,26 +855,29 @@ async function getOverlayDatabaseMode(
818855 `build-mode is set to "${ buildMode } " instead of "none". ` +
819856 "Falling back to creating a normal full database instead." ,
820857 ) ;
821- return OverlayDatabaseMode . None ;
858+ return nonOverlayAnalysis ;
822859 }
823860 if ( ! ( await codeQlVersionAtLeast ( codeql , CODEQL_OVERLAY_MINIMUM_VERSION ) ) ) {
824861 logger . warning (
825862 `Cannot build an ${ overlayDatabaseMode } database because ` +
826863 `the CodeQL CLI is older than ${ CODEQL_OVERLAY_MINIMUM_VERSION } . ` +
827864 "Falling back to creating a normal full database instead." ,
828865 ) ;
829- return OverlayDatabaseMode . None ;
866+ return nonOverlayAnalysis ;
830867 }
831868 if ( ( await getGitRoot ( sourceRoot ) ) === undefined ) {
832869 logger . warning (
833870 `Cannot build an ${ overlayDatabaseMode } database because ` +
834871 `the source root "${ sourceRoot } " is not inside a git repository. ` +
835872 "Falling back to creating a normal full database instead." ,
836873 ) ;
837- return OverlayDatabaseMode . None ;
874+ return nonOverlayAnalysis ;
838875 }
839876
840- return overlayDatabaseMode ;
877+ return {
878+ overlayDatabaseMode,
879+ useOverlayDatabaseCaching,
880+ } ;
841881}
842882
843883/**
0 commit comments