@@ -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 defaultQueryFilters : [ ] ,
217229 overlayDatabaseMode : OverlayDatabaseMode . None ,
230+ useOverlayDatabaseCaching : false ,
218231} ;
219232export type Packs = Partial < Record < Language , string [ ] > > ;
220233
@@ -689,14 +702,18 @@ export async function calculateAugmentation(
689702 rawQueriesInput ,
690703 queriesInputCombines ,
691704 ) ;
692- const overlayDatabaseMode = await getOverlayDatabaseMode (
693- codeql ,
694- features ,
695- sourceRoot ,
696- buildMode ,
697- logger ,
705+ const { overlayDatabaseMode, useOverlayDatabaseCaching } =
706+ await getOverlayDatabaseMode (
707+ codeql ,
708+ features ,
709+ sourceRoot ,
710+ buildMode ,
711+ logger ,
712+ ) ;
713+ logger . info (
714+ `Using overlay database mode: ${ overlayDatabaseMode } ` +
715+ `${ useOverlayDatabaseCaching ? "with" : "without" } caching.` ,
698716 ) ;
699- logger . info ( `Using overlay database mode: ${ overlayDatabaseMode } ` ) ;
700717
701718 const qualityQueriesInput = parseQueriesFromInput (
702719 rawQualityQueriesInput ,
@@ -716,6 +733,7 @@ export async function calculateAugmentation(
716733 qualityQueriesInput,
717734 defaultQueryFilters,
718735 overlayDatabaseMode,
736+ useOverlayDatabaseCaching,
719737 } ;
720738}
721739
@@ -743,26 +761,38 @@ function parseQueriesFromInput(
743761}
744762
745763/**
746- * Calculate and validate the overlay database mode to use.
764+ * Calculate and validate the overlay database mode and caching to use.
747765 *
748766 * - If the environment variable `CODEQL_OVERLAY_DATABASE_MODE` is set, use it.
767+ * In this case, the workflow is responsible for managing database storage and
768+ * retrieval, and the action will not perform overlay database caching. Think
769+ * of it as a "manual control" mode where the calling workflow is responsible
770+ * for making sure that everything is set up correctly.
749771 * - Otherwise, if `Feature.OverlayAnalysis` is enabled, calculate the mode
750- * based on what we are analyzing.
751- * - If we are analyzing a pull request, use `Overlay`.
752- * - If we are analyzing the default branch, use `OverlayBase`.
772+ * based on what we are analyzing. Think of it as a "automatic control" mode
773+ * where the action will do the right thing by itself.
774+ * - If we are analyzing a pull request, use `Overlay` with caching.
775+ * - If we are analyzing the default branch, use `OverlayBase` with caching.
753776 * - Otherwise, use `None`.
754777 *
755778 * For `Overlay` and `OverlayBase`, the function performs further checks and
756779 * reverts to `None` if any check should fail.
780+ *
781+ * @returns An object containing the overlay database mode and whether the
782+ * action should perform overlay-base database caching.
757783 */
758784async function getOverlayDatabaseMode (
759785 codeql : CodeQL ,
760786 features : FeatureEnablement ,
761787 sourceRoot : string ,
762788 buildMode : BuildMode | undefined ,
763789 logger : Logger ,
764- ) : Promise < OverlayDatabaseMode > {
790+ ) : Promise < {
791+ overlayDatabaseMode : OverlayDatabaseMode ;
792+ useOverlayDatabaseCaching : boolean ;
793+ } > {
765794 let overlayDatabaseMode = OverlayDatabaseMode . None ;
795+ let useOverlayDatabaseCaching = false ;
766796
767797 const modeEnv = process . env . CODEQL_OVERLAY_DATABASE_MODE ;
768798 // Any unrecognized CODEQL_OVERLAY_DATABASE_MODE value will be ignored and
@@ -780,21 +810,28 @@ async function getOverlayDatabaseMode(
780810 } else if ( await features . getValue ( Feature . OverlayAnalysis , codeql ) ) {
781811 if ( isAnalyzingPullRequest ( ) ) {
782812 overlayDatabaseMode = OverlayDatabaseMode . Overlay ;
813+ useOverlayDatabaseCaching = true ;
783814 logger . info (
784815 `Setting overlay database mode to ${ overlayDatabaseMode } ` +
785- "because we are analyzing a pull request." ,
816+ "with caching because we are analyzing a pull request." ,
786817 ) ;
787818 } else if ( await isAnalyzingDefaultBranch ( ) ) {
788819 overlayDatabaseMode = OverlayDatabaseMode . OverlayBase ;
820+ useOverlayDatabaseCaching = true ;
789821 logger . info (
790822 `Setting overlay database mode to ${ overlayDatabaseMode } ` +
791- "because we are analyzing the default branch." ,
823+ "with caching because we are analyzing the default branch." ,
792824 ) ;
793825 }
794826 }
795827
828+ const nonOverlayAnalysis = {
829+ overlayDatabaseMode : OverlayDatabaseMode . None ,
830+ useOverlayDatabaseCaching : false ,
831+ } ;
832+
796833 if ( overlayDatabaseMode === OverlayDatabaseMode . None ) {
797- return OverlayDatabaseMode . None ;
834+ return nonOverlayAnalysis ;
798835 }
799836
800837 if ( buildMode !== BuildMode . None ) {
@@ -803,26 +840,29 @@ async function getOverlayDatabaseMode(
803840 `build-mode is set to "${ buildMode } " instead of "none". ` +
804841 "Falling back to creating a normal full database instead." ,
805842 ) ;
806- return OverlayDatabaseMode . None ;
843+ return nonOverlayAnalysis ;
807844 }
808845 if ( ! ( await codeQlVersionAtLeast ( codeql , CODEQL_OVERLAY_MINIMUM_VERSION ) ) ) {
809846 logger . warning (
810847 `Cannot build an ${ overlayDatabaseMode } database because ` +
811848 `the CodeQL CLI is older than ${ CODEQL_OVERLAY_MINIMUM_VERSION } . ` +
812849 "Falling back to creating a normal full database instead." ,
813850 ) ;
814- return OverlayDatabaseMode . None ;
851+ return nonOverlayAnalysis ;
815852 }
816853 if ( ( await getGitRoot ( sourceRoot ) ) === undefined ) {
817854 logger . warning (
818855 `Cannot build an ${ overlayDatabaseMode } database because ` +
819856 `the source root "${ sourceRoot } " is not inside a git repository. ` +
820857 "Falling back to creating a normal full database instead." ,
821858 ) ;
822- return OverlayDatabaseMode . None ;
859+ return nonOverlayAnalysis ;
823860 }
824861
825- return overlayDatabaseMode ;
862+ return {
863+ overlayDatabaseMode,
864+ useOverlayDatabaseCaching,
865+ } ;
826866}
827867
828868/**
0 commit comments