Skip to content

Commit

Permalink
Merge pull request #1815 from eNeRGy164/code-coverage
Browse files Browse the repository at this point in the history
Add code coverage reporting
  • Loading branch information
dennisdoomen committed Feb 18, 2022
2 parents 795dcb1 + 47ba546 commit 78322ca
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 18 deletions.
30 changes: 15 additions & 15 deletions .github/workflows/build.yml
Expand Up @@ -13,36 +13,36 @@ jobs:

runs-on: windows-latest

env:
DOTNET_NOLOGO: true

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup .NET 5
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x

- name: Setup .NET 3.1
- name: Setup .NET SDKs
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.x

- name: Setup .NET 2.1
uses: actions/setup-dotnet@v1
with:
dotnet-version: 2.1.x
dotnet-version: |
2.1.x
3.1.x
5.0.x
- name: Run NUKE
run: ./build.ps1
env:
BranchSpec: ${{ github.ref }}
BuildNumber: ${{ github.run_number}}
BuildNumber: ${{ github.run_number }}
ApiKey: ${{ secrets.NUGETAPIKEY }}

- name: coveralls
uses: coverallsapp/github-action@1.1.3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: TestResults/reports/lcov.info

- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
path: ./Artifacts/*


23 changes: 20 additions & 3 deletions Build/Build.cs
Expand Up @@ -8,10 +8,12 @@
using Nuke.Common.Tooling;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.GitVersion;
using Nuke.Common.Tools.ReportGenerator;
using Nuke.Common.Tools.Xunit;
using static Nuke.Common.IO.FileSystemTasks;
using static Nuke.Common.IO.PathConstruction;
using static Nuke.Common.Tools.DotNet.DotNetTasks;
using static Nuke.Common.Tools.ReportGenerator.ReportGeneratorTasks;
using static Nuke.Common.Tools.Xunit.XunitTasks;

[CheckBuildProjectConfigurations]
Expand Down Expand Up @@ -66,7 +68,7 @@ class Build : NukeBuild
"Branch spec {branchspec} is a pull request. Adding build number {buildnumber}",
BranchSpec, BuildNumber);
SemVer = string.Join('.', GitVersion.SemVer.Split('.').Take(3).Union(new [] { BuildNumber }));
SemVer = string.Join('.', GitVersion.SemVer.Split('.').Take(3).Union(new[] { BuildNumber }));
}
Serilog.Log.Information("SemVer = {semver}", SemVer);
Expand All @@ -91,6 +93,7 @@ class Build : NukeBuild
DotNetBuild(s => s
.SetProjectFile(Solution)
.SetConfiguration("CI")
.EnableNoLogo()
.EnableNoRestore()
.SetAssemblyVersion(GitVersion.AssemblySemVer)
.SetFileVersion(GitVersion.AssemblySemFileVer)
Expand Down Expand Up @@ -132,9 +135,22 @@ class Build : NukeBuild
.SetProjectFile(Solution.Specs.FluentAssertions_Specs)
.SetConfiguration("Debug")
.EnableNoBuild()
.SetDataCollector("XPlat Code Coverage")
.SetResultsDirectory(RootDirectory / "TestResults")
.CombineWith(
Solution.Specs.FluentAssertions_Specs.GetTargetFrameworks().Except(new[] { "net47" }),
(_, v) => _.SetFramework(v)));
ReportGenerator(s => s
.SetProcessToolPath(ToolPathResolver.GetPackageExecutable("ReportGenerator", "ReportGenerator.dll", framework: "net5.0"))
.SetTargetDirectory(RootDirectory / "TestResults" / "reports")
.AddReports(RootDirectory / "TestResults/**/coverage.cobertura.xml")
.AddReportTypes("HtmlInline_AzurePipelines_Dark", "lcov")
.SetAssemblyFilters("+FluentAssertions"));
string link = RootDirectory / "TestResults" / "reports" / "index.html";
Serilog.Log.Information($"Code coverage report: \x1b]8;;file://{link.Replace('\\', '/')}\x1b\\{link}\x1b]8;;\x1b\\");
});

Target TestFrameworks => _ => _
Expand Down Expand Up @@ -178,6 +194,8 @@ class Build : NukeBuild
.SetProject(Solution.Core.FluentAssertions)
.SetOutputDirectory(ArtifactsDirectory)
.SetConfiguration("Release")
.EnableNoLogo()
.EnableNoRestore()
.EnableContinuousIntegrationBuild() // Necessary for deterministic builds
.SetVersion(SemVer));
});
Expand All @@ -187,7 +205,7 @@ class Build : NukeBuild
.OnlyWhenDynamic(() => IsTag)
.Executes(() =>
{
var packages = GlobFiles(ArtifactsDirectory, "*.nupkg");
IReadOnlyCollection<string> packages = GlobFiles(ArtifactsDirectory, "*.nupkg");
Assert.NotEmpty(packages.ToList());
Expand All @@ -201,5 +219,4 @@ class Build : NukeBuild
});

bool IsTag => BranchSpec != null && BranchSpec.Contains("refs/tags", StringComparison.InvariantCultureIgnoreCase);

}
1 change: 1 addition & 0 deletions Build/_build.csproj
Expand Up @@ -10,6 +10,7 @@
<ItemGroup>
<PackageDownload Include="GitVersion.Tool" Version="[5.8.1]" />
<PackageDownload Include="NSpec" Version="[3.1.0]" />
<PackageDownload Include="ReportGenerator" Version="[5.0.4]" />
<PackageDownload Include="xunit.runner.console" Version="[2.4.1]" />
<PackageReference Include="Nuke.Common" Version="6.0.1" />
</ItemGroup>
Expand Down
Expand Up @@ -56,6 +56,9 @@
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="Xunit.StaFact" Version="1.1.5-alpha" />
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
<PackageReference Include="coverlet.collector" Version="3.1.1" PrivateAssets="all">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
Expand Down
3 changes: 3 additions & 0 deletions Tests/FluentAssertions.Specs/FluentAssertions.Specs.csproj
Expand Up @@ -60,6 +60,9 @@
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="Xunit.StaFact" Version="1.1.5-alpha" />
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
<PackageReference Include="coverlet.collector" Version="3.1.1" PrivateAssets="all">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
Expand Down

0 comments on commit 78322ca

Please sign in to comment.