Skip to content

Commit 4788877

Browse files
authored
ci: add test results and coverage reporting to PR comments (#153)
## Summary - Add `dotnet-test-reporter` to CI workflow to post test results and code coverage as a PR comment - Collect XPlat Code Coverage (Cobertura) and TRX test results from both test projects - Gate the report to the Ubuntu matrix leg to avoid duplicate comments ## Test plan - [x] Verify PR comment appears with test results and coverage after CI runs - [x] Confirm coverage threshold of 70% is enforced
1 parent b0a25c8 commit 4788877

26 files changed

+1705
-8
lines changed

.github/workflows/ci.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: CI Builds
22
permissions:
33
contents: read
4+
pull-requests: write
45

56
on:
67
pull_request:
@@ -36,7 +37,26 @@ jobs:
3637
run: dotnet build --no-restore
3738

3839
- name: Test
39-
run: dotnet test --no-build
40+
run: dotnet test --no-build --verbosity normal --logger trx --collect:"XPlat Code Coverage"
41+
42+
- name: Merge coverage reports
43+
if: ${{ always() && matrix.os == 'ubuntu-latest' }}
44+
uses: danielpalme/ReportGenerator-GitHub-Action@5
45+
with:
46+
reports: tests/**/coverage.cobertura.xml
47+
targetdir: coverage
48+
reporttypes: Cobertura
49+
50+
- name: Generate test report
51+
uses: bibipkins/dotnet-test-reporter@v1.6.1
52+
if: ${{ always() && matrix.os == 'ubuntu-latest' }}
53+
with:
54+
github-token: ${{ secrets.GITHUB_TOKEN }}
55+
comment-title: "Test Results"
56+
results-path: tests/**/*.trx
57+
coverage-path: coverage/Cobertura.xml
58+
coverage-type: cobertura
59+
coverage-threshold: 70
4060

4161
- name: Publish
4262
run: dotnet publish src/SharpFM/SharpFM.csproj --runtime "${{ matrix.target }}" -c Debug

src/SharpFM.Plugin.XmlViewer/XmlViewerPanel.axaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
using System.Diagnostics.CodeAnalysis;
12
using Avalonia.Controls;
23
using AvaloniaEdit;
34
using AvaloniaEdit.TextMate;
45
using TextMateSharp.Grammars;
56

67
namespace SharpFM.Plugin.XmlViewer;
78

9+
[ExcludeFromCodeCoverage]
810
public partial class XmlViewerPanel : UserControl
911
{
1012
private TextMate.Installation? _textMateInstallation;

src/SharpFM/App.axaml.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
using System;
2+
using System.Diagnostics.CodeAnalysis;
13
using Avalonia;
24
using Avalonia.Controls.ApplicationLifetimes;
35
using Avalonia.Markup.Xaml;
46
using SharpFM.ViewModels;
57
using Microsoft.Extensions.Logging;
68
using NLog.Extensions.Logging;
79
using Microsoft.Extensions.DependencyInjection;
8-
using System;
910
using SharpFM.Services;
1011

1112
namespace SharpFM;
1213

14+
[ExcludeFromCodeCoverage]
1315
public partial class App : Application
1416
{
1517
ILogger logger = LoggerFactory.Create(builder => builder.AddNLog()).CreateLogger<MainWindow>();

src/SharpFM/AvaloniaNLogSink.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Diagnostics.CodeAnalysis;
23
using Avalonia;
34
using Avalonia.Logging;
45
using NLog;
@@ -8,6 +9,7 @@ namespace SharpFM;
89
/// <summary>
910
/// Avalonia Log Sink that writes to NLog Loggers.
1011
/// </summary>
12+
[ExcludeFromCodeCoverage]
1113
public class AvaloniaNLogSink : ILogSink
1214
{
1315
/// <summary>
@@ -43,6 +45,7 @@ private static LogLevel LogLevelToNLogLevel(LogEventLevel level)
4345
}
4446
}
4547

48+
[ExcludeFromCodeCoverage]
4649
public static class NLogSinkExtensions
4750
{
4851
/// <summary>

src/SharpFM/MainWindow.axaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.ComponentModel;
3+
using System.Diagnostics.CodeAnalysis;
34
using Avalonia;
45
using Avalonia.Controls;
56
using Avalonia.Input;
@@ -14,6 +15,7 @@
1415

1516
namespace SharpFM;
1617

18+
[ExcludeFromCodeCoverage]
1719
public partial class MainWindow : Window
1820
{
1921
private readonly RegistryOptions _registryOptions;

src/SharpFM/Models/ClipRepository.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics.CodeAnalysis;
34
using System.IO;
45
using NLog;
56

@@ -8,6 +9,7 @@ namespace SharpFM.Models;
89
/// <summary>
910
/// Clip File Repository.
1011
/// </summary>
12+
[ExcludeFromCodeCoverage]
1113
public class ClipRepository
1214
{
1315
private static readonly Logger Log = LogManager.GetCurrentClassLogger();

src/SharpFM/PluginManager/PluginManagerWindow.axaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics.CodeAnalysis;
34
using System.Linq;
45
using Avalonia.Controls;
56
using Avalonia.Platform.Storage;
@@ -9,6 +10,7 @@
910

1011
namespace SharpFM.PluginManager;
1112

13+
[ExcludeFromCodeCoverage]
1214
public partial class PluginManagerWindow : Window
1315
{
1416
private readonly PluginManagerViewModel _viewModel = new();

src/SharpFM/Program.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
using Avalonia;
1+
using System;
2+
using System.Diagnostics.CodeAnalysis;
3+
using Avalonia;
24
using NLog;
3-
using System;
45

56
namespace SharpFM;
67

8+
[ExcludeFromCodeCoverage]
79
class Program
810
{
911
// Initialization code. Don't use any Avalonia, third-party APIs or any

src/SharpFM/Schema/Editor/CalculationEditorWindow.axaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Diagnostics.CodeAnalysis;
12
using Avalonia.Controls;
23
using Avalonia.Interactivity;
34
using AvaloniaEdit;
@@ -8,6 +9,7 @@
89

910
namespace SharpFM.Schema.Editor;
1011

12+
[ExcludeFromCodeCoverage]
1113
public partial class CalculationEditorWindow : Window
1214
{
1315
private readonly FmField _field;

src/SharpFM/Schema/Editor/TableEditorControl.axaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using System;
2+
using System.Diagnostics.CodeAnalysis;
23
using Avalonia.Controls;
34
using Avalonia.Input;
45
using SharpFM.Schema.Model;
56

67
namespace SharpFM.Schema.Editor;
78

9+
[ExcludeFromCodeCoverage]
810
public partial class TableEditorControl : UserControl
911
{
1012
public static FieldDataType[] DataTypes { get; } = Enum.GetValues<FieldDataType>();

0 commit comments

Comments
 (0)