From 44b8c6cc0a87814fa2a9626bce54716e675cb9df Mon Sep 17 00:00:00 2001 From: matteoGregoricchio <32459930+followynne@users.noreply.github.com> Date: Mon, 25 Sep 2023 09:43:09 +0200 Subject: [PATCH] fix(build): missing sonarcloud csharp coverage (#92) --- .github/workflows/DotNET-build.yml | 7 +- .github/workflows/JS-build.yml | 7 +- .github/workflows/Release.yml | 5 + build/Build.Backend.Tests.cs | 4 +- build/Build.Backend.cs | 2 - build/Build.CI.GithubActions.cs | 9 +- build/Build.Frontend.cs | 2 - build/CustomGithubActionsAttribute.cs | 29 ++++- build/_build.csproj | 4 +- .../Extensions/VanillaSerializer.cs | 110 +++++++++--------- 10 files changed, 107 insertions(+), 72 deletions(-) diff --git a/.github/workflows/DotNET-build.yml b/.github/workflows/DotNET-build.yml index 495b1bf3..1cb6378e 100644 --- a/.github/workflows/DotNET-build.yml +++ b/.github/workflows/DotNET-build.yml @@ -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 @@ -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 diff --git a/.github/workflows/JS-build.yml b/.github/workflows/JS-build.yml index 73fee295..60398b54 100644 --- a/.github/workflows/JS-build.yml +++ b/.github/workflows/JS-build.yml @@ -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 @@ -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 diff --git a/.github/workflows/Release.yml b/.github/workflows/Release.yml index 4cffbdd3..7b68c6c1 100644 --- a/.github/workflows/Release.yml +++ b/.github/workflows/Release.yml @@ -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 diff --git a/build/Build.Backend.Tests.cs b/build/Build.Backend.Tests.cs index 5bc5414c..f9614768 100644 --- a/build/Build.Backend.Tests.cs +++ b/build/Build.Backend.Tests.cs @@ -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"""); }); -} \ No newline at end of file +} diff --git a/build/Build.Backend.cs b/build/Build.Backend.cs index 317ee73e..501be96d 100644 --- a/build/Build.Backend.cs +++ b/build/Build.Backend.cs @@ -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(() => { diff --git a/build/Build.CI.GithubActions.cs b/build/Build.CI.GithubActions.cs index 5558ae26..5c1ad91e 100644 --- a/build/Build.CI.GithubActions.cs +++ b/build/Build.CI.GithubActions.cs @@ -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; @@ -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") @@ -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) ); @@ -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)); }); @@ -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"); -} \ No newline at end of file +} diff --git a/build/Build.Frontend.cs b/build/Build.Frontend.cs index b1af2f6c..7c3ce3e6 100644 --- a/build/Build.Frontend.cs +++ b/build/Build.Frontend.cs @@ -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(() => { diff --git a/build/CustomGithubActionsAttribute.cs b/build/CustomGithubActionsAttribute.cs index 2bbb86da..48b5facd 100644 --- a/build/CustomGithubActionsAttribute.cs +++ b/build/CustomGithubActionsAttribute.cs @@ -4,6 +4,7 @@ using Nuke.Common.Utilities; using System; using System.Collections.Generic; +using System.Linq; /// /// from: https://github.com/RicoSuter/NSwag/blob/master/build/Build.CI.GitHubActions.cs @@ -28,7 +29,7 @@ public enum GithubAction protected override GitHubActionsJob GetJobs(GitHubActionsImage image, IReadOnlyCollection relevantTargets) { var job = base.GetJobs(image, relevantTargets); - var newSteps = new List(job.Steps); + var newSteps = new List(new GitHubActionsStep[] { new GitHubActionSetupJava17() }.Concat(job.Steps)); foreach (var act in AddGithubActions) { @@ -59,6 +60,30 @@ protected override GitHubActionsJob GetJobs(GitHubActionsImage image, IReadOnlyC } } +/// +/// using: https://github.com/actions/setup-java +/// +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; @@ -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()) { diff --git a/build/_build.csproj b/build/_build.csproj index e7c568e0..89a0f97c 100644 --- a/build/_build.csproj +++ b/build/_build.csproj @@ -21,7 +21,7 @@ - - + + diff --git a/src/Serilog.Ui.ElasticSearchProvider/Extensions/VanillaSerializer.cs b/src/Serilog.Ui.ElasticSearchProvider/Extensions/VanillaSerializer.cs index f0ce1be1..c61cd594 100644 --- a/src/Serilog.Ui.ElasticSearchProvider/Extensions/VanillaSerializer.cs +++ b/src/Serilog.Ui.ElasticSearchProvider/Extensions/VanillaSerializer.cs @@ -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(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 DeserializeAsync(Stream stream, CancellationToken cancellationToken = default) => - Task.FromResult(Deserialize(stream)); - - public Task DeserializeAsync(Type type, Stream stream, CancellationToken cancellationToken = default) => - Task.FromResult(Deserialize(type, stream)); - - public void Serialize(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 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(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 DeserializeAsync(Stream stream, CancellationToken cancellationToken = default) => + Task.FromResult(Deserialize(stream)); + + public Task DeserializeAsync(Type type, Stream stream, CancellationToken cancellationToken = default) => + Task.FromResult(Deserialize(type, stream)); + + public void Serialize(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 data, + Stream stream, + SerializationFormatting formatting = SerializationFormatting.None, + CancellationToken cancellationToken = default) + { + Serialize(data, stream, formatting); + + return Task.CompletedTask; + } + } } \ No newline at end of file