Skip to content

Commit 1f8a3e5

Browse files
committed
AugmentationProperties: add useOverlayDatabaseCaching
This commit adds a useOverlayDatabaseCaching property 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 e3cc4a7 commit 1f8a3e5

File tree

1 file changed

+59
-19
lines changed

1 file changed

+59
-19
lines changed

src/config-utils.ts

Lines changed: 59 additions & 19 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

@@ -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,
@@ -718,6 +735,7 @@ export async function calculateAugmentation(
718735
qualityQueriesInput,
719736
extraQueryExclusions,
720737
overlayDatabaseMode,
738+
useOverlayDatabaseCaching,
721739
};
722740
}
723741

@@ -745,26 +763,38 @@ function parseQueriesFromInput(
745763
}
746764

747765
/**
748-
* Calculate and validate the overlay database mode to use.
766+
* Calculate and validate the overlay database mode and caching to use.
749767
*
750768
* - 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.
751773
* - 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.
755778
* - Otherwise, use `None`.
756779
*
757780
* For `Overlay` and `OverlayBase`, the function performs further checks and
758781
* 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.
759785
*/
760786
async function getOverlayDatabaseMode(
761787
codeql: CodeQL,
762788
features: FeatureEnablement,
763789
sourceRoot: string,
764790
buildMode: BuildMode | undefined,
765791
logger: Logger,
766-
): Promise<OverlayDatabaseMode> {
792+
): Promise<{
793+
overlayDatabaseMode: OverlayDatabaseMode;
794+
useOverlayDatabaseCaching: boolean;
795+
}> {
767796
let overlayDatabaseMode = OverlayDatabaseMode.None;
797+
let useOverlayDatabaseCaching = false;
768798

769799
const modeEnv = process.env.CODEQL_OVERLAY_DATABASE_MODE;
770800
// Any unrecognized CODEQL_OVERLAY_DATABASE_MODE value will be ignored and
@@ -782,21 +812,28 @@ async function getOverlayDatabaseMode(
782812
} else if (await features.getValue(Feature.OverlayAnalysis, codeql)) {
783813
if (isAnalyzingPullRequest()) {
784814
overlayDatabaseMode = OverlayDatabaseMode.Overlay;
815+
useOverlayDatabaseCaching = true;
785816
logger.info(
786817
`Setting overlay database mode to ${overlayDatabaseMode} ` +
787-
"because we are analyzing a pull request.",
818+
"with caching because we are analyzing a pull request.",
788819
);
789820
} else if (await isAnalyzingDefaultBranch()) {
790821
overlayDatabaseMode = OverlayDatabaseMode.OverlayBase;
822+
useOverlayDatabaseCaching = true;
791823
logger.info(
792824
`Setting overlay database mode to ${overlayDatabaseMode} ` +
793-
"because we are analyzing the default branch.",
825+
"with caching because we are analyzing the default branch.",
794826
);
795827
}
796828
}
797829

830+
const nonOverlayAnalysis = {
831+
overlayDatabaseMode: OverlayDatabaseMode.None,
832+
useOverlayDatabaseCaching: false,
833+
};
834+
798835
if (overlayDatabaseMode === OverlayDatabaseMode.None) {
799-
return OverlayDatabaseMode.None;
836+
return nonOverlayAnalysis;
800837
}
801838

802839
if (buildMode !== BuildMode.None) {
@@ -805,26 +842,29 @@ async function getOverlayDatabaseMode(
805842
`build-mode is set to "${buildMode}" instead of "none". ` +
806843
"Falling back to creating a normal full database instead.",
807844
);
808-
return OverlayDatabaseMode.None;
845+
return nonOverlayAnalysis;
809846
}
810847
if (!(await codeQlVersionAtLeast(codeql, CODEQL_OVERLAY_MINIMUM_VERSION))) {
811848
logger.warning(
812849
`Cannot build an ${overlayDatabaseMode} database because ` +
813850
`the CodeQL CLI is older than ${CODEQL_OVERLAY_MINIMUM_VERSION}. ` +
814851
"Falling back to creating a normal full database instead.",
815852
);
816-
return OverlayDatabaseMode.None;
853+
return nonOverlayAnalysis;
817854
}
818855
if ((await getGitRoot(sourceRoot)) === undefined) {
819856
logger.warning(
820857
`Cannot build an ${overlayDatabaseMode} database because ` +
821858
`the source root "${sourceRoot}" is not inside a git repository. ` +
822859
"Falling back to creating a normal full database instead.",
823860
);
824-
return OverlayDatabaseMode.None;
861+
return nonOverlayAnalysis;
825862
}
826863

827-
return overlayDatabaseMode;
864+
return {
865+
overlayDatabaseMode,
866+
useOverlayDatabaseCaching,
867+
};
828868
}
829869

830870
/**

0 commit comments

Comments
 (0)