@@ -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
@@ -793,21 +823,28 @@ async function getOverlayDatabaseMode(
793823 ) {
794824 if ( isAnalyzingPullRequest ( ) ) {
795825 overlayDatabaseMode = OverlayDatabaseMode . Overlay ;
826+ useOverlayDatabaseCaching = true ;
796827 logger . info (
797828 `Setting overlay database mode to ${ overlayDatabaseMode } ` +
798- "because we are analyzing a pull request." ,
829+ "with caching because we are analyzing a pull request." ,
799830 ) ;
800831 } else if ( await isAnalyzingDefaultBranch ( ) ) {
801832 overlayDatabaseMode = OverlayDatabaseMode . OverlayBase ;
833+ useOverlayDatabaseCaching = true ;
802834 logger . info (
803835 `Setting overlay database mode to ${ overlayDatabaseMode } ` +
804- "because we are analyzing the default branch." ,
836+ "with caching because we are analyzing the default branch." ,
805837 ) ;
806838 }
807839 }
808840
841+ const nonOverlayAnalysis = {
842+ overlayDatabaseMode : OverlayDatabaseMode . None ,
843+ useOverlayDatabaseCaching : false ,
844+ } ;
845+
809846 if ( overlayDatabaseMode === OverlayDatabaseMode . None ) {
810- return OverlayDatabaseMode . None ;
847+ return nonOverlayAnalysis ;
811848 }
812849
813850 if ( buildMode !== BuildMode . None && languages . some ( isTracedLanguage ) ) {
@@ -816,26 +853,29 @@ async function getOverlayDatabaseMode(
816853 `build-mode is set to "${ buildMode } " instead of "none". ` +
817854 "Falling back to creating a normal full database instead." ,
818855 ) ;
819- return OverlayDatabaseMode . None ;
856+ return nonOverlayAnalysis ;
820857 }
821858 if ( ! ( await codeQlVersionAtLeast ( codeql , CODEQL_OVERLAY_MINIMUM_VERSION ) ) ) {
822859 logger . warning (
823860 `Cannot build an ${ overlayDatabaseMode } database because ` +
824861 `the CodeQL CLI is older than ${ CODEQL_OVERLAY_MINIMUM_VERSION } . ` +
825862 "Falling back to creating a normal full database instead." ,
826863 ) ;
827- return OverlayDatabaseMode . None ;
864+ return nonOverlayAnalysis ;
828865 }
829866 if ( ( await getGitRoot ( sourceRoot ) ) === undefined ) {
830867 logger . warning (
831868 `Cannot build an ${ overlayDatabaseMode } database because ` +
832869 `the source root "${ sourceRoot } " is not inside a git repository. ` +
833870 "Falling back to creating a normal full database instead." ,
834871 ) ;
835- return OverlayDatabaseMode . None ;
872+ return nonOverlayAnalysis ;
836873 }
837874
838- return overlayDatabaseMode ;
875+ return {
876+ overlayDatabaseMode,
877+ useOverlayDatabaseCaching,
878+ } ;
839879}
840880
841881/**
0 commit comments