Skip to content

Commit

Permalink
Add recent build log chart. Set this to display on main page
Browse files Browse the repository at this point in the history
- Add recent build log chart (last 30 days).
- Set recent build log chart to display on main markdown README.md
- Update workflow actions
- Set workflows to run on push
- Set workflows to not run concurrently + cancel in progress
- minor formatting changes
  • Loading branch information
erichiller committed Feb 8, 2024
1 parent 67cc28b commit b91628e
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 34 deletions.
18 changes: 12 additions & 6 deletions .github/workflows/build_and_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,29 @@
name: 'Build & Test'

on:
#push:
# branches: [ "master" ]
push:
branches: [ "master" ]
workflow_dispatch:

env:
TZ: America/Chicago

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# Cancel in-progress runs.
concurrency:
group: "docker"
cancel-in-progress: true

jobs:
test:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 7.0.x
#
Expand Down Expand Up @@ -59,7 +65,7 @@ jobs:
-fl1 "/flp1:logFile=gh-action-plot-build.log;warningsonly" \
-p:"WarnLevel=5"
#
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
repository: 'erichiller/mkmrk.Channels'
path: 'test-src/mkmrk-channels'
Expand Down Expand Up @@ -125,7 +131,7 @@ jobs:
Get-ChildItem -Recurse -Path ./ | Select-Object -Property Name,CreationTime,Size
- name: Upload results
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: plot-results
retention-days: 1
Expand Down
13 changes: 10 additions & 3 deletions .github/workflows/docker-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@
name: 'Build Docker image'

on:
push:
branches: [ "master" ]
workflow_dispatch:

env:
TZ: America/Chicago

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# Cancel in-progress runs.
concurrency:
group: "docker"
cancel-in-progress: true

jobs:
docker_build:
runs-on: ubuntu-latest
Expand All @@ -15,9 +23,9 @@ jobs:
packages: write

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 7.0.x
- name: Restore dependencies
Expand All @@ -30,7 +38,6 @@ jobs:
--configuration Release \
-r linux-x64 \
-o built
#
#
- name: docker login
Expand Down
20 changes: 17 additions & 3 deletions src/PlotGitHubAction/BuildLogAnalyzer.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace PlotGitHubAction;

Expand Down Expand Up @@ -37,6 +37,7 @@ public class BuildLogAnalyzer {
public readonly string MarkdownPath;
private const string _build_warnings_per_project_chart_file_name = "build_warnings";
public const string BUILD_WARNINGS_TOTAL_CHART_FILE_NAME = "build_warnings_total";
public const string BUILD_WARNINGS_TOTAL_RECENT_CHART_FILE_NAME = "build_warnings_total_recent";
private string _filePattern => _config.BuildLogFilePattern;

private readonly Dictionary<CsProjInfo, HashSet<WarnLogEntry>> _projWarningsHs = new ();
Expand Down Expand Up @@ -66,6 +67,8 @@ public void Analyze( ) {
// Charts
summary.AppendLine();
summary.AppendLine();
summary.AppendLine( _config.GetMarkdownChartLink( BUILD_WARNINGS_TOTAL_RECENT_CHART_FILE_NAME ) );
summary.AppendLine();
summary.AppendLine( _config.GetMarkdownChartLink( BUILD_WARNINGS_TOTAL_CHART_FILE_NAME ) );
summary.AppendLine();
summary.AppendLine( _config.GetMarkdownChartLink( _build_warnings_per_project_chart_file_name ) );
Expand Down Expand Up @@ -231,6 +234,17 @@ public XYPlotConfig<DateTime>[] GetPlottable( ) => new[] {
XAxisType: AxisType.DateTime,
YAxisType: AxisType.Numeric,
Data: Array.Empty<XYData<DateTime>>()
), PlotDataSelection.Total )
), PlotDataSelection.Total ),
_historyPlotter.AddDataToPlottable(
new XYPlotConfig<DateTime>(
Title: "Build Warnings Total - Recent",
OutputFileName: BUILD_WARNINGS_TOTAL_RECENT_CHART_FILE_NAME,
PlotType: PlotType.Scatter,
Width: 1024,
Height: 800,
XAxisType: AxisType.DateTime,
YAxisType: AxisType.Numeric,
Data: Array.Empty<XYData<DateTime>>()
), PlotDataSelection.Total | PlotDataSelection.Recent )
};
}
11 changes: 8 additions & 3 deletions src/PlotGitHubAction/ProjectDataHistoryPlotter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;

using ScottPlot;
Expand Down Expand Up @@ -94,6 +94,10 @@ public XYPlotConfig<DateTime> AddDataToPlottable( XYPlotConfig<DateTime> plottab
( date: DateTime.Parse( h.Key ),
total: h.Value.Sum( p => p.Value )
) ).ToArray();
if ( plotDataSelection.HasFlag( PlotDataSelection.Recent ) ) {
var recentCutoff = DateTime.Now - TimeSpan.FromDays( 30 );
totalSeries = totalSeries.Where( x => x.date > recentCutoff ).ToArray();
}
data.Add(
new XYData<DateTime>(
Title: "Total",
Expand All @@ -107,6 +111,7 @@ public XYPlotConfig<DateTime> AddDataToPlottable( XYPlotConfig<DateTime> plottab

[ Flags ]
public enum PlotDataSelection {
Projects = 0b01,
Total = 0b10
Projects = 0b001,
Total = 0b010,
Recent = 0b100,
}
2 changes: 1 addition & 1 deletion src/PlotGitHubAction/RepoAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static void Run( ActionConfig config ) {
config.PlotOutputDir );
links.AppendLine( $"- [Build Warnings]({relPath( buildLogAnalyzer.MarkdownPath )})" );
readme.AppendLine( "\n## Build Warnings\n\n" );
readme.AppendLine( config.GetMarkdownChartLink( BuildLogAnalyzer.BUILD_WARNINGS_TOTAL_CHART_FILE_NAME ) );
readme.AppendLine( config.GetMarkdownChartLink( BuildLogAnalyzer.BUILD_WARNINGS_TOTAL_RECENT_CHART_FILE_NAME ) );
}

links.Insert( 0, "# README\n\n" );
Expand Down
38 changes: 20 additions & 18 deletions src/PlotGitHubAction/TestResultAnalyzer.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Xml.Linq;
using System.Xml.Serialization;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Serialization;

namespace PlotGitHubAction;

Expand Down Expand Up @@ -191,10 +191,10 @@ public void ScanForTrx( ) {
$"\n{ActionConfig.NOW_STRING},{commitSha},{_testResults.Count},{_failedTests.Count},{String.Join( ';', _failedTests.Select( f => f.ShortTestName ) )}" );
writeMarkdownSummary();
}
private int TestSuccessCount => _testResults.Count( t => t.Outcome == "Passed" );
private int TestFailCount => _failedTests.Count;
private int TestSkipCount => _testResults.Count( t => t.Outcome == "NotExecuted" );

private int _testSuccessCount => _testResults.Count( t => t.Outcome == "Passed" );
private int _testFailCount => _failedTests.Count;
private int _testSkipCount => _testResults.Count( t => t.Outcome == "NotExecuted" );

private void writeMarkdownSummary( ) {
UrlMdShortUtils sourceUrls = new (config: _config, generateIds: true);
Expand All @@ -208,10 +208,10 @@ private void writeMarkdownSummary( ) {
const string colDiv = " | ";
const int firstColumnWidth = 50;
if ( _failedTests.Count > 0 ) {
Utils.SetGitHubActionsOutput( GitHubActionOutputIds.TEST_RESULTS,
Utils.SetGitHubActionsOutput( GitHubActionOutputIds.TEST_RESULTS,
$$"""
{ "success": false }
""");
{ "success": false }
""" );
Sb.AppendLine(
"Test & Exception Location".PadRight( firstColumnWidth )
+ colDiv
Expand Down Expand Up @@ -257,19 +257,21 @@ private void writeMarkdownSummary( ) {
sourceUrls.AddReferencedUrls( Sb );
Sb.AppendLine();
} else {
Utils.SetGitHubActionsOutput( GitHubActionOutputIds.TEST_RESULTS,
Utils.SetGitHubActionsOutput( GitHubActionOutputIds.TEST_RESULTS,
$$"""
{ "success": true }
""");
""" );
}
// Write Test Summary as an output
Utils.SetGitHubActionsOutput( GitHubActionOutputIds.TEST_SUMMARY,
Utils.SetGitHubActionsOutput( GitHubActionOutputIds.TEST_SUMMARY,
$$"""
✅ Success : {{this.TestSuccessCount:N0}}
💤 Skip : {{this.TestSkipCount:N0}}
❌ Failed : {{this.TestFailCount:N0}}
```
✅ Success : {{this._testSuccessCount:N0}}
💤 Skip : {{this._testSkipCount:N0}}
❌ Failed : {{this._testFailCount:N0}}
#️⃣ Total : {{_testResults.Count:N0}}
""");
```
""" );

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

0 comments on commit b91628e

Please sign in to comment.