Skip to content

Commit

Permalink
fix(build): missing sonarcloud csharp coverage (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
followynne authored Sep 25, 2023
1 parent 44fc5c7 commit 44b8c6c
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 72 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/DotNET-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ jobs:
name: ubuntu-latest
runs-on: ubuntu-latest
steps:

- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
- uses: actions/checkout@v3
with:
fetch-depth: 0
Expand All @@ -47,7 +52,7 @@ jobs:
SonarToken: ${{ secrets.SONAR_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v3
if: always()
with:
name: test-results
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/JS-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ jobs:
name: ubuntu-latest
runs-on: ubuntu-latest
steps:

- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
- uses: actions/checkout@v3
with:
fetch-depth: 0
Expand Down Expand Up @@ -63,7 +68,7 @@ jobs:
-Dsonar.test.inclusions=src/Serilog.Ui.Web/assets/__tests__/**/*
-Dsonar.javascript.lcov.reportPaths=./src/Serilog.Ui.Web/coverage/lcov.info
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v3
if: always()
with:
name: test-results
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ jobs:
name: ubuntu-latest
runs-on: ubuntu-latest
steps:

- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
- uses: actions/checkout@v3
with:
fetch-depth: 0
Expand Down
4 changes: 2 additions & 2 deletions build/Build.Backend.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ partial class Build : NukeBuild
.Executes(() =>
{
DotnetCoverage?.Invoke(
@"collect -f xml -o ""coverage.xml"" dotnet test --configuration Release --no-build --logger=""trx;LogFileName=test-results.trx""");
@"collect -f xml -o coverage.xml dotnet test --configuration Release --no-build --logger=""trx;LogFileName=test-results.trx""");
});
}
}
2 changes: 0 additions & 2 deletions build/Build.Backend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
using Nuke.Common.IO;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Utilities.Collections;
using System.Diagnostics.CodeAnalysis;
using static Nuke.Common.Tools.DotNet.DotNetTasks;

partial class Build : NukeBuild
{
[SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Not necessary")]
Target Backend_Clean => _ => _
.Executes(() =>
{
Expand Down
9 changes: 4 additions & 5 deletions build/Build.CI.GithubActions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Nuke.Common;
using Nuke.Common.CI.GitHubActions;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.GitHub;
using Nuke.Common.Tools.SonarScanner;
using static CustomGithubActionsAttribute;

Expand Down Expand Up @@ -88,7 +87,7 @@ partial class Build : NukeBuild
SonarScannerTasks.SonarScannerBegin(new SonarScannerBeginSettings()
.SetExcludeTestProjects(true)
.SetFramework("net5.0")
.SetLogin(SonarToken)
.SetAdditionalParameter("sonar.token", SonarToken) // replace deprecated .login
.SetOrganization(SonarCloudInfo.Organization)
.SetProjectKey(SonarCloudInfo.BackendProjectKey)
.SetServer("https://sonarcloud.io")
Expand All @@ -99,7 +98,7 @@ partial class Build : NukeBuild
"src/Serilog.Ui.Web/node_modules/**/*",
"src/Serilog.Ui.Web/*.js",
"src/Serilog.Ui.Web/*.json")
.SetVisualStudioCoveragePaths("**/coverage.xml")
.SetVisualStudioCoveragePaths("coverage.xml", "**/coverage.xml", "./**/coverage.xml")
.SetProcessEnvironmentVariable("GITHUB_TOKEN", GitHubActions.Instance.Token)
.SetProcessEnvironmentVariable("SONAR_TOKEN", SonarToken)
);
Expand All @@ -115,7 +114,7 @@ partial class Build : NukeBuild
{
SonarScannerTasks.SonarScannerEnd(new SonarScannerEndSettings()
.SetFramework("net5.0")
.SetLogin(SonarToken)
.SetProcessArgumentConfigurator(_ => _.Add("/d:sonar.token={value}", SonarToken, secret: true))
.SetProcessEnvironmentVariable("GITHUB_TOKEN", GitHubActions.Instance.Token)
.SetProcessEnvironmentVariable("SONAR_TOKEN", SonarToken));
});
Expand All @@ -124,4 +123,4 @@ partial class Build : NukeBuild
public readonly record struct ReleaseParams(string Key, string ShouldPublish, string Project)
{
public bool Publish() => ShouldPublish.Equals("true");
}
}
2 changes: 0 additions & 2 deletions build/Build.Frontend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
using Nuke.Common.Tools.Docker;
using Nuke.Common.Tools.Npm;
using Nuke.Common.Utilities.Collections;
using System.Diagnostics.CodeAnalysis;

partial class Build : NukeBuild
{
[SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Not necessary")]
Target Frontend_Clean => _ => _
.Executes(() =>
{
Expand Down
29 changes: 27 additions & 2 deletions build/CustomGithubActionsAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Nuke.Common.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;

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

foreach (var act in AddGithubActions)
{
Expand Down Expand Up @@ -59,6 +60,30 @@ protected override GitHubActionsJob GetJobs(GitHubActionsImage image, IReadOnlyC
}
}

/// <summary>
/// using: https://github.com/actions/setup-java
/// </summary>
class GitHubActionSetupJava17 : GitHubActionsStep
{
public override void Write(CustomFileWriter writer)
{
writer.WriteLine(); // empty line to separate tasks

writer.WriteLine("- uses: actions/setup-java@v3");

using (writer.Indent())
{
writer.WriteLine("with:");

using (writer.Indent())
{
writer.WriteLine($"distribution: 'temurin'");
writer.WriteLine($"java-version: '17'");
}
}
}
}

class GithubActionUploadArtifact : GitHubActionsStep
{
readonly string Path;
Expand All @@ -72,7 +97,7 @@ public override void Write(CustomFileWriter writer)
{
writer.WriteLine(); // empty line to separate tasks

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

using (writer.Indent())
{
Expand Down
4 changes: 2 additions & 2 deletions build/_build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</ItemGroup>

<ItemGroup>
<PackageDownload Include="dotnet-coverage" Version="[17.6.11]" />
<PackageDownload Include="dotnet-sonarscanner" Version="[5.12.0]" />
<PackageDownload Include="dotnet-coverage" Version="[17.8.6]" />
<PackageDownload Include="dotnet-sonarscanner" Version="[5.13.1]" />
</ItemGroup>
</Project>
110 changes: 55 additions & 55 deletions src/Serilog.Ui.ElasticSearchProvider/Extensions/VanillaSerializer.cs
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
using Elasticsearch.Net;
using Newtonsoft.Json;
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;

namespace Serilog.Ui.ElasticSearchProvider
{
internal class VanillaSerializer : IElasticsearchSerializer
{
public T Deserialize<T>(Stream stream) => (T)Deserialize(typeof(T), stream);

public object Deserialize(Type type, Stream stream)
{
var reader = new StreamReader(stream);

using (var jsonTextReader = new JsonTextReader(reader))
{
var serializer = new JsonSerializer();
return serializer.Deserialize(jsonTextReader, type);
}
}

public Task<T> DeserializeAsync<T>(Stream stream, CancellationToken cancellationToken = default) =>
Task.FromResult(Deserialize<T>(stream));

public Task<object> DeserializeAsync(Type type, Stream stream, CancellationToken cancellationToken = default) =>
Task.FromResult(Deserialize(type, stream));

public void Serialize<T>(T data, Stream stream, SerializationFormatting formatting = SerializationFormatting.Indented)
{
var writer = new StreamWriter(stream);

using (var jWriter = new JsonTextWriter(writer))
{
var serializer = new JsonSerializer
{
Formatting = formatting == SerializationFormatting.Indented ? Formatting.Indented : Formatting.None
};
serializer.Serialize(jWriter, data);
}
}

public Task SerializeAsync<T>(
T data,
Stream stream,
SerializationFormatting formatting = SerializationFormatting.Indented,
CancellationToken cancellationToken = default)
{
Serialize(data, stream, formatting);

return Task.CompletedTask;
}
}
using Elasticsearch.Net;
using Newtonsoft.Json;
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;

namespace Serilog.Ui.ElasticSearchProvider
{
internal class VanillaSerializer : IElasticsearchSerializer
{
public T Deserialize<T>(Stream stream) => (T)Deserialize(typeof(T), stream);

public object Deserialize(Type type, Stream stream)
{
var reader = new StreamReader(stream);

using (var jsonTextReader = new JsonTextReader(reader))
{
var serializer = new JsonSerializer();
return serializer.Deserialize(jsonTextReader, type);
}
}

public Task<T> DeserializeAsync<T>(Stream stream, CancellationToken cancellationToken = default) =>
Task.FromResult(Deserialize<T>(stream));

public Task<object> DeserializeAsync(Type type, Stream stream, CancellationToken cancellationToken = default) =>
Task.FromResult(Deserialize(type, stream));

public void Serialize<T>(T data, Stream stream, SerializationFormatting formatting = SerializationFormatting.None)
{
var writer = new StreamWriter(stream);

using (var jWriter = new JsonTextWriter(writer))
{
var serializer = new JsonSerializer
{
Formatting = formatting == SerializationFormatting.Indented ? Formatting.Indented : Formatting.None
};
serializer.Serialize(jWriter, data);
}
}

public Task SerializeAsync<T>(
T data,
Stream stream,
SerializationFormatting formatting = SerializationFormatting.None,
CancellationToken cancellationToken = default)
{
Serialize(data, stream, formatting);

return Task.CompletedTask;
}
}
}

0 comments on commit 44b8c6c

Please sign in to comment.