mirror of
https://github.com/github/codeql-action.git
synced 2025-12-06 07:48:17 +08:00
Add unit tests for disabling overlay analysis by custom repo property
This commit is contained in:
55
lib/init-action.js
generated
55
lib/init-action.js
generated
@@ -87845,6 +87845,7 @@ function getUnknownLanguagesError(languages) {
|
||||
// src/feature-flags/properties.ts
|
||||
var RepositoryPropertyName = /* @__PURE__ */ ((RepositoryPropertyName2) => {
|
||||
RepositoryPropertyName2["EXTRA_QUERIES"] = "github-codeql-extra-queries";
|
||||
RepositoryPropertyName2["DISABLE_OVERLAY_ANALYSIS"] = "github-codeql-disable-overlay-analysis";
|
||||
return RepositoryPropertyName2;
|
||||
})(RepositoryPropertyName || {});
|
||||
async function loadPropertiesFromApi(gitHubVersion, logger, repositoryNwo) {
|
||||
@@ -89403,34 +89404,39 @@ async function isOverlayAnalysisFeatureEnabled(repository, features, codeql, lan
|
||||
}
|
||||
return true;
|
||||
}
|
||||
async function getOverlayDatabaseMode(codeql, repository, features, languages, sourceRoot, buildMode, codeScanningConfig, logger) {
|
||||
async function getOverlayDatabaseMode(codeql, repository, features, languages, sourceRoot, buildMode, codeScanningConfig, repositoryProperties, logger) {
|
||||
let overlayDatabaseMode = "none" /* None */;
|
||||
let useOverlayDatabaseCaching = false;
|
||||
const modeEnv = process.env.CODEQL_OVERLAY_DATABASE_MODE;
|
||||
if (modeEnv === "overlay" /* Overlay */ || modeEnv === "overlay-base" /* OverlayBase */ || modeEnv === "none" /* None */) {
|
||||
overlayDatabaseMode = modeEnv;
|
||||
logger.info(
|
||||
`Setting overlay database mode to ${overlayDatabaseMode} from the CODEQL_OVERLAY_DATABASE_MODE environment variable.`
|
||||
);
|
||||
} else if (await isOverlayAnalysisFeatureEnabled(
|
||||
repository,
|
||||
features,
|
||||
codeql,
|
||||
languages,
|
||||
codeScanningConfig
|
||||
)) {
|
||||
if (isAnalyzingPullRequest()) {
|
||||
overlayDatabaseMode = "overlay" /* Overlay */;
|
||||
useOverlayDatabaseCaching = true;
|
||||
const overlayAnalysisDisabled = repositoryProperties["github-codeql-disable-overlay-analysis" /* DISABLE_OVERLAY_ANALYSIS */];
|
||||
if (overlayAnalysisDisabled && overlayAnalysisDisabled === "true") {
|
||||
logger.info(`Setting overlay database mode to ${overlayDatabaseMode} because overlay analysis is disabled by a custom repository property.`);
|
||||
} else {
|
||||
const modeEnv = process.env.CODEQL_OVERLAY_DATABASE_MODE;
|
||||
if (modeEnv === "overlay" /* Overlay */ || modeEnv === "overlay-base" /* OverlayBase */ || modeEnv === "none" /* None */) {
|
||||
overlayDatabaseMode = modeEnv;
|
||||
logger.info(
|
||||
`Setting overlay database mode to ${overlayDatabaseMode} with caching because we are analyzing a pull request.`
|
||||
);
|
||||
} else if (await isAnalyzingDefaultBranch()) {
|
||||
overlayDatabaseMode = "overlay-base" /* OverlayBase */;
|
||||
useOverlayDatabaseCaching = true;
|
||||
logger.info(
|
||||
`Setting overlay database mode to ${overlayDatabaseMode} with caching because we are analyzing the default branch.`
|
||||
`Setting overlay database mode to ${overlayDatabaseMode} from the CODEQL_OVERLAY_DATABASE_MODE environment variable.`
|
||||
);
|
||||
} else if (await isOverlayAnalysisFeatureEnabled(
|
||||
repository,
|
||||
features,
|
||||
codeql,
|
||||
languages,
|
||||
codeScanningConfig
|
||||
)) {
|
||||
if (isAnalyzingPullRequest()) {
|
||||
overlayDatabaseMode = "overlay" /* Overlay */;
|
||||
useOverlayDatabaseCaching = true;
|
||||
logger.info(
|
||||
`Setting overlay database mode to ${overlayDatabaseMode} with caching because we are analyzing a pull request.`
|
||||
);
|
||||
} else if (await isAnalyzingDefaultBranch()) {
|
||||
overlayDatabaseMode = "overlay-base" /* OverlayBase */;
|
||||
useOverlayDatabaseCaching = true;
|
||||
logger.info(
|
||||
`Setting overlay database mode to ${overlayDatabaseMode} with caching because we are analyzing the default branch.`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
const nonOverlayAnalysis = {
|
||||
@@ -89527,6 +89533,7 @@ async function initConfig(features, inputs) {
|
||||
inputs.sourceRoot,
|
||||
config.buildMode,
|
||||
config.computedConfig,
|
||||
inputs.repositoryProperties,
|
||||
logger
|
||||
);
|
||||
logger.info(
|
||||
|
||||
@@ -38,6 +38,7 @@ import {
|
||||
withTmpDir,
|
||||
BuildMode,
|
||||
} from "./util";
|
||||
import { RepositoryProperties, RepositoryPropertyName } from "./feature-flags/properties";
|
||||
|
||||
setupTests(test);
|
||||
|
||||
@@ -1005,6 +1006,7 @@ interface OverlayDatabaseModeTestSetup {
|
||||
codeqlVersion: string;
|
||||
gitRoot: string | undefined;
|
||||
codeScanningConfig: configUtils.UserConfig;
|
||||
repositoryProperties?: RepositoryProperties | undefined;
|
||||
}
|
||||
|
||||
const defaultOverlayDatabaseModeTestSetup: OverlayDatabaseModeTestSetup = {
|
||||
@@ -1092,6 +1094,7 @@ const getOverlayDatabaseModeMacro = test.macro({
|
||||
tempDir, // sourceRoot
|
||||
setup.buildMode,
|
||||
setup.codeScanningConfig,
|
||||
setup.repositoryProperties || {},
|
||||
logger,
|
||||
);
|
||||
|
||||
@@ -1180,6 +1183,21 @@ test(
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
getOverlayDatabaseModeMacro,
|
||||
"Overlay analysis disabled by repository property overrides overlay-base database on default branch when feature enabled",
|
||||
{
|
||||
languages: [KnownLanguage.javascript],
|
||||
features: [Feature.OverlayAnalysis, Feature.OverlayAnalysisJavascript],
|
||||
isDefaultBranch: true,
|
||||
repositoryProperties: { [RepositoryPropertyName.DISABLE_OVERLAY_ANALYSIS]: "true" },
|
||||
},
|
||||
{
|
||||
overlayDatabaseMode: OverlayDatabaseMode.None,
|
||||
useOverlayDatabaseCaching: false,
|
||||
},
|
||||
)
|
||||
|
||||
test(
|
||||
getOverlayDatabaseModeMacro,
|
||||
"Overlay-base database on default branch when feature enabled with custom analysis",
|
||||
@@ -1214,6 +1232,24 @@ test(
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
getOverlayDatabaseModeMacro,
|
||||
"Overlay analysis disabled by repository property overrides overlay-base database on default branch when code-scanning feature enabled",
|
||||
{
|
||||
languages: [KnownLanguage.javascript],
|
||||
features: [
|
||||
Feature.OverlayAnalysis,
|
||||
Feature.OverlayAnalysisCodeScanningJavascript,
|
||||
],
|
||||
isDefaultBranch: true,
|
||||
repositoryProperties: { [RepositoryPropertyName.DISABLE_OVERLAY_ANALYSIS]: "true" },
|
||||
},
|
||||
{
|
||||
overlayDatabaseMode: OverlayDatabaseMode.None,
|
||||
useOverlayDatabaseCaching: false,
|
||||
},
|
||||
)
|
||||
|
||||
test(
|
||||
getOverlayDatabaseModeMacro,
|
||||
"No overlay-base database on default branch when code-scanning feature enabled with disable-default-queries",
|
||||
@@ -1350,6 +1386,21 @@ test(
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
getOverlayDatabaseModeMacro,
|
||||
"Overlay analysis disabled by repository property overrides overlay analysis on PR when feature enabled",
|
||||
{
|
||||
languages: [KnownLanguage.javascript],
|
||||
features: [Feature.OverlayAnalysis, Feature.OverlayAnalysisJavascript],
|
||||
isPullRequest: true,
|
||||
repositoryProperties: { [RepositoryPropertyName.DISABLE_OVERLAY_ANALYSIS]: "true" },
|
||||
},
|
||||
{
|
||||
overlayDatabaseMode: OverlayDatabaseMode.None,
|
||||
useOverlayDatabaseCaching: false,
|
||||
},
|
||||
)
|
||||
|
||||
test(
|
||||
getOverlayDatabaseModeMacro,
|
||||
"Overlay analysis on PR when feature enabled with custom analysis",
|
||||
@@ -1532,6 +1583,34 @@ test(
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
getOverlayDatabaseModeMacro,
|
||||
"Overlay analysis disabled by repository property overrides PR analysis by env for other-org",
|
||||
{
|
||||
overlayDatabaseEnvVar: "overlay",
|
||||
repositoryOwner: "other-org",
|
||||
repositoryProperties: { [RepositoryPropertyName.DISABLE_OVERLAY_ANALYSIS]: "true" },
|
||||
},
|
||||
{
|
||||
overlayDatabaseMode: OverlayDatabaseMode.None,
|
||||
useOverlayDatabaseCaching: false,
|
||||
},
|
||||
)
|
||||
|
||||
test(
|
||||
getOverlayDatabaseModeMacro,
|
||||
"Disable overlay analysis repository property must be true to disable overlay analysis",
|
||||
{
|
||||
overlayDatabaseEnvVar: "overlay",
|
||||
repositoryOwner: "other-org",
|
||||
repositoryProperties: { [RepositoryPropertyName.DISABLE_OVERLAY_ANALYSIS]: "false" },
|
||||
},
|
||||
{
|
||||
overlayDatabaseMode: OverlayDatabaseMode.Overlay,
|
||||
useOverlayDatabaseCaching: false,
|
||||
},
|
||||
)
|
||||
|
||||
test(
|
||||
getOverlayDatabaseModeMacro,
|
||||
"Overlay PR analysis by feature flag for dsp-testing",
|
||||
|
||||
@@ -666,7 +666,7 @@ export async function getOverlayDatabaseMode(
|
||||
let useOverlayDatabaseCaching = false;
|
||||
|
||||
const overlayAnalysisDisabled = repositoryProperties[RepositoryPropertyName.DISABLE_OVERLAY_ANALYSIS];
|
||||
if (overlayAnalysisDisabled) {
|
||||
if (overlayAnalysisDisabled && overlayAnalysisDisabled === "true") {
|
||||
logger.info(`Setting overlay database mode to ${overlayDatabaseMode} ` +
|
||||
`because overlay analysis is disabled by a custom repository property.`);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user