Skip to content

Commit

Permalink
Version updates. Better TRX exception handling.
Browse files Browse the repository at this point in the history
- Update ScottPlot to new methods.
- Update to .NET 8.0.
- Handle TRX file without results element
  • Loading branch information
erichiller committed Oct 5, 2024
1 parent c9b96c1 commit a2d96cd
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_and_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 7.0.x
dotnet-version: 8.0.x
#
- name: Restore dependencies
run: dotnet restore
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 7.0.x
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
#
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run_unit_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
dotnet-version: 8.0.x
#
- name: Restore dependencies
run: dotnet restore
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-full-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
New-Item -Type Directory -Path './test-dir'
Set-Content -Path "./test-dir/test_json_file_plot_config_1.json" -Value '{ "Title": "Test plot from File", "OutputFileName": "test_json_file_plot.png", "PlotType": "Scatter", "Width": 800, "Height": 600, "Data": [ { "Title": "Series A", "X": [ 11, 52, 19 ], "Y": [ 57, 54, 31 ] } ]}'
- name: 'Run gh-action-plot'
uses: erichiller/gh-action-plot@v0.0.11-alpha
uses: erichiller/gh-action-plot@v1.0.3
with:
source_scan_dir: './mkmrk-channels/src'
plot_definitions_dir: './test-dir'
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build-env
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env
WORKDIR /action

ENV TZ="America/Chicago"
Expand All @@ -24,7 +24,7 @@ RUN du -sh .
RUN du -sh built

# Build runtime image
FROM mcr.microsoft.com/dotnet/runtime:7.0
FROM mcr.microsoft.com/dotnet/runtime:8.0
COPY --from=build-env /action/built/ /action

# required for fonts
Expand Down
2 changes: 1 addition & 1 deletion PlotGitHubAction.sln.DotSettings.user
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=c5240d5d_002Ddaa7_002D4363_002D8ef5_002Dfceb4f9b2cdd/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from &amp;lt;PlotGitHubAction.Tests&amp;gt;" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=107b0f58_002Dee98_002D4951_002Da899_002D5fa9bcab444d/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from &amp;lt;PlotGitHubAction.Tests&amp;gt;" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;
&lt;Project Location="/home/eric/dev/src/github.com/erichiller/gh-action-plot/test/PlotGitHubAction.Tests" Presentation="&amp;lt;PlotGitHubAction.Tests&amp;gt;" /&gt;
&lt;/SessionState&gt;</s:String></wpf:ResourceDictionary>
22 changes: 12 additions & 10 deletions src/PlotGitHubAction/PlotGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@

using ScottPlot;
using ScottPlot.Plottables;
using ScottPlot.TickGenerators;

using SkiaSharp;

namespace PlotGitHubAction;

public static class PlotGen {
private static readonly JsonSerializerOptions _serializer_options = Utils.SERIALIZER_OPTIONS;

public static string GetChartFilePath( string plotDefinitionsDir, string outputFileName ) => System.IO.Path.Join( plotDefinitionsDir, outputFileName ) is var path && path.EndsWith( ".png" ) ? path : $"{path}.png";
public static string GetChartFilePath( string plotDefinitionsDir, string outputFileName ) => Path.Join( plotDefinitionsDir, outputFileName ) is var path && path.EndsWith( ".png" ) ? path : $"{path}.png";

public static void CreatePlot( string jsonString, string plotDefinitionsDir ) {
Log.Info( $"==== {nameof(CreatePlot)} ====" );
Expand All @@ -31,11 +34,10 @@ private static void createPlot( string jsonString, string plotDefinitionsDir ) {
Log.Info( $"==== {nameof(CreatePlot)} ====" );
Log.Debug( $"Source JSON:\n{jsonString}" );

var plt = new ScottPlot.Plot();
plt.Style.SetBestFonts();
// plt.Style.AxisFrame( );
var plt = new Plot();
plt.Font.Automatic();

foreach ( var font in SkiaSharp.SKFontManager.Default.FontFamilies ) {
foreach ( var font in SKFontManager.Default.FontFamilies ) {
Log.Debug( font );
}
Log.Debug( $"Default = {Fonts.Default}" );
Expand Down Expand Up @@ -95,7 +97,7 @@ private static void createPlot( string jsonString, string plotDefinitionsDir ) {
size: markerSize.Value,
color: series.LineStyle.Color );
}
series.Label = data.Title;
series.LegendText = data.Title;
// diag
for ( int i = 0 ; i < xData.Length ; i++ ) {
Log.Verbose( $"#{i}\t{sorted[ i ].First} x {sorted[ i ].Second}" );
Expand All @@ -107,11 +109,11 @@ private static void createPlot( string jsonString, string plotDefinitionsDir ) {
*/

if ( config.YAxisType switch {
AxisType.Percent => new ScottPlot.TickGenerators.NumericAutomatic { LabelFormatter = static v => $"{v:p1}" },
AxisType.Percent => new NumericAutomatic { LabelFormatter = static v => $"{v:p1}" },
// AxisType.Numeric => new ScottPlot.TickGenerators.NumericFixedInterval { Interval = 1 },
// https://github.com/ScottPlot/ScottPlot/blob/main/src/ScottPlot5/ScottPlot5/TickGenerators/NumericAutomatic.cs
AxisType.Numeric => new ScottPlot.TickGenerators.NumericAutomatic { IntegerTicksOnly = true },
_ => ( ITickGenerator? )null
AxisType.Numeric => new NumericAutomatic { IntegerTicksOnly = true },
_ => ( ITickGenerator? )null
} is { } tickGenerator ) {
plt.Axes.Left.TickGenerator = tickGenerator;
}
Expand Down Expand Up @@ -143,7 +145,7 @@ private static void createPlot( string jsonString, string plotDefinitionsDir ) {
* https://scottplot.net/cookbook/5.0/configuring-legends/#legend-customization
*/
plt.Legend.IsVisible = true;
plt.Legend.Location = Alignment.LowerLeft;
plt.Legend.Alignment = Alignment.LowerLeft;

Log.Info( $"Writing to path: {outputPath}\n" +
$"YAxis: {plt.Axes.Left.Range}\n" +
Expand Down
8 changes: 4 additions & 4 deletions src/PlotGitHubAction/PlotGitHubAction.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>PlotGitHubAction</RootNamespace>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand All @@ -27,9 +27,9 @@
</Target>

<ItemGroup>
<PackageReference Include="ScottPlot" Version="5.0.21" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.7" />
<PackageReference Include="ScottPlot" Version="5.0.39"/>

<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.8"/>

<!--
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.4-preview.89" />
Expand Down
52 changes: 28 additions & 24 deletions src/PlotGitHubAction/TestResultAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public record UnitTestResult {
[ XmlAttribute( AttributeName = "computerName" ) ] public required string ComputerName { get; set; }
// computerName="fv-az471-492"

private System.TimeSpan _duration;
private TimeSpan _duration;

[ XmlIgnore ] public TimeSpan Duration {
get => _duration;
Expand Down Expand Up @@ -142,8 +142,8 @@ public TestResultAnalyzer( ActionConfig config ) {
_config = config;
_directoryRoot = config.TestResultsDir;
_outputDir = config.TestFailureOutputDir;
_csvFilePath = System.IO.Path.Combine( _config.MetaDataOutputDir, "test_results.csv" );
MarkdownSummaryFilePath = System.IO.Path.Combine( _config.OutputDir, "Test_Results.md" );
_csvFilePath = Path.Combine( _config.MetaDataOutputDir, "test_results.csv" );
MarkdownSummaryFilePath = Path.Combine( _config.OutputDir, "Test_Results.md" );
Log.Info(
$"==== {nameof(TestResultAnalyzer)} ====\n" +
$" DirectoryRoot: {_directoryRoot}\n" +
Expand All @@ -154,32 +154,32 @@ public void ScanForTrx( ) {
//
int trxFileCount = 0;
Log.Info( $" Scanning '{_directoryRoot}' and all subdirectories for trx files." );
foreach ( var filePath in System.IO.Directory.EnumerateFiles( _directoryRoot, "*.trx", System.IO.SearchOption.AllDirectories ) ) {
foreach ( var filePath in Directory.EnumerateFiles( _directoryRoot, "*.trx", SearchOption.AllDirectories ) ) {
trxFileCount++;
try {
Log.Info( $" trx: {filePath}" );
this.extractTrx( filePath );
} catch ( Exception e ) {
Log.Error( $"Exception will processing TRX file '{filePath}'\n\t{e}\n\t{e.StackTrace}" );
Log.Error( $"Exception when processing TRX file '{filePath}'\n\t{e}\n\t{e.StackTrace}" );
throw;
}
}
Log.Info( $" Found {trxFileCount} trx files in {_directoryRoot}" );

// CSV
string commitSha = _config.CommitHash;
if ( !System.IO.File.Exists( _csvFilePath ) ) {
System.IO.File.WriteAllText( _csvFilePath,
String.Join( ",", new string[] {
"Date",
"Commit SHA",
"Total Test Count",
"Failed Test Count",
"Failed Test Names"
} ) );
if ( !File.Exists( _csvFilePath ) ) {
File.WriteAllText( _csvFilePath,
String.Join( ",", new string[] {
"Date",
"Commit SHA",
"Total Test Count",
"Failed Test Count",
"Failed Test Names"
} ) );
}
System.IO.File.AppendAllText( _csvFilePath,
$"\n{ActionConfig.NOW_STRING},{commitSha},{_testResults.Count},{_failedTests.Count},{String.Join( ';', _failedTests.Select( f => f.ShortTestName ) )}" );
File.AppendAllText( _csvFilePath,
$"\n{ActionConfig.NOW_STRING},{commitSha},{_testResults.Count},{_failedTests.Count},{String.Join( ';', _failedTests.Select( f => f.ShortTestName ) )}" );
writeMarkdownSummary();
}

Expand Down Expand Up @@ -264,7 +264,7 @@ private void writeMarkdownSummary( ) {
```
""" );

System.IO.File.WriteAllText( MarkdownSummaryFilePath, Sb.ToString() );
File.WriteAllText( MarkdownSummaryFilePath, Sb.ToString() );
}

private string markdownInlineCodeSafe( string inputString ) {
Expand All @@ -278,9 +278,13 @@ private void extractTrx( string filePath ) {
XDocument xd = XDocument.Load( filePath );
XmlSerializer sx = new XmlSerializer( typeof(UnitTestResult) );

var results = xd.Elements().First().Elements()
.Single( static el => el.Name.LocalName == "Results" )
.Elements().ToArray();
var results = xd.Elements().FirstOrDefault()?.Elements()
.SingleOrDefault( static el => el.Name.LocalName == "Results" )?
.Elements().ToArray() ?? Array.Empty<XElement>();
if ( results.Length == 0 ) {
Log.Warn( $"Trx file '{filePath}' had no results." );
return;
}
string[] nonFailedResultOutcomes = { "Passed", "NotExecuted" /* = Skipped */ };
var failedResults = results.Where( el => !nonFailedResultOutcomes.Contains(
el.Attributes()
Expand Down Expand Up @@ -339,12 +343,12 @@ private void writeToFile( List<UnitTestResult> failures ) {
Log.Debug( str + "\n" );
string outFilePath = getTestResultOutputFilePath( failure );
Log.Debug( $"Writing to file: {outFilePath}" );
System.IO.File.WriteAllText( outFilePath, str );
File.WriteAllText( outFilePath, str );
}
}

private string getTestResultOutputFilePath( UnitTestResult failure ) {
return System.IO.Path.Combine( _outputDir, failure.ShortTestName + ".log" );
return Path.Combine( _outputDir, failure.ShortTestName + ".log" );
}

private string? getErrorSourceLink( UnitTestResult failure ) {
Expand Down Expand Up @@ -381,8 +385,8 @@ private string getTestResultOutputFilePath( UnitTestResult failure ) {
$"Split is {String.Join( ", ", unitTestPathFromTrx.Split( csProj.DirectoryPath ) )}\n\t" +
$"CsProject: {csProj}\n\t\twith DirectoryPath: {csProj.DirectoryPath}\n\t" +
$"relativePath: {relativePath}\n\t" +
$"Combined Path: {Path.Combine( csProj.DirectoryPath, relativePath.TrimStart( System.IO.Path.DirectorySeparatorChar ) )}" );
return Path.Combine( csProj.DirectoryPath, relativePath.TrimStart( System.IO.Path.DirectorySeparatorChar ) );
$"Combined Path: {Path.Combine( csProj.DirectoryPath, relativePath.TrimStart( Path.DirectorySeparatorChar ) )}" );
return Path.Combine( csProj.DirectoryPath, relativePath.TrimStart( Path.DirectorySeparatorChar ) );
}
Log.Warn( $"[{nameof(getUnitTestPath)}] Found csProj: {csProj}, but was unable to determine the relative path." );
}
Expand Down
14 changes: 7 additions & 7 deletions test/PlotGitHubAction.Tests/PlotGitHubAction.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>

Expand All @@ -10,18 +10,18 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="FluentAssertions.Analyzers" Version="0.30.0">
<PackageReference Include="FluentAssertions" Version="6.12.1"/>
<PackageReference Include="FluentAssertions.Analyzers" Version="0.33.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.6" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1"/>
<PackageReference Include="xunit" Version="2.9.2"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PackageReference Include="coverlet.collector" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down

0 comments on commit a2d96cd

Please sign in to comment.