mirror of
https://github.com/irongut/CodeCoverageSummary.git
synced 2026-06-12 15:40:47 +00:00
added ability to fail a workflow #16
This commit is contained in:
@@ -13,6 +13,11 @@ namespace CodeCoverageSummary
|
|||||||
|
|
||||||
public bool Badge => BadgeString.Equals("true", StringComparison.OrdinalIgnoreCase);
|
public bool Badge => BadgeString.Equals("true", StringComparison.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
[Option(longName: "fail", Required = false, HelpText = "Fail if overall Line Rate below lower threshold - true or false.", Default = "false")]
|
||||||
|
public string FailString { get; set; }
|
||||||
|
|
||||||
|
public bool FailBelowThreshold => FailString.Equals("true", StringComparison.OrdinalIgnoreCase);
|
||||||
|
|
||||||
[Option(longName: "format", Required = false, HelpText = "Output Format - markdown or text.", Default = "text")]
|
[Option(longName: "format", Required = false, HelpText = "Output Format - markdown or text.", Default = "text")]
|
||||||
public string Format { get; set; }
|
public string Format { get; set; }
|
||||||
|
|
||||||
@@ -24,7 +29,7 @@ namespace CodeCoverageSummary
|
|||||||
[Option(longName: "output", Required = false, HelpText = "Output Type - console, file or both.", Default = "console")]
|
[Option(longName: "output", Required = false, HelpText = "Output Type - console, file or both.", Default = "console")]
|
||||||
public string Output { get; set; }
|
public string Output { get; set; }
|
||||||
|
|
||||||
[Option(longName: "thresholds", Required = false, HelpText = "Badge and health indicator threshold percentages.", Default = "50 75")]
|
[Option(longName: "thresholds", Required = false, HelpText = "Threshold percentages for badge and health indicators, lower threshold can also be used to fail the action.", Default = "50 75")]
|
||||||
public string Thresholds { get; set; }
|
public string Thresholds { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,11 +49,15 @@ namespace CodeCoverageSummary
|
|||||||
{
|
{
|
||||||
fileExt = "txt";
|
fileExt = "txt";
|
||||||
output = GenerateTextOutput(summary, badgeUrl, o.Indicators);
|
output = GenerateTextOutput(summary, badgeUrl, o.Indicators);
|
||||||
|
if (o.FailBelowThreshold)
|
||||||
|
output += $"Minimum allowed line rate is {lowerThreshold * 100:N0}%{Environment.NewLine}";
|
||||||
}
|
}
|
||||||
else if (o.Format.Equals("md", StringComparison.OrdinalIgnoreCase) || o.Format.Equals("markdown", StringComparison.OrdinalIgnoreCase))
|
else if (o.Format.Equals("md", StringComparison.OrdinalIgnoreCase) || o.Format.Equals("markdown", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
fileExt = "md";
|
fileExt = "md";
|
||||||
output = GenerateMarkdownOutput(summary, badgeUrl, o.Indicators);
|
output = GenerateMarkdownOutput(summary, badgeUrl, o.Indicators);
|
||||||
|
if (o.FailBelowThreshold)
|
||||||
|
output += $"{Environment.NewLine}_Minimum allowed line rate is `{lowerThreshold * 100:N0}%`_{Environment.NewLine}";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -81,6 +85,12 @@ namespace CodeCoverageSummary
|
|||||||
return -2; // error
|
return -2; // error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (o.FailBelowThreshold && summary.LineRate < lowerThreshold)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"FAIL: Overall line rate below minimum threshold of {lowerThreshold * 100:N0}%.");
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
return 0; // success
|
return 0; // success
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"profiles": {
|
"profiles": {
|
||||||
"CodeCoverageSummary": {
|
"CodeCoverageSummary": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"commandLineArgs": "../../../../coverage.cobertura.xml --format=md --badge true --thresholds=\"80 90\""
|
"commandLineArgs": "../../../../coverage.cobertura.xml --format=md --badge true --thresholds=\"85 90\" --fail true"
|
||||||
},
|
},
|
||||||
"Docker": {
|
"Docker": {
|
||||||
"commandName": "Docker",
|
"commandName": "Docker",
|
||||||
|
|||||||
Reference in New Issue
Block a user