diff --git a/lib/init-action.js b/lib/init-action.js index 6b9af9b69..34b9335f5 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -109094,15 +109094,19 @@ function cleanupDatabaseClusterDirectory(config, logger, options = {}, rmSync2 = } } async function getFileCoverageInformationEnabled(debugMode, codeql, features, repositoryProperties) { - 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 repositories to opt in to file coverage information on PRs - // using a repository property. - repositoryProperties["github-codeql-file-coverage-on-prs" /* FILE_COVERAGE_ON_PRS */] === true || !await features.getValue("skip_file_coverage_on_prs" /* SkipFileCoverageOnPrs */, codeql) - ); + if (debugMode) { + return { enabled: true, enabledByRepositoryProperty: false }; + } + if (!isAnalyzingPullRequest()) { + return { enabled: true, enabledByRepositoryProperty: false }; + } + if (!await features.getValue("skip_file_coverage_on_prs" /* SkipFileCoverageOnPrs */, codeql)) { + return { enabled: true, enabledByRepositoryProperty: false }; + } + if (repositoryProperties["github-codeql-file-coverage-on-prs" /* FILE_COVERAGE_ON_PRS */] === true) { + return { enabled: true, enabledByRepositoryProperty: true }; + } + return { enabled: false, enabledByRepositoryProperty: false }; } // src/status-report.ts @@ -109714,6 +109718,12 @@ async function run(startedAt) { analysisKinds = await getAnalysisKinds(logger); const debugMode = getOptionalInput("debug") === "true" || core13.isDebug(); const repositoryProperties = repositoryPropertiesResult.orElse({}); + const fileCoverageResult = await getFileCoverageInformationEnabled( + debugMode, + codeql, + features, + repositoryProperties + ); config = await initConfig2(features, { analysisKinds, languagesInput: getOptionalInput("languages"), @@ -109742,12 +109752,7 @@ async function run(startedAt) { apiDetails, features, repositoryProperties, - enableFileCoverageInformation: await getFileCoverageInformationEnabled( - debugMode, - codeql, - features, - repositoryProperties - ), + enableFileCoverageInformation: fileCoverageResult.enabled, logger }); if (repositoryPropertiesResult.isFailure()) { @@ -109762,7 +109767,7 @@ async function run(startedAt) { ) ); } - if (config.enableFileCoverageInformation && isAnalyzingPullRequest() && await features.getValue("skip_file_coverage_on_prs" /* SkipFileCoverageOnPrs */, codeql) && repositoryProperties["github-codeql-file-coverage-on-prs" /* FILE_COVERAGE_ON_PRS */] === true) { + if (fileCoverageResult.enabledByRepositoryProperty) { addNoLanguageDiagnostic( config, makeTelemetryDiagnostic( diff --git a/src/init-action.ts b/src/init-action.ts index 6a386ed7a..577292ecd 100644 --- a/src/init-action.ts +++ b/src/init-action.ts @@ -14,7 +14,6 @@ import { getOptionalInput, getRequiredInput, getTemporaryDirectory, - isAnalyzingPullRequest, persistInputs, } from "./actions-util"; import { AnalysisKind, getAnalysisKinds } from "./analyses"; @@ -43,7 +42,6 @@ import { Feature, FeatureEnablement, initFeatures } from "./feature-flags"; import { loadPropertiesFromApi, RepositoryProperties, - RepositoryPropertyName, } from "./feature-flags/properties"; import { checkInstallPython311, @@ -349,6 +347,13 @@ async function run(startedAt: Date) { analysisKinds = await getAnalysisKinds(logger); const debugMode = getOptionalInput("debug") === "true" || core.isDebug(); const repositoryProperties = repositoryPropertiesResult.orElse({}); + const fileCoverageResult = await getFileCoverageInformationEnabled( + debugMode, + codeql, + features, + repositoryProperties, + ); + config = await initConfig(features, { analysisKinds, languagesInput: getOptionalInput("languages"), @@ -379,12 +384,7 @@ async function run(startedAt: Date) { apiDetails, features, repositoryProperties, - enableFileCoverageInformation: await getFileCoverageInformationEnabled( - debugMode, - codeql, - features, - repositoryProperties, - ), + enableFileCoverageInformation: fileCoverageResult.enabled, logger, }); @@ -401,12 +401,7 @@ async function run(startedAt: Date) { ); } - if ( - config.enableFileCoverageInformation && - isAnalyzingPullRequest() && - (await features.getValue(Feature.SkipFileCoverageOnPrs, codeql)) && - repositoryProperties[RepositoryPropertyName.FILE_COVERAGE_ON_PRS] === true - ) { + if (fileCoverageResult.enabledByRepositoryProperty) { addNoLanguageDiagnostic( config, makeTelemetryDiagnostic( diff --git a/src/init.test.ts b/src/init.test.ts index dbc4b4c30..c37d1c1e6 100644 --- a/src/init.test.ts +++ b/src/init.test.ts @@ -452,14 +452,14 @@ test( ); test("file coverage information enabled when debugMode is true", async (t) => { - t.true( - await getFileCoverageInformationEnabled( - true, // debugMode - createStubCodeQL({}), - createFeatures([Feature.SkipFileCoverageOnPrs]), - {}, - ), + const result = await getFileCoverageInformationEnabled( + true, // debugMode + createStubCodeQL({}), + createFeatures([Feature.SkipFileCoverageOnPrs]), + {}, ); + t.true(result.enabled); + t.false(result.enabledByRepositoryProperty); }); test.serial( @@ -467,14 +467,14 @@ test.serial( async (t) => { sinon.stub(actionsUtil, "isAnalyzingPullRequest").returns(false); - t.true( - await getFileCoverageInformationEnabled( - false, // debugMode - createStubCodeQL({}), - createFeatures([Feature.SkipFileCoverageOnPrs]), - {}, - ), + const result = await getFileCoverageInformationEnabled( + false, // debugMode + createStubCodeQL({}), + createFeatures([Feature.SkipFileCoverageOnPrs]), + {}, ); + t.true(result.enabled); + t.false(result.enabledByRepositoryProperty); }, ); @@ -483,14 +483,14 @@ test.serial( async (t) => { sinon.stub(actionsUtil, "isAnalyzingPullRequest").returns(true); - t.true( - await getFileCoverageInformationEnabled( - false, // debugMode - createStubCodeQL({}), - createFeatures([]), - {}, - ), + const result = await getFileCoverageInformationEnabled( + false, // debugMode + createStubCodeQL({}), + createFeatures([]), + {}, ); + t.true(result.enabled); + t.false(result.enabledByRepositoryProperty); }, ); @@ -499,16 +499,16 @@ test.serial( async (t) => { sinon.stub(actionsUtil, "isAnalyzingPullRequest").returns(true); - t.true( - await getFileCoverageInformationEnabled( - false, // debugMode - createStubCodeQL({}), - createFeatures([Feature.SkipFileCoverageOnPrs]), - { - "github-codeql-file-coverage-on-prs": true, - }, - ), + const result = await getFileCoverageInformationEnabled( + false, // debugMode + createStubCodeQL({}), + createFeatures([Feature.SkipFileCoverageOnPrs]), + { + "github-codeql-file-coverage-on-prs": true, + }, ); + t.true(result.enabled); + t.true(result.enabledByRepositoryProperty); }, ); @@ -517,13 +517,13 @@ test.serial( async (t) => { sinon.stub(actionsUtil, "isAnalyzingPullRequest").returns(true); - t.false( - await getFileCoverageInformationEnabled( - false, // debugMode - createStubCodeQL({}), - createFeatures([Feature.SkipFileCoverageOnPrs]), - {}, - ), + const result = await getFileCoverageInformationEnabled( + false, // debugMode + createStubCodeQL({}), + createFeatures([Feature.SkipFileCoverageOnPrs]), + {}, ); + t.false(result.enabled); + t.false(result.enabledByRepositoryProperty); }, ); diff --git a/src/init.ts b/src/init.ts index b5e90b68b..a1c6b2108 100644 --- a/src/init.ts +++ b/src/init.ts @@ -306,18 +306,32 @@ export async function getFileCoverageInformationEnabled( codeql: CodeQL, features: FeatureEnablement, repositoryProperties: RepositoryProperties, -): Promise { - 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 repositories to opt in to file coverage information on PRs - // using a repository property. - repositoryProperties[RepositoryPropertyName.FILE_COVERAGE_ON_PRS] === - true || - !(await features.getValue(Feature.SkipFileCoverageOnPrs, codeql)) - ); +): Promise<{ + enabled: boolean; + enabledByRepositoryProperty: boolean; +}> { + // Always enable file coverage information in debug mode + if (debugMode) { + return { enabled: true, enabledByRepositoryProperty: false }; + } + // 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 { enabled: true, enabledByRepositoryProperty: false }; + } + // If the feature is disabled, then maintain the previous behavior of + // unconditionally computing file coverage information. + if (!(await features.getValue(Feature.SkipFileCoverageOnPrs, codeql))) { + return { enabled: true, enabledByRepositoryProperty: false }; + } + // Allow repositories to opt in to file coverage information on PRs + // using a repository property. + if ( + repositoryProperties[RepositoryPropertyName.FILE_COVERAGE_ON_PRS] === true + ) { + return { enabled: true, enabledByRepositoryProperty: true }; + } + // Otherwise, disable file coverage information on PRs to speed up analysis. + return { enabled: false, enabledByRepositoryProperty: false }; }