Skip to content

Commit ebee197

Browse files
committed
ci(unit-tests): Align build target, structure results, and upload coverage
1 parent ec270af commit ebee197

2 files changed

Lines changed: 21 additions & 26 deletions

File tree

.github/workflows/_unit_tests.yml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ env:
1111
jobs:
1212
unit_test:
1313
name: ${{ matrix.os }} - net${{ matrix.dotnet_version }}
14-
env:
15-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
14+
permissions:
15+
id-token: write
1616
strategy:
1717
fail-fast: false
1818
matrix:
@@ -30,18 +30,27 @@ jobs:
3030
name: Restore State
3131
uses: ./.github/actions/cache-restore
3232

33-
- name: '[Unit Test]'
33+
-
34+
name: '[Unit Test]'
3435
uses: nick-fields/retry@v3
3536
with:
3637
shell: pwsh
3738
timeout_minutes: 30
3839
max_attempts: 3
3940
retry_on: error
40-
command: 'dotnet run/build.dll --target=Test --dotnet_version=${{ matrix.dotnet_version }}'
41+
command: 'dotnet run/build.dll --target=UnitTest --dotnet_version=${{ matrix.dotnet_version }}'
4142

4243
-
4344
name: Test Summary
4445
uses: test-summary/action@v2.4
4546
if: always() && matrix.dotnet_version == '10.0'
4647
with:
47-
paths: artifacts/test-results/*.results.xml
48+
paths: artifacts/test-results/**/results.xml
49+
50+
-
51+
name: Upload Coverage
52+
uses: codecov/codecov-action@v5
53+
if: success() && github.event_name != 'pull_request' && github.repository_owner == 'GitTools' && github.ref_name == 'main' && matrix.dotnet_version == '10.0'
54+
with:
55+
directory: artifacts/test-results
56+
use_oidc: true

build/build/Tasks/Test/UnitTest.cs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using Cake.Common.Build.AzurePipelines.Data;
21
using Cake.Common.Tools.DotNet.Test;
3-
using Cake.Coverlet;
42
using Cake.Incubator.LoggingExtensions;
53
using Common.Utilities;
64

@@ -49,24 +47,10 @@ public override void OnError(Exception exception, BuildContext context)
4947
throw exception;
5048
}
5149

52-
public override void Finally(BuildContext context)
53-
{
54-
var testResultsFiles = context.GetFiles($"{Paths.TestOutput}/*.results.xml");
55-
if (!context.IsAzurePipelineBuild || testResultsFiles.Count == 0) return;
56-
57-
var data = new AzurePipelinesPublishTestResultsData
58-
{
59-
TestResultsFiles = testResultsFiles.ToArray(),
60-
Platform = context.Platform.ToString(),
61-
TestRunner = AzurePipelinesTestRunnerType.JUnit
62-
};
63-
context.BuildSystem().AzurePipelines.Commands.PublishTestResults(data);
64-
}
65-
6650
private static void TestProjectForTarget(BuildContext context, FilePath project, string framework)
6751
{
6852
var testResultsPath = Paths.TestOutput;
69-
var projectName = $"{project.GetFilenameWithoutExtension()}.net{framework}";
53+
var projectName = $"{project.GetFilenameWithoutExtension()}";
7054
var settings = new DotNetTestSettings
7155
{
7256
PathType = DotNetTestPathType.Project,
@@ -78,14 +62,16 @@ private static void TestProjectForTarget(BuildContext context, FilePath project,
7862
};
7963
settings.MSBuildSettings.SetContinuousIntegrationBuild(false);
8064

81-
var resultsPath = context.MakeAbsolute(testResultsPath.CombineWithFilePath($"{projectName}.results.xml"));
65+
var resultsDirectory = context.MakeAbsolute(testResultsPath.Combine(projectName));
66+
8267
settings.WithArgumentCustomization(args => args
8368
.Append("--report-spekt-junit")
84-
.Append("--report-spekt-junit-filename").AppendQuoted(resultsPath.FullPath)
69+
.Append("--report-spekt-junit-filename").AppendQuoted(resultsDirectory.CombineWithFilePath("results.xml").FullPath)
70+
.Append("--results-directory").AppendQuoted(resultsDirectory.FullPath)
8571
.Append("--coverlet")
8672
.Append("--coverlet-output-format").AppendQuoted("cobertura")
87-
.Append("--coverlet-exclude ").AppendQuoted("[GitVersion*.Tests]*")
88-
.Append("--coverlet-exclude ").AppendQuoted("[GitTools.Testing]*")
73+
.Append("--coverlet-exclude").AppendQuoted("[GitVersion*.Tests]*")
74+
.Append("--coverlet-exclude").AppendQuoted("[GitTools.Testing]*")
8975
);
9076

9177
context.DotNetTest(project.FullPath, settings);

0 commit comments

Comments
 (0)