Log ability to re-enable via repo property

This commit is contained in:
Henry Mercer
2026-03-02 19:48:19 +01:00
parent b2fff91823
commit 003c59c557
10 changed files with 662 additions and 612 deletions

View File

@@ -2,6 +2,7 @@ import * as fs from "fs";
import * as path from "path";
import { performance } from "perf_hooks";
import * as github from "@actions/github";
import * as io from "@actions/io";
import * as yaml from "js-yaml";
@@ -22,6 +23,7 @@ import {
} from "./diff-informed-analysis-utils";
import { EnvVar } from "./environment";
import { FeatureEnablement, Feature } from "./feature-flags";
import { RepositoryPropertyName } from "./feature-flags/properties";
import { KnownLanguage, Language } from "./languages";
import { Logger, withGroupAsync } from "./logging";
import { OverlayDatabaseMode } from "./overlay";
@@ -502,9 +504,13 @@ export async function runQueries(
logger.info(qualityAnalysisSummary);
}
if (!config.enableFileCoverageInformation) {
const isOrgOwned =
github.context.payload.repository?.owner.type === "Organization";
const reenableMessage = isOrgOwned
? ` To enable file coverage information on pull requests, set the '${RepositoryPropertyName.ENABLE_FILE_COVERAGE_ON_PRS}' repository property to 'true'.`
: "";
logger.info(
"To speed up pull request analysis, file coverage information is only enabled when analyzing " +
"the default branch and protected branches.",
`To speed up pull request analysis, file coverage information is only enabled when analyzing the default branch and protected branches.${reenableMessage}`,
);
}

View File

@@ -381,6 +381,7 @@ async function run(startedAt: Date) {
repositoryNwo,
features,
repositoryPropertiesResult.orElse({}),
logger,
),
logger,
});

View File

@@ -14,6 +14,7 @@ import {
getFileCoverageInformationEnabled,
} from "./init";
import { KnownLanguage } from "./languages";
import { getRunnerLogger } from "./logging";
import { parseRepositoryNwo } from "./repository";
import {
createFeatures,
@@ -457,6 +458,7 @@ test("file coverage information enabled when debugMode is true", async (t) => {
parseRepositoryNwo("github/codeql-action"),
createFeatures([Feature.SkipFileCoverageOnPrs]),
{},
getRunnerLogger(true),
),
);
});
@@ -470,6 +472,7 @@ test("file coverage information enabled when not analyzing a pull request", asyn
parseRepositoryNwo("github/codeql-action"),
createFeatures([Feature.SkipFileCoverageOnPrs]),
{},
getRunnerLogger(true),
),
);
});
@@ -483,6 +486,7 @@ test("file coverage information enabled when owner is not 'github'", async (t) =
parseRepositoryNwo("other-org/some-repo"),
createFeatures([Feature.SkipFileCoverageOnPrs]),
{},
getRunnerLogger(true),
),
);
});
@@ -496,6 +500,7 @@ test("file coverage information enabled when feature flag is not enabled", async
parseRepositoryNwo("github/codeql-action"),
createFeatures([]),
{},
getRunnerLogger(true),
),
);
});
@@ -509,6 +514,7 @@ test("file coverage information disabled when all conditions for skipping are me
parseRepositoryNwo("github/codeql-action"),
createFeatures([Feature.SkipFileCoverageOnPrs]),
{},
getRunnerLogger(true),
),
);
});
@@ -516,6 +522,9 @@ test("file coverage information disabled when all conditions for skipping are me
test("file coverage information enabled when repository property enables it on PRs", async (t) => {
sinon.stub(actionsUtil, "isAnalyzingPullRequest").returns(true);
const messages: LoggedMessage[] = [];
const logger = getRecordingLogger(messages);
t.true(
await getFileCoverageInformationEnabled(
false, // debugMode
@@ -524,6 +533,16 @@ test("file coverage information enabled when repository property enables it on P
{
[RepositoryPropertyName.ENABLE_FILE_COVERAGE_ON_PRS]: true,
},
logger,
),
);
t.true(
messages.some(
(m) =>
m.type === "info" &&
typeof m.message === "string" &&
m.message.includes(RepositoryPropertyName.ENABLE_FILE_COVERAGE_ON_PRS),
),
);
});

View File

@@ -307,20 +307,35 @@ export async function getFileCoverageInformationEnabled(
repositoryNwo: RepositoryNwo,
features: FeatureEnablement,
repositoryProperties: RepositoryProperties,
logger: Logger,
): Promise<boolean> {
return (
// Always enable file coverage information in debug mode
debugMode ||
// We're most interested in speeding up PRs, and we want to keep
// submitting file coverage information for the default branch since
// it is used to populate the status page.
!isAnalyzingPullRequest() ||
// Allow repository owners to opt in to file coverage on PRs via a
// repository property.
// Always enable file coverage information in debug mode
if (debugMode) return true;
// We're most interested in speeding up PRs, and we want to keep
// submitting file coverage information for the default branch since
// it is used to populate the status page.
if (!isAnalyzingPullRequest()) return true;
// Allow repository owners to opt in to file coverage on PRs via a
// repository property.
if (
repositoryProperties[RepositoryPropertyName.ENABLE_FILE_COVERAGE_ON_PRS] ===
true ||
// For now, restrict this feature to the GitHub org
repositoryNwo.owner !== "github" ||
!(await features.getValue(Feature.SkipFileCoverageOnPrs))
);
true
) {
logger.info(
"File coverage information on pull requests has been enabled by the " +
`'${RepositoryPropertyName.ENABLE_FILE_COVERAGE_ON_PRS}' repository property. ` +
"This will increase the time it takes to analyze pull requests, particularly on " +
"large repositories.",
);
return true;
}
// For now, restrict this feature to the GitHub org
if (repositoryNwo.owner !== "github") return true;
if (!(await features.getValue(Feature.SkipFileCoverageOnPrs))) return true;
return false;
}