-
Notifications
You must be signed in to change notification settings - Fork 398
Add option to give warning instead of failing the build if coverage is below threshold #1670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
roostaamir
wants to merge
4
commits into
coverlet-coverage:master
Choose a base branch
from
roostaamir:add-threshold-warning-option
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
989eaae
Add ThresholdAct option to MSBuild task
roostaamir 3b5bc1e
Fix review issues
roostaamir b63d399
Merge branch 'add-threshold-warning-option' of https://github.com/roo…
roostaamir d90a3f8
Sync threshold action logic with master branch updates
roostaamir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,7 @@ static int Main(string[] args) | |
| var threshold = new Option<string>("--threshold", "Exits with error if the coverage % is below value.") { Arity = ArgumentArity.ZeroOrOne }; | ||
| var thresholdTypes = new Option<List<string>>("--threshold-type", () => new List<string>(new string[] { "line", "branch", "method" }), "Coverage type to apply the threshold to.").FromAmong("line", "branch", "method"); | ||
| var thresholdStat = new Option<ThresholdStatistic>("--threshold-stat", () => ThresholdStatistic.Minimum, "Coverage statistic used to enforce the threshold value.") { Arity = ArgumentArity.ZeroOrOne }; | ||
| var thresholdAct = new Option<ThresholdAction>("--threshold-act", () => ThresholdAction.Fail, "The action to take when coverage is below the threshold value. Defaults to failing the build.") { Arity = ArgumentArity.ZeroOrOne }; | ||
| var excludeFilters = new Option<string[]>("--exclude", "Filter expressions to exclude specific modules and types.") { Arity = ArgumentArity.ZeroOrMore, AllowMultipleArgumentsPerToken = true }; | ||
| var includeFilters = new Option<string[]>("--include", "Filter expressions to include only specific modules and types.") { Arity = ArgumentArity.ZeroOrMore, AllowMultipleArgumentsPerToken = true }; | ||
| var excludedSourceFiles = new Option<string[]>("--exclude-by-file", "Glob patterns specifying source files to exclude.") { Arity = ArgumentArity.ZeroOrMore, AllowMultipleArgumentsPerToken = true }; | ||
|
|
@@ -61,6 +62,7 @@ static int Main(string[] args) | |
| threshold, | ||
| thresholdTypes, | ||
| thresholdStat, | ||
| thresholdAct, | ||
| excludeFilters, | ||
| includeFilters, | ||
| excludedSourceFiles, | ||
|
|
@@ -89,6 +91,7 @@ static int Main(string[] args) | |
| string thresholdValue = context.ParseResult.GetValueForOption(threshold); | ||
| List<string> thresholdTypesValue = context.ParseResult.GetValueForOption(thresholdTypes); | ||
| ThresholdStatistic thresholdStatValue = context.ParseResult.GetValueForOption(thresholdStat); | ||
| ThresholdAction thresholdActValue = context.ParseResult.GetValueForOption(thresholdAct); | ||
| string[] excludeFiltersValue = context.ParseResult.GetValueForOption(excludeFilters); | ||
| string[] includeFiltersValue = context.ParseResult.GetValueForOption(includeFilters); | ||
| string[] excludedSourceFilesValue = context.ParseResult.GetValueForOption(excludedSourceFiles); | ||
|
|
@@ -115,6 +118,7 @@ static int Main(string[] args) | |
| thresholdValue, | ||
| thresholdTypesValue, | ||
| thresholdStatValue, | ||
| thresholdActValue, | ||
| excludeFiltersValue, | ||
| includeFiltersValue, | ||
| excludedSourceFilesValue, | ||
|
|
@@ -142,6 +146,7 @@ private static Task<int> HandleCommand(string moduleOrAppDirectory, | |
| string threshold, | ||
| List<string> thresholdTypes, | ||
| ThresholdStatistic thresholdStat, | ||
| ThresholdAction thresholdAct, | ||
| string[] excludeFilters, | ||
| string[] includeFilters, | ||
| string[] excludedSourceFiles, | ||
|
|
@@ -380,12 +385,21 @@ string sourceMappingFile | |
| { | ||
| exceptionMessageBuilder.AppendLine($"The {thresholdStat.ToString().ToLower()} method coverage is below the specified {thresholdTypeFlagValues[ThresholdTypeFlags.Method]}"); | ||
| } | ||
| throw new Exception(exceptionMessageBuilder.ToString()); | ||
|
|
||
| switch (thresholdAct) | ||
| { | ||
| case ThresholdAction.Warning: | ||
| logger.LogWarning(exceptionMessageBuilder.ToString()); | ||
| break; | ||
| case ThresholdAction.Fail: | ||
| exitCode += (int)CommandExitCodes.CoverageBelowThreshold; | ||
| throw new Exception(exceptionMessageBuilder.ToString()); | ||
|
Comment on lines
+394
to
+396
|
||
| default: | ||
| throw new ArgumentOutOfRangeException(nameof(thresholdAct), thresholdAct, "Unhandled threshold action"); | ||
| } | ||
| } | ||
|
|
||
| return Task.FromResult(exitCode); | ||
|
|
||
|
|
||
| } | ||
|
|
||
| catch (Win32Exception we) when (we.Source == "System.Diagnostics.Process") | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // Copyright (c) Toni Solarin-Sodara | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| namespace Coverlet.Core.Enums | ||
| { | ||
| internal enum ThresholdAction | ||
| { | ||
| Fail, | ||
| Warning | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In
Warningmode this block only logs a warning, butexitCodehas already been set toCoverageBelowThresholdearlier in the method, so--threshold-act warningwill still exit non-zero. To match the intended behavior, avoid setting the coverage-below-threshold exit code whenthresholdAct == Warning(set it only in theFailpath).