Skip to content

Commit b42811a

Browse files
CopilotScarletKuro
andcommitted
Add test and codecov support to nuke build and CI workflow
Co-authored-by: ScarletKuro <19953225+ScarletKuro@users.noreply.github.com>
1 parent b49c4f5 commit b42811a

3 files changed

Lines changed: 28 additions & 5 deletions

File tree

.github/workflows/continuous.yml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
name: ubuntu-latest
2424
runs-on: ubuntu-latest
2525
steps:
26-
- uses: actions/checkout@v4
26+
- uses: actions/checkout@v6
2727
with:
2828
fetch-depth: 0
2929
- name: 'Cache: .nuke/temp, ~/.nuget/packages'
@@ -33,10 +33,21 @@ jobs:
3333
.nuke/temp
3434
~/.nuget/packages
3535
key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj', '**/Directory.Packages.props') }}
36-
- name: 'Run: Compile, Pack'
37-
run: ./build.cmd Compile Pack
36+
- name: 'Run: Compile, Test, Pack'
37+
run: ./build.cmd Compile Test Pack
38+
- name: 'Upload coverage to Codecov'
39+
uses: codecov/codecov-action@v5
40+
with:
41+
token: ${{ secrets.CODECOV_TOKEN }}
42+
files: artifacts/coverage/*.xml
43+
fail_ci_if_error: false
44+
- name: 'Publish: coverage'
45+
uses: actions/upload-artifact@v5
46+
with:
47+
name: coverage
48+
path: artifacts/coverage
3849
- name: 'Publish: packages'
39-
uses: actions/upload-artifact@v4
50+
uses: actions/upload-artifact@v5
4051
with:
4152
name: packages
4253
path: artifacts/packages

build/Build.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Nuke.Common.IO;
99
using Nuke.Common.ProjectModel;
1010
using Nuke.Common.Tooling;
11+
using Nuke.Common.Tools.Coverlet;
1112
using Nuke.Common.Tools.DotNet;
1213
using Nuke.Common.Tools.GitHub;
1314
using Nuke.Common.Utilities.Collections;
@@ -22,7 +23,7 @@
2223
FetchDepth = 0,
2324
On = [GitHubActionsTrigger.Push],
2425
PublishArtifacts = true,
25-
InvokedTargets = [nameof(Compile), nameof(Pack)])]
26+
InvokedTargets = [nameof(Compile), nameof(Test), nameof(Pack)])]
2627
[GitHubActions(
2728
"release",
2829
GitHubActionsImage.UbuntuLatest,
@@ -59,6 +60,7 @@ class Build : NukeBuild
5960
AbsolutePath TestsDirectory => RootDirectory / "tests";
6061
AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts";
6162
AbsolutePath PackagesDirectory => ArtifactsDirectory / "packages";
63+
AbsolutePath CoverageDirectory => ArtifactsDirectory / "coverage";
6264

6365
Target Clean => _ => _
6466
.Before(Restore)
@@ -104,16 +106,22 @@ class Build : NukeBuild
104106

105107
Target Test => _ => _
106108
.DependsOn(Compile)
109+
.Produces(CoverageDirectory / "*.xml")
107110
.Executes(() =>
108111
{
109112
var projects = Solution.GetAllProjects("*.Tests");
110113

114+
CoverageDirectory.CreateOrCleanDirectory();
115+
111116
foreach (var project in projects)
112117
{
113118
DotNetTest(_ => _
114119
.SetProjectFile(project.Path)
115120
.SetConfiguration(Configuration)
116121
.EnableNoBuild()
122+
.EnableCollectCoverage()
123+
.SetCoverletOutputFormat(CoverletOutputFormat.cobertura)
124+
.SetCoverletOutput(CoverageDirectory / $"{project.Name}.xml")
117125
);
118126
}
119127
});

src/Scarlet.System.Text.Json.DateTimeConverter.Tests/Scarlet.System.Text.Json.DateTimeConverter.Tests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
<PrivateAssets>all</PrivateAssets>
1515
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1616
</PackageReference>
17+
<PackageReference Include="coverlet.msbuild" Version="6.0.4">
18+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
19+
<PrivateAssets>all</PrivateAssets>
20+
</PackageReference>
1721
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
1822
<PackageReference Include="xunit" Version="2.9.3" />
1923
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">

0 commit comments

Comments
 (0)