Skip to content

Commit 44b8c6c

Browse files
authored
fix(build): missing sonarcloud csharp coverage (#92)
1 parent 44fc5c7 commit 44b8c6c

File tree

10 files changed

+107
-72
lines changed

10 files changed

+107
-72
lines changed

.github/workflows/DotNET-build.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ jobs:
3131
name: ubuntu-latest
3232
runs-on: ubuntu-latest
3333
steps:
34+
35+
- uses: actions/setup-java@v3
36+
with:
37+
distribution: 'temurin'
38+
java-version: '17'
3439
- uses: actions/checkout@v3
3540
with:
3641
fetch-depth: 0
@@ -47,7 +52,7 @@ jobs:
4752
SonarToken: ${{ secrets.SONAR_TOKEN }}
4853
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4954

50-
- uses: actions/upload-artifact@v2
55+
- uses: actions/upload-artifact@v3
5156
if: always()
5257
with:
5358
name: test-results

.github/workflows/JS-build.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ jobs:
3131
name: ubuntu-latest
3232
runs-on: ubuntu-latest
3333
steps:
34+
35+
- uses: actions/setup-java@v3
36+
with:
37+
distribution: 'temurin'
38+
java-version: '17'
3439
- uses: actions/checkout@v3
3540
with:
3641
fetch-depth: 0
@@ -63,7 +68,7 @@ jobs:
6368
-Dsonar.test.inclusions=src/Serilog.Ui.Web/assets/__tests__/**/*
6469
-Dsonar.javascript.lcov.reportPaths=./src/Serilog.Ui.Web/coverage/lcov.info
6570
66-
- uses: actions/upload-artifact@v2
71+
- uses: actions/upload-artifact@v3
6772
if: always()
6873
with:
6974
name: test-results

.github/workflows/Release.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ jobs:
4343
name: ubuntu-latest
4444
runs-on: ubuntu-latest
4545
steps:
46+
47+
- uses: actions/setup-java@v3
48+
with:
49+
distribution: 'temurin'
50+
java-version: '17'
4651
- uses: actions/checkout@v3
4752
with:
4853
fetch-depth: 0

build/Build.Backend.Tests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ partial class Build : NukeBuild
3131
.Executes(() =>
3232
{
3333
DotnetCoverage?.Invoke(
34-
@"collect -f xml -o ""coverage.xml"" dotnet test --configuration Release --no-build --logger=""trx;LogFileName=test-results.trx""");
34+
@"collect -f xml -o coverage.xml dotnet test --configuration Release --no-build --logger=""trx;LogFileName=test-results.trx""");
3535
});
36-
}
36+
}

build/Build.Backend.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
using Nuke.Common.IO;
33
using Nuke.Common.Tools.DotNet;
44
using Nuke.Common.Utilities.Collections;
5-
using System.Diagnostics.CodeAnalysis;
65
using static Nuke.Common.Tools.DotNet.DotNetTasks;
76

87
partial class Build : NukeBuild
98
{
10-
[SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Not necessary")]
119
Target Backend_Clean => _ => _
1210
.Executes(() =>
1311
{

build/Build.CI.GithubActions.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using Nuke.Common;
22
using Nuke.Common.CI.GitHubActions;
33
using Nuke.Common.Tooling;
4-
using Nuke.Common.Tools.GitHub;
54
using Nuke.Common.Tools.SonarScanner;
65
using static CustomGithubActionsAttribute;
76

@@ -88,7 +87,7 @@ partial class Build : NukeBuild
8887
SonarScannerTasks.SonarScannerBegin(new SonarScannerBeginSettings()
8988
.SetExcludeTestProjects(true)
9089
.SetFramework("net5.0")
91-
.SetLogin(SonarToken)
90+
.SetAdditionalParameter("sonar.token", SonarToken) // replace deprecated .login
9291
.SetOrganization(SonarCloudInfo.Organization)
9392
.SetProjectKey(SonarCloudInfo.BackendProjectKey)
9493
.SetServer("https://sonarcloud.io")
@@ -99,7 +98,7 @@ partial class Build : NukeBuild
9998
"src/Serilog.Ui.Web/node_modules/**/*",
10099
"src/Serilog.Ui.Web/*.js",
101100
"src/Serilog.Ui.Web/*.json")
102-
.SetVisualStudioCoveragePaths("**/coverage.xml")
101+
.SetVisualStudioCoveragePaths("coverage.xml", "**/coverage.xml", "./**/coverage.xml")
103102
.SetProcessEnvironmentVariable("GITHUB_TOKEN", GitHubActions.Instance.Token)
104103
.SetProcessEnvironmentVariable("SONAR_TOKEN", SonarToken)
105104
);
@@ -115,7 +114,7 @@ partial class Build : NukeBuild
115114
{
116115
SonarScannerTasks.SonarScannerEnd(new SonarScannerEndSettings()
117116
.SetFramework("net5.0")
118-
.SetLogin(SonarToken)
117+
.SetProcessArgumentConfigurator(_ => _.Add("/d:sonar.token={value}", SonarToken, secret: true))
119118
.SetProcessEnvironmentVariable("GITHUB_TOKEN", GitHubActions.Instance.Token)
120119
.SetProcessEnvironmentVariable("SONAR_TOKEN", SonarToken));
121120
});
@@ -124,4 +123,4 @@ partial class Build : NukeBuild
124123
public readonly record struct ReleaseParams(string Key, string ShouldPublish, string Project)
125124
{
126125
public bool Publish() => ShouldPublish.Equals("true");
127-
}
126+
}

build/Build.Frontend.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
using Nuke.Common.Tools.Docker;
55
using Nuke.Common.Tools.Npm;
66
using Nuke.Common.Utilities.Collections;
7-
using System.Diagnostics.CodeAnalysis;
87

98
partial class Build : NukeBuild
109
{
11-
[SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Not necessary")]
1210
Target Frontend_Clean => _ => _
1311
.Executes(() =>
1412
{

build/CustomGithubActionsAttribute.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Nuke.Common.Utilities;
55
using System;
66
using System.Collections.Generic;
7+
using System.Linq;
78

89
/// <summary>
910
/// from: https://github.com/RicoSuter/NSwag/blob/master/build/Build.CI.GitHubActions.cs
@@ -28,7 +29,7 @@ public enum GithubAction
2829
protected override GitHubActionsJob GetJobs(GitHubActionsImage image, IReadOnlyCollection<ExecutableTarget> relevantTargets)
2930
{
3031
var job = base.GetJobs(image, relevantTargets);
31-
var newSteps = new List<GitHubActionsStep>(job.Steps);
32+
var newSteps = new List<GitHubActionsStep>(new GitHubActionsStep[] { new GitHubActionSetupJava17() }.Concat(job.Steps));
3233

3334
foreach (var act in AddGithubActions)
3435
{
@@ -59,6 +60,30 @@ protected override GitHubActionsJob GetJobs(GitHubActionsImage image, IReadOnlyC
5960
}
6061
}
6162

63+
/// <summary>
64+
/// using: https://github.com/actions/setup-java
65+
/// </summary>
66+
class GitHubActionSetupJava17 : GitHubActionsStep
67+
{
68+
public override void Write(CustomFileWriter writer)
69+
{
70+
writer.WriteLine(); // empty line to separate tasks
71+
72+
writer.WriteLine("- uses: actions/setup-java@v3");
73+
74+
using (writer.Indent())
75+
{
76+
writer.WriteLine("with:");
77+
78+
using (writer.Indent())
79+
{
80+
writer.WriteLine($"distribution: 'temurin'");
81+
writer.WriteLine($"java-version: '17'");
82+
}
83+
}
84+
}
85+
}
86+
6287
class GithubActionUploadArtifact : GitHubActionsStep
6388
{
6489
readonly string Path;
@@ -72,7 +97,7 @@ public override void Write(CustomFileWriter writer)
7297
{
7398
writer.WriteLine(); // empty line to separate tasks
7499

75-
writer.WriteLine("- uses: actions/upload-artifact@v2");
100+
writer.WriteLine("- uses: actions/upload-artifact@v3");
76101

77102
using (writer.Indent())
78103
{

build/_build.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</ItemGroup>
2222

2323
<ItemGroup>
24-
<PackageDownload Include="dotnet-coverage" Version="[17.6.11]" />
25-
<PackageDownload Include="dotnet-sonarscanner" Version="[5.12.0]" />
24+
<PackageDownload Include="dotnet-coverage" Version="[17.8.6]" />
25+
<PackageDownload Include="dotnet-sonarscanner" Version="[5.13.1]" />
2626
</ItemGroup>
2727
</Project>
Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
1-
using Elasticsearch.Net;
2-
using Newtonsoft.Json;
3-
using System;
4-
using System.IO;
5-
using System.Threading;
6-
using System.Threading.Tasks;
7-
8-
namespace Serilog.Ui.ElasticSearchProvider
9-
{
10-
internal class VanillaSerializer : IElasticsearchSerializer
11-
{
12-
public T Deserialize<T>(Stream stream) => (T)Deserialize(typeof(T), stream);
13-
14-
public object Deserialize(Type type, Stream stream)
15-
{
16-
var reader = new StreamReader(stream);
17-
18-
using (var jsonTextReader = new JsonTextReader(reader))
19-
{
20-
var serializer = new JsonSerializer();
21-
return serializer.Deserialize(jsonTextReader, type);
22-
}
23-
}
24-
25-
public Task<T> DeserializeAsync<T>(Stream stream, CancellationToken cancellationToken = default) =>
26-
Task.FromResult(Deserialize<T>(stream));
27-
28-
public Task<object> DeserializeAsync(Type type, Stream stream, CancellationToken cancellationToken = default) =>
29-
Task.FromResult(Deserialize(type, stream));
30-
31-
public void Serialize<T>(T data, Stream stream, SerializationFormatting formatting = SerializationFormatting.Indented)
32-
{
33-
var writer = new StreamWriter(stream);
34-
35-
using (var jWriter = new JsonTextWriter(writer))
36-
{
37-
var serializer = new JsonSerializer
38-
{
39-
Formatting = formatting == SerializationFormatting.Indented ? Formatting.Indented : Formatting.None
40-
};
41-
serializer.Serialize(jWriter, data);
42-
}
43-
}
44-
45-
public Task SerializeAsync<T>(
46-
T data,
47-
Stream stream,
48-
SerializationFormatting formatting = SerializationFormatting.Indented,
49-
CancellationToken cancellationToken = default)
50-
{
51-
Serialize(data, stream, formatting);
52-
53-
return Task.CompletedTask;
54-
}
55-
}
1+
using Elasticsearch.Net;
2+
using Newtonsoft.Json;
3+
using System;
4+
using System.IO;
5+
using System.Threading;
6+
using System.Threading.Tasks;
7+
8+
namespace Serilog.Ui.ElasticSearchProvider
9+
{
10+
internal class VanillaSerializer : IElasticsearchSerializer
11+
{
12+
public T Deserialize<T>(Stream stream) => (T)Deserialize(typeof(T), stream);
13+
14+
public object Deserialize(Type type, Stream stream)
15+
{
16+
var reader = new StreamReader(stream);
17+
18+
using (var jsonTextReader = new JsonTextReader(reader))
19+
{
20+
var serializer = new JsonSerializer();
21+
return serializer.Deserialize(jsonTextReader, type);
22+
}
23+
}
24+
25+
public Task<T> DeserializeAsync<T>(Stream stream, CancellationToken cancellationToken = default) =>
26+
Task.FromResult(Deserialize<T>(stream));
27+
28+
public Task<object> DeserializeAsync(Type type, Stream stream, CancellationToken cancellationToken = default) =>
29+
Task.FromResult(Deserialize(type, stream));
30+
31+
public void Serialize<T>(T data, Stream stream, SerializationFormatting formatting = SerializationFormatting.None)
32+
{
33+
var writer = new StreamWriter(stream);
34+
35+
using (var jWriter = new JsonTextWriter(writer))
36+
{
37+
var serializer = new JsonSerializer
38+
{
39+
Formatting = formatting == SerializationFormatting.Indented ? Formatting.Indented : Formatting.None
40+
};
41+
serializer.Serialize(jWriter, data);
42+
}
43+
}
44+
45+
public Task SerializeAsync<T>(
46+
T data,
47+
Stream stream,
48+
SerializationFormatting formatting = SerializationFormatting.None,
49+
CancellationToken cancellationToken = default)
50+
{
51+
Serialize(data, stream, formatting);
52+
53+
return Task.CompletedTask;
54+
}
55+
}
5656
}

0 commit comments

Comments
 (0)