percentageChanges)
{
var significantHtml = string.Join("", significantLines.Select(line => $"{line}"));
var minorHtml = string.Join("", minorLines.Select(line => $"{line}"));
var detailsHtml = string.Join("", percentageChanges.Select(change =>
$"{change.Key} changed by {change.Value:F2}% to {newRow[change.Key]}"
));
return $@"
Report on {newRow["buildversion"]}
{message}
▼ Click to see all details
";
}
// Writes the new new report HTML report
static void WriteHtmlReport(string outputPath, string outputName, string baseHtml, string insertAfterTag, string reportContent)
{
string outputFilePath = Path.Combine(outputPath, outputName);
string content;
// Append if the file exists, otherwise use the base template
if (File.Exists(outputFilePath))
{
content = File.ReadAllText(outputFilePath);
}
else
{
content = baseHtml;
}
// Append the report after the first instance of the specified tag
string insertTag = $"";
int insertIndex = content.IndexOf(insertTag) + insertTag.Length;
content = content.Insert(insertIndex, reportContent);
File.WriteAllText(outputFilePath, content);
}
// Creates a JSON file with a content summary of the regression report it generated
static void DumpContentsToJson(string filePath, DataRow oldRow, DataRow newRow, Dictionary significantRegressions, Dictionary percentageChanges, string testName)
{
// Store regression information in a dictionary
var regressions = new Dictionary();
foreach (var regression in significantRegressions)
{
string stat = regression.Key;
regressions[stat] = new
{
percentage_change = $"{percentageChanges[stat]:F2}%",
original_value = oldRow[stat].ToString(),
new_value = newRow[stat].ToString()
};
}
// Create new JSON object
var jsonObject = new
{
had_regression = significantRegressions.Count != 0,
commit = $"CL {newRow["buildversion"]}",
test = testName,
html_path = filePath.Replace(".json", ".html"),
regressions = regressions
};
// Write JSON object to path provided
string jsonString = JsonSerializer.Serialize(jsonObject, new JsonSerializerOptions { WriteIndented = true });
File.WriteAllText(filePath, jsonString);
}
static int Main(string[] args)
{
Program program = new Program();
if (Debugger.IsAttached)
{
program.Run(args);
}
else
{
try
{
program.Run(args);
}
catch (System.Exception e)
{
Console.WriteLine("[ERROR] " + e.Message);
return 1;
}
}
return 0;
}
}
}