Skip to content

Commit 481e594

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

File tree

3 files changed

+57
-27
lines changed

3 files changed

+57
-27
lines changed

.github/codecov.yml

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,46 @@
1+
comment:
2+
layout: "header, diff, flags, components"
3+
behavior: default
4+
require_changes: false
5+
component_management:
6+
individual_components:
7+
- component_id: gitversion-app
8+
name: GitVersion.App
9+
paths: [ src/GitVersion.App/** ]
10+
- component_id: gitversion-buildagents
11+
name: GitVersion.BuildAgents
12+
paths: [ src/GitVersion.BuildAgents/** ]
13+
- component_id: gitversion-configuration
14+
name: GitVersion.Configuration
15+
paths: [ src/GitVersion.Configuration/** ]
16+
- component_id: gitversion-core
17+
name: GitVersion.Core
18+
paths: [ src/GitVersion.Core/** ]
19+
- component_id: gitversion-libgit2sharp
20+
name: GitVersion.LibGit2Sharp
21+
paths: [ src/GitVersion.LibGit2Sharp/** ]
22+
- component_id: gitversion-msbuild
23+
name: GitVersion.MsBuild
24+
paths: [ src/GitVersion.MsBuild/** ]
25+
- component_id: gitversion-output
26+
name: GitVersion.Output
27+
paths: [ src/GitVersion.Output/** ]
128
coverage:
229
range: 50..70
330
round: down
431
precision: 2
532
status:
33+
project:
34+
default:
35+
target: auto
36+
base: auto
37+
paths:
38+
- src
39+
branches:
40+
- main
641
patch:
742
default:
843
# basic
944
target: auto
1045
threshold: 1%
11-
base: auto
46+
base: auto

.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("[GitVersion.Testing]*")
8975
);
9076

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

0 commit comments

Comments
 (0)