Skip to content

Commit 0fa6583

Browse files
committed
Add AugmentationProperties.useOverlayDatabaseCaching
This commit adds useOverlayDatabaseCaching to AugmentationProperties to indicate whether the action should upload overlay-base databases to the actions cache and to download a cached overlay-base database when creating an overlay database.
1 parent 3207936 commit 0fa6583

File tree

1 file changed

+60
-20
lines changed

1 file changed

+60
-20
lines changed

src/config-utils.ts

Lines changed: 60 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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
};
219232
export type Packs = Partial<Record<Language, string[]>>;
220233

@@ -693,15 +706,19 @@ export async function calculateAugmentation(
693706
rawQueriesInput,
694707
queriesInputCombines,
695708
);
696-
const overlayDatabaseMode = await getOverlayDatabaseMode(
697-
codeql,
698-
repository,
699-
features,
700-
sourceRoot,
701-
buildMode,
702-
logger,
709+
const { overlayDatabaseMode, useOverlayDatabaseCaching } =
710+
await getOverlayDatabaseMode(
711+
codeql,
712+
repository,
713+
features,
714+
sourceRoot,
715+
buildMode,
716+
logger,
717+
);
718+
logger.info(
719+
`Using overlay database mode: ${overlayDatabaseMode} ` +
720+
`${useOverlayDatabaseCaching ? "with" : "without"} caching.`,
703721
);
704-
logger.info(`Using overlay database mode: ${overlayDatabaseMode}`);
705722

706723
const qualityQueriesInput = parseQueriesFromInput(
707724
rawQualityQueriesInput,
@@ -723,6 +740,7 @@ export async function calculateAugmentation(
723740
qualityQueriesInput,
724741
extraQueryExclusions,
725742
overlayDatabaseMode,
743+
useOverlayDatabaseCaching,
726744
};
727745
}
728746

@@ -750,17 +768,25 @@ function parseQueriesFromInput(
750768
}
751769

752770
/**
753-
* Calculate and validate the overlay database mode to use.
771+
* Calculate and validate the overlay database mode and caching to use.
754772
*
755773
* - If the environment variable `CODEQL_OVERLAY_DATABASE_MODE` is set, use it.
774+
* In this case, the workflow is responsible for managing database storage and
775+
* retrieval, and the action will not perform overlay database caching. Think
776+
* of it as a "manual control" mode where the calling workflow is responsible
777+
* for making sure that everything is set up correctly.
756778
* - Otherwise, if `Feature.OverlayAnalysis` is enabled, calculate the mode
757-
* based on what we are analyzing.
758-
* - If we are analyzing a pull request, use `Overlay`.
759-
* - If we are analyzing the default branch, use `OverlayBase`.
779+
* based on what we are analyzing. Think of it as a "automatic control" mode
780+
* where the action will do the right thing by itself.
781+
* - If we are analyzing a pull request, use `Overlay` with caching.
782+
* - If we are analyzing the default branch, use `OverlayBase` with caching.
760783
* - Otherwise, use `None`.
761784
*
762785
* For `Overlay` and `OverlayBase`, the function performs further checks and
763786
* reverts to `None` if any check should fail.
787+
*
788+
* @returns An object containing the overlay database mode and whether the
789+
* action should perform overlay-base database caching.
764790
*/
765791
async function getOverlayDatabaseMode(
766792
codeql: CodeQL,
@@ -769,8 +795,12 @@ async function getOverlayDatabaseMode(
769795
sourceRoot: string,
770796
buildMode: BuildMode | undefined,
771797
logger: Logger,
772-
): Promise<OverlayDatabaseMode> {
798+
): Promise<{
799+
overlayDatabaseMode: OverlayDatabaseMode;
800+
useOverlayDatabaseCaching: boolean;
801+
}> {
773802
let overlayDatabaseMode = OverlayDatabaseMode.None;
803+
let useOverlayDatabaseCaching = false;
774804

775805
const modeEnv = process.env.CODEQL_OVERLAY_DATABASE_MODE;
776806
// Any unrecognized CODEQL_OVERLAY_DATABASE_MODE value will be ignored and
@@ -791,21 +821,28 @@ async function getOverlayDatabaseMode(
791821
) {
792822
if (isAnalyzingPullRequest()) {
793823
overlayDatabaseMode = OverlayDatabaseMode.Overlay;
824+
useOverlayDatabaseCaching = true;
794825
logger.info(
795826
`Setting overlay database mode to ${overlayDatabaseMode} ` +
796-
"because we are analyzing a pull request.",
827+
"with caching because we are analyzing a pull request.",
797828
);
798829
} else if (await isAnalyzingDefaultBranch()) {
799830
overlayDatabaseMode = OverlayDatabaseMode.OverlayBase;
831+
useOverlayDatabaseCaching = true;
800832
logger.info(
801833
`Setting overlay database mode to ${overlayDatabaseMode} ` +
802-
"because we are analyzing the default branch.",
834+
"with caching because we are analyzing the default branch.",
803835
);
804836
}
805837
}
806838

839+
const nonOverlayAnalysis = {
840+
overlayDatabaseMode: OverlayDatabaseMode.None,
841+
useOverlayDatabaseCaching: false,
842+
};
843+
807844
if (overlayDatabaseMode === OverlayDatabaseMode.None) {
808-
return OverlayDatabaseMode.None;
845+
return nonOverlayAnalysis;
809846
}
810847

811848
if (buildMode !== BuildMode.None) {
@@ -814,26 +851,29 @@ async function getOverlayDatabaseMode(
814851
`build-mode is set to "${buildMode}" instead of "none". ` +
815852
"Falling back to creating a normal full database instead.",
816853
);
817-
return OverlayDatabaseMode.None;
854+
return nonOverlayAnalysis;
818855
}
819856
if (!(await codeQlVersionAtLeast(codeql, CODEQL_OVERLAY_MINIMUM_VERSION))) {
820857
logger.warning(
821858
`Cannot build an ${overlayDatabaseMode} database because ` +
822859
`the CodeQL CLI is older than ${CODEQL_OVERLAY_MINIMUM_VERSION}. ` +
823860
"Falling back to creating a normal full database instead.",
824861
);
825-
return OverlayDatabaseMode.None;
862+
return nonOverlayAnalysis;
826863
}
827864
if ((await getGitRoot(sourceRoot)) === undefined) {
828865
logger.warning(
829866
`Cannot build an ${overlayDatabaseMode} database because ` +
830867
`the source root "${sourceRoot}" is not inside a git repository. ` +
831868
"Falling back to creating a normal full database instead.",
832869
);
833-
return OverlayDatabaseMode.None;
870+
return nonOverlayAnalysis;
834871
}
835872

836-
return overlayDatabaseMode;
873+
return {
874+
overlayDatabaseMode,
875+
useOverlayDatabaseCaching,
876+
};
837877
}
838878

839879
/**

0 commit comments

Comments
 (0)