@@ -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
@@ -689,14 +702,18 @@ export async function calculateAugmentation(
689
702
rawQueriesInput ,
690
703
queriesInputCombines ,
691
704
) ;
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.` ,
698
716
) ;
699
- logger . info ( `Using overlay database mode: ${ overlayDatabaseMode } ` ) ;
700
717
701
718
const qualityQueriesInput = parseQueriesFromInput (
702
719
rawQualityQueriesInput ,
@@ -718,6 +735,7 @@ export async function calculateAugmentation(
718
735
qualityQueriesInput,
719
736
extraQueryExclusions,
720
737
overlayDatabaseMode,
738
+ useOverlayDatabaseCaching,
721
739
} ;
722
740
}
723
741
@@ -745,26 +763,38 @@ function parseQueriesFromInput(
745
763
}
746
764
747
765
/**
748
- * Calculate and validate the overlay database mode to use.
766
+ * Calculate and validate the overlay database mode and caching to use.
749
767
*
750
768
* - If the environment variable `CODEQL_OVERLAY_DATABASE_MODE` is set, use it.
769
+ * In this case, the workflow is responsible for managing database storage and
770
+ * retrieval, and the action will not perform overlay database caching. Think
771
+ * of it as a "manual control" mode where the calling workflow is responsible
772
+ * for making sure that everything is set up correctly.
751
773
* - Otherwise, if `Feature.OverlayAnalysis` is enabled, calculate the mode
752
- * based on what we are analyzing.
753
- * - If we are analyzing a pull request, use `Overlay`.
754
- * - If we are analyzing the default branch, use `OverlayBase`.
774
+ * based on what we are analyzing. Think of it as a "automatic control" mode
775
+ * where the action will do the right thing by itself.
776
+ * - If we are analyzing a pull request, use `Overlay` with caching.
777
+ * - If we are analyzing the default branch, use `OverlayBase` with caching.
755
778
* - Otherwise, use `None`.
756
779
*
757
780
* For `Overlay` and `OverlayBase`, the function performs further checks and
758
781
* reverts to `None` if any check should fail.
782
+ *
783
+ * @returns An object containing the overlay database mode and whether the
784
+ * action should perform overlay-base database caching.
759
785
*/
760
786
async function getOverlayDatabaseMode (
761
787
codeql : CodeQL ,
762
788
features : FeatureEnablement ,
763
789
sourceRoot : string ,
764
790
buildMode : BuildMode | undefined ,
765
791
logger : Logger ,
766
- ) : Promise < OverlayDatabaseMode > {
792
+ ) : Promise < {
793
+ overlayDatabaseMode : OverlayDatabaseMode ;
794
+ useOverlayDatabaseCaching : boolean ;
795
+ } > {
767
796
let overlayDatabaseMode = OverlayDatabaseMode . None ;
797
+ let useOverlayDatabaseCaching = false ;
768
798
769
799
const modeEnv = process . env . CODEQL_OVERLAY_DATABASE_MODE ;
770
800
// Any unrecognized CODEQL_OVERLAY_DATABASE_MODE value will be ignored and
@@ -782,21 +812,28 @@ async function getOverlayDatabaseMode(
782
812
} else if ( await features . getValue ( Feature . OverlayAnalysis , codeql ) ) {
783
813
if ( isAnalyzingPullRequest ( ) ) {
784
814
overlayDatabaseMode = OverlayDatabaseMode . Overlay ;
815
+ useOverlayDatabaseCaching = true ;
785
816
logger . info (
786
817
`Setting overlay database mode to ${ overlayDatabaseMode } ` +
787
- "because we are analyzing a pull request." ,
818
+ "with caching because we are analyzing a pull request." ,
788
819
) ;
789
820
} else if ( await isAnalyzingDefaultBranch ( ) ) {
790
821
overlayDatabaseMode = OverlayDatabaseMode . OverlayBase ;
822
+ useOverlayDatabaseCaching = true ;
791
823
logger . info (
792
824
`Setting overlay database mode to ${ overlayDatabaseMode } ` +
793
- "because we are analyzing the default branch." ,
825
+ "with caching because we are analyzing the default branch." ,
794
826
) ;
795
827
}
796
828
}
797
829
830
+ const nonOverlayAnalysis = {
831
+ overlayDatabaseMode : OverlayDatabaseMode . None ,
832
+ useOverlayDatabaseCaching : false ,
833
+ } ;
834
+
798
835
if ( overlayDatabaseMode === OverlayDatabaseMode . None ) {
799
- return OverlayDatabaseMode . None ;
836
+ return nonOverlayAnalysis ;
800
837
}
801
838
802
839
if ( buildMode !== BuildMode . None ) {
@@ -805,26 +842,29 @@ async function getOverlayDatabaseMode(
805
842
`build-mode is set to "${ buildMode } " instead of "none". ` +
806
843
"Falling back to creating a normal full database instead." ,
807
844
) ;
808
- return OverlayDatabaseMode . None ;
845
+ return nonOverlayAnalysis ;
809
846
}
810
847
if ( ! ( await codeQlVersionAtLeast ( codeql , CODEQL_OVERLAY_MINIMUM_VERSION ) ) ) {
811
848
logger . warning (
812
849
`Cannot build an ${ overlayDatabaseMode } database because ` +
813
850
`the CodeQL CLI is older than ${ CODEQL_OVERLAY_MINIMUM_VERSION } . ` +
814
851
"Falling back to creating a normal full database instead." ,
815
852
) ;
816
- return OverlayDatabaseMode . None ;
853
+ return nonOverlayAnalysis ;
817
854
}
818
855
if ( ( await getGitRoot ( sourceRoot ) ) === undefined ) {
819
856
logger . warning (
820
857
`Cannot build an ${ overlayDatabaseMode } database because ` +
821
858
`the source root "${ sourceRoot } " is not inside a git repository. ` +
822
859
"Falling back to creating a normal full database instead." ,
823
860
) ;
824
- return OverlayDatabaseMode . None ;
861
+ return nonOverlayAnalysis ;
825
862
}
826
863
827
- return overlayDatabaseMode ;
864
+ return {
865
+ overlayDatabaseMode,
866
+ useOverlayDatabaseCaching,
867
+ } ;
828
868
}
829
869
830
870
/**
0 commit comments