Skip to content

Commit

Permalink
switch to using microsoft.codecoverage (#1413)
Browse files Browse the repository at this point in the history
* switch to using microsoft.codecoverage

* removed legacy coverage interfaces as they aren't really needed, remove if used directly

* more coverage changes

* more coverage changes

* more coverage changes

* more coverage changes

* Automatically linting code

* somedays case sensitivity is evil

* Automatically linting code

* more coverage changes

---------

Co-authored-by: Rocket Understudy <33589210+rsg-bot@users.noreply.github.com>
  • Loading branch information
david-driscoll and rsg-bot authored Nov 17, 2024
1 parent 85c496c commit 51d6f21
Show file tree
Hide file tree
Showing 19 changed files with 275 additions and 181 deletions.
3 changes: 1 addition & 2 deletions .build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
[LocalBuildConventions]
#pragma warning disable CA1050
internal partial class Pipeline : NukeBuild,
#pragma warning restore CA1050
#pragma warning restore CA1050
ICanRestoreWithDotNetCore,
ICanBuildWithDotNetCore,
ICanTestWithDotNetCore,
ICanPackWithDotNetCore,
IHaveDataCollector,
ICanClean,
IHaveCommonLintTargets,
IHavePublicApis,
Expand Down
5 changes: 0 additions & 5 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@
"commands": ["husky"],
"rollForward": false
},
"liquidtestreports.cli": {
"version": "2.0.0-beta.2",
"commands": ["liquid"],
"rollForward": false
},
"verify.tool": {
"version": "0.6.0",
"commands": ["dotnet-verify"],
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,20 @@ permissions:

jobs:
build:
permissions:
actions: read
checks: write
contents: read
deployments: read
id-token: none
issues: write
discussions: none
packages: none
pages: none
pull-requests: write
repository-projects: none
security-events: none
statuses: write
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down Expand Up @@ -140,6 +154,13 @@ jobs:
with:
name: 'coverage'
path: 'coverage/'
- name: Coverage Comment
if: github.event_name == 'pull_request'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: 'Coverage'
path: 'coverage/summary/SummaryGithub.md'
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
- name: 📫 Publish Coverage
if: (github.event_name != 'pull_request' && github.event_name != 'pull_request_target') || ((github.event_name == 'pull_request' || github.event_name == 'pull_request_target') && github.event.pull_request.user.login != 'renovate[bot]' && github.event.pull_request.user.login != 'dependabot[bot]')
uses: codecov/codecov-action@v5
Expand All @@ -158,6 +179,11 @@ jobs:
with:
name: 'test data'
path: 'artifacts/test/'
- name: 📫 Publish Test Results
if: always()
uses: EnricoMi/publish-unit-test-result-action@v2
with:
files: 'artifacts/test/**/*.trx'
- name: 🏺 Publish NuGet Packages
if: always()
uses: actions/upload-artifact@v4
Expand Down
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<PackageVersion Include="System.Interactive" Version="6.0.1" />
<PackageVersion Include="System.Interactive.Async" Version="6.0.1" />
<PackageVersion Include="Bogus" Version="35.6.1" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="Microsoft.CodeCoverage" Version="17.11.1" />
<PackageVersion Include="FakeItEasy" Version="8.3.0" />
<PackageVersion Include="FluentAssertions" Version="6.12.2" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
using Nuke.Common.CI.GitHubActions;
using Nuke.Common.Execution;
using Nuke.Common.IO;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.DotNet;
using Serilog;

namespace Rocket.Surgery.Nuke.ContinuousIntegration;

Expand All @@ -24,59 +21,20 @@ public partial class ContinuousIntegrationConventionsAttribute : BuildExtensionA

private void EmitTestSummaryMarkdown(INukeBuild build, AbsolutePath summary)
{
var toolInstalled = DotNetTool.IsInstalled("liquidtestreports.cli");
// ReSharper disable once SuspiciousTypeConversion.Global
if (toolInstalled
&& build.ExecutionPlan.Any(z => z.Name == nameof(IHaveTestTarget.Test))
&& build is IHaveTestArtifacts { TestResultsDirectory: { } testResultsDirectory, }
&& testResultsDirectory.GlobFiles("**/*.trx") is { Count: > 0, } results)
{
var pathArgs =
results
.Select(
path => testResultsDirectory.GetRelativePathTo(
path.RenameWithoutExtension(static path => path.Name.Replace("[", "").Replace("]", ""))
)
)
.Aggregate(new Arguments(), (arguments, path) => arguments.Add("--inputs {value}", $"File={path}"));


// summary.TouchFile();
// var reporter = new LiquidReporter(results.Select(z => z.ToString()), Log.Logger);
// var report = reporter.Run("Test results");
// summary.WriteAllText(summary.ReadAllText().TrimStart() + "\n" + report);
var liquidResult = DotNetTasks.DotNet(
new Arguments()
.Add("liquid")
.Concatenate(pathArgs)
.Add("--output-file {0}", summary)
.RenderForExecution(),
testResultsDirectory,
logOutput: false,
logInvocation: build.Verbosity == Verbosity.Verbose,
exitHandler: process => process.AssertWaitForExit()
);
_ = ( testResultsDirectory / "liquidtestreports.log" ).WriteAllText(liquidResult.StdToText());
}
else if (!toolInstalled)
{
Log.Warning("liquidtestreports.cli is not installed, skipping test summary generation");
}

// ReSharper disable once SuspiciousTypeConversion.Global
if (build.ExecutionPlan.Any(z => z.Name == nameof(IGenerateCodeCoverageSummary.GenerateCodeCoverageSummary))
&& build is IGenerateCodeCoverageSummary codeCoverage
&& ( codeCoverage.CoverageSummaryDirectory / "Summary.md" ).FileExists())
{
_ = summary.TouchFile();
var coverageSummary = ( codeCoverage.CoverageSummaryDirectory / "Summary.md" ).ReadAllText();
if (coverageSummary.IndexOf("|**Name**", StringComparison.Ordinal) is > -1 and var index)
{
coverageSummary = coverageSummary[..( index - 1 )];
}

_ = summary.WriteAllText(coverageSummary + summary.ReadAllText().TrimStart());
}
// // ReSharper disable once SuspiciousTypeConversion.Global
// if (build.ExecutionPlan.Any(z => z.Name == nameof(IGenerateCodeCoverageSummary.GenerateCodeCoverageSummary))
// && build is IGenerateCodeCoverageSummary codeCoverage
// && ( codeCoverage.CoverageSummaryDirectory / "Summary.md" ).FileExists())
// {
// _ = summary.TouchFile();
// var coverageSummary = ( codeCoverage.CoverageSummaryDirectory / "Summary.md" ).ReadAllText();
// if (coverageSummary.IndexOf("|**Name**", StringComparison.Ordinal) is > -1 and var index)
// {
// coverageSummary = coverageSummary[..( index - 1 )];
// }
//
// _ = summary.WriteAllText(coverageSummary + summary.ReadAllText().TrimStart());
// }
}

/// <inheritdoc />
Expand All @@ -102,4 +60,4 @@ public void OnBuildFinished()
}
}
}
}
}
18 changes: 3 additions & 15 deletions src/Nuke/DotNetCore/ICanTestWithDotNetCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ namespace Rocket.Surgery.Nuke.DotNetCore;
/// Defines a `dotnet test` test run with code coverage via coverlet
/// </summary>
[PublicAPI]
public interface ICanTestWithDotNetCore : IHaveCollectCoverage,
IHaveBuildTarget,
public interface ICanTestWithDotNetCore : IHaveBuildTarget,
ITriggerCodeCoverageReports,
IComprehendTests,
IHaveTestArtifacts,
Expand Down Expand Up @@ -57,19 +56,8 @@ public interface ICanTestWithDotNetCore : IHaveCollectCoverage,
.EnableNoBuild()
.SetLoggers("trx")
.SetResultsDirectory(TestResultsDirectory)
.When(
!CollectCoverage,
x => x
.SetProperty((string)"CollectCoverage", "true")
.SetProperty("CoverageDirectory", CoverageDirectory)
)
.When(
CollectCoverage,
x => x
.SetProperty("CollectCoverage", "false")
.SetDataCollector("XPlat Code Coverage")
.SetSettingsFile(RunSettings)
)
.SetSettingsFile(RunSettings)
.SetDataCollector(DataCollector)
)
)
.CollectCoverage(TestResultsDirectory, CoverageDirectory);
Expand Down
18 changes: 3 additions & 15 deletions src/Nuke/DotNetCore/ICanTestWithDotNetCoreBuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ namespace Rocket.Surgery.Nuke.DotNetCore;
/// Defines a `dotnet test` test run with code coverage via coverlet
/// </summary>
[PublicAPI]
public interface ICanTestWithDotNetCoreBuild : IHaveCollectCoverage,
IHaveBuildTarget,
public interface ICanTestWithDotNetCoreBuild : IHaveBuildTarget,
ITriggerCodeCoverageReports,
IComprehendTests,
IHaveTestArtifacts,
Expand Down Expand Up @@ -59,19 +58,8 @@ public interface ICanTestWithDotNetCoreBuild : IHaveCollectCoverage,
.SetConfiguration(TestBuildConfiguration)
.EnableNoBuild()
.SetResultsDirectory(TestResultsDirectory)
.When(
!CollectCoverage,
x => x
.SetProperty((string)"CollectCoverage", "true")
.SetProperty("CoverageDirectory", CoverageDirectory)
)
.When(
CollectCoverage,
x => x
.SetProperty("CollectCoverage", "false")
.SetDataCollector("XPlat Code Coverage")
.SetSettingsFile(RunSettings)
)
.SetSettingsFile(RunSettings)
.SetDataCollector(DataCollector)
)
)
.CollectCoverage(TestResultsDirectory, CoverageDirectory);
Expand Down
13 changes: 0 additions & 13 deletions src/Nuke/DotNetCore/IHaveCollectCoverage.cs

This file was deleted.

10 changes: 0 additions & 10 deletions src/Nuke/DotNetCore/IHaveDataCollector.cs

This file was deleted.

10 changes: 0 additions & 10 deletions src/Nuke/DotNetCore/IHaveMsBuildCoverage.cs

This file was deleted.

Loading

0 comments on commit 51d6f21

Please sign in to comment.