@@ -201,6 +201,18 @@ export interface AugmentationProperties {
201
201
* The overlay database mode to use.
202
202
*/
203
203
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 ;
204
216
}
205
217
206
218
/**
@@ -215,6 +227,7 @@ export const defaultAugmentationProperties: AugmentationProperties = {
215
227
qualityQueriesInput : undefined ,
216
228
extraQueryExclusions : [ ] ,
217
229
overlayDatabaseMode : OverlayDatabaseMode . None ,
230
+ useOverlayDatabaseCaching : false ,
218
231
} ;
219
232
export type Packs = Partial < Record < Language , string [ ] > > ;
220
233
@@ -693,16 +706,20 @@ export async function calculateAugmentation(
693
706
rawQueriesInput ,
694
707
queriesInputCombines ,
695
708
) ;
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.` ,
704
722
) ;
705
- logger . info ( `Using overlay database mode: ${ overlayDatabaseMode } ` ) ;
706
723
707
724
const qualityQueriesInput = parseQueriesFromInput (
708
725
rawQualityQueriesInput ,
@@ -724,6 +741,7 @@ export async function calculateAugmentation(
724
741
qualityQueriesInput,
725
742
extraQueryExclusions,
726
743
overlayDatabaseMode,
744
+ useOverlayDatabaseCaching,
727
745
} ;
728
746
}
729
747
@@ -751,17 +769,25 @@ function parseQueriesFromInput(
751
769
}
752
770
753
771
/**
754
- * Calculate and validate the overlay database mode to use.
772
+ * Calculate and validate the overlay database mode and caching to use.
755
773
*
756
774
* - 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.
757
779
* - 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.
761
784
* - Otherwise, use `None`.
762
785
*
763
786
* For `Overlay` and `OverlayBase`, the function performs further checks and
764
787
* 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.
765
791
*/
766
792
async function getOverlayDatabaseMode (
767
793
codeql : CodeQL ,
@@ -771,8 +797,12 @@ async function getOverlayDatabaseMode(
771
797
sourceRoot : string ,
772
798
buildMode : BuildMode | undefined ,
773
799
logger : Logger ,
774
- ) : Promise < OverlayDatabaseMode > {
800
+ ) : Promise < {
801
+ overlayDatabaseMode : OverlayDatabaseMode ;
802
+ useOverlayDatabaseCaching : boolean ;
803
+ } > {
775
804
let overlayDatabaseMode = OverlayDatabaseMode . None ;
805
+ let useOverlayDatabaseCaching = false ;
776
806
777
807
const modeEnv = process . env . CODEQL_OVERLAY_DATABASE_MODE ;
778
808
// Any unrecognized CODEQL_OVERLAY_DATABASE_MODE value will be ignored and
@@ -795,21 +825,28 @@ async function getOverlayDatabaseMode(
795
825
) {
796
826
if ( isAnalyzingPullRequest ( ) ) {
797
827
overlayDatabaseMode = OverlayDatabaseMode . Overlay ;
828
+ useOverlayDatabaseCaching = true ;
798
829
logger . info (
799
830
`Setting overlay database mode to ${ overlayDatabaseMode } ` +
800
- "because we are analyzing a pull request." ,
831
+ "with caching because we are analyzing a pull request." ,
801
832
) ;
802
833
} else if ( await isAnalyzingDefaultBranch ( ) ) {
803
834
overlayDatabaseMode = OverlayDatabaseMode . OverlayBase ;
835
+ useOverlayDatabaseCaching = true ;
804
836
logger . info (
805
837
`Setting overlay database mode to ${ overlayDatabaseMode } ` +
806
- "because we are analyzing the default branch." ,
838
+ "with caching because we are analyzing the default branch." ,
807
839
) ;
808
840
}
809
841
}
810
842
843
+ const nonOverlayAnalysis = {
844
+ overlayDatabaseMode : OverlayDatabaseMode . None ,
845
+ useOverlayDatabaseCaching : false ,
846
+ } ;
847
+
811
848
if ( overlayDatabaseMode === OverlayDatabaseMode . None ) {
812
- return OverlayDatabaseMode . None ;
849
+ return nonOverlayAnalysis ;
813
850
}
814
851
815
852
if ( buildMode !== BuildMode . None && languages . some ( isTracedLanguage ) ) {
@@ -818,26 +855,29 @@ async function getOverlayDatabaseMode(
818
855
`build-mode is set to "${ buildMode } " instead of "none". ` +
819
856
"Falling back to creating a normal full database instead." ,
820
857
) ;
821
- return OverlayDatabaseMode . None ;
858
+ return nonOverlayAnalysis ;
822
859
}
823
860
if ( ! ( await codeQlVersionAtLeast ( codeql , CODEQL_OVERLAY_MINIMUM_VERSION ) ) ) {
824
861
logger . warning (
825
862
`Cannot build an ${ overlayDatabaseMode } database because ` +
826
863
`the CodeQL CLI is older than ${ CODEQL_OVERLAY_MINIMUM_VERSION } . ` +
827
864
"Falling back to creating a normal full database instead." ,
828
865
) ;
829
- return OverlayDatabaseMode . None ;
866
+ return nonOverlayAnalysis ;
830
867
}
831
868
if ( ( await getGitRoot ( sourceRoot ) ) === undefined ) {
832
869
logger . warning (
833
870
`Cannot build an ${ overlayDatabaseMode } database because ` +
834
871
`the source root "${ sourceRoot } " is not inside a git repository. ` +
835
872
"Falling back to creating a normal full database instead." ,
836
873
) ;
837
- return OverlayDatabaseMode . None ;
874
+ return nonOverlayAnalysis ;
838
875
}
839
876
840
- return overlayDatabaseMode ;
877
+ return {
878
+ overlayDatabaseMode,
879
+ useOverlayDatabaseCaching,
880
+ } ;
841
881
}
842
882
843
883
/**
0 commit comments