Feature/sonar cloud (#5224)

* Update packages.yml

* Added sonar cloud properties

* Update packages.yml

* Update packages.yml

* Update packages.yml

* Update packages.yml

* Updated nuke Build to produce test coverage output

* Updated project key

* Fix organization key

* Versioning fix

* Removed sonar properties

* Added jdk17

* Changed build configuration for nuke

* Added opencover paths

* Added the coverlet collector NuGet package

* Added exclusions

* Updated workflow

* Modified exclusions

* Updated packages.yml to contain sonar cloud integration

* Removed test github action

* Updated for test coverage

* Updated MergeWith property for the tests

* Add verbose to check for code coverage issue

* Updated reportPaths

* Added --collect parameter

* Updates

* Updated packages workflow

* Updated exclusions

* Added sonar exclusions

* Updated exclusions

---------

Co-authored-by: Sipke Schoorstra <sipkeschoorstra@outlook.com>
This commit is contained in:
cristinamudura 2024-04-26 15:46:34 +02:00 committed by GitHub
parent 1c22cdd30c
commit 9fa1b4685e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 59 additions and 18 deletions

View file

@ -64,8 +64,25 @@ jobs:
else
echo "VERSION=3.2.0-${PACKAGE_PREFIX}.${{github.run_number}}" >> $GITHUB_ENV
fi
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'adopt'
- name: Install SonarScanner for .NET
run: dotnet tool install --global dotnet-sonarscanner
- name: Install Coverlet for code coverage
run: dotnet tool install --global coverlet.console
- name: Begin SonarCloud analysis
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: dotnet sonarscanner begin /k:"elsa-workflows_elsa-core" /o:"elsa-workflows" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.exclusions=**/obj/**,**/*.dll,build/**,samples/**,src/bundles/** /d:"sonar.verbose=true" /d:sonar.cs.opencover.reportsPaths=**/testresults/**/coverage.opencover.xml
- name: Compile+Test+Pack
run: ./build.sh Compile+Test+Pack --version ${VERSION}
run: ./build.sh Compile+Test+Pack --version ${VERSION} --analyseCode true
- name: End SonarCloud analysis
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: dotnet sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
- name: Upload artifact
uses: actions/upload-artifact@v3
with:

View file

@ -6,6 +6,9 @@
"build": {
"type": "object",
"properties": {
"AnalyseCode": {
"type": "boolean"
},
"Configuration": {
"type": "string",
"enum": [
@ -75,6 +78,7 @@
"items": {
"type": "string",
"enum": [
"Analyze",
"Clean",
"Compile",
"Pack",
@ -93,6 +97,7 @@
"items": {
"type": "string",
"enum": [
"Analyze",
"Clean",
"Compile",
"Pack",

View file

@ -8,7 +8,9 @@ using Nuke.Common.Git;
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.Coverlet;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.SonarScanner;
using Nuke.Common.Utilities.Collections;
using Nuke.Components;
using Serilog;
@ -16,23 +18,26 @@ using Serilog;
[ShutdownDotNetAfterServerBuild]
partial class Build : NukeBuild, ITest, IPack
{
public static int Main() => Execute<Build>(x => ((ICompile) x).Compile);
public static int Main() => Execute<Build>(x => ((ICompile)x).Compile);
[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")] readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;
[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;
[GitRepository] readonly GitRepository GitRepository;
AbsolutePath SourceDirectory => RootDirectory / "src";
public AbsolutePath PackagesDirectory => RootDirectory / "packages";
public AbsolutePath TestResultDirectory => RootDirectory / "testresults";
string TagVersion => GitRepository.Tags.SingleOrDefault(x => "v".StartsWith(x))?[1..];
bool IsTaggedBuild => !string.IsNullOrWhiteSpace(TagVersion);
string VersionSuffix;
[Parameter]
string Version;
[Parameter] string Version;
[Parameter] bool AnalyseCode;
protected override void OnBuildInitialized()
{
@ -45,11 +50,8 @@ partial class Build : NukeBuild, ITest, IPack
VersionSuffix = $"dev-{DateTime.UtcNow:yyyyMMdd-HHmm}";
}
Log.Information("BUILD SETUP");
Log.Information("Configuration:\t{Configuration}", Configuration);
Log.Information("Version suffix:\t{VersionSuffix}", VersionSuffix);
Log.Information("Version:\t\t{Version}", Version);
Log.Information("Tagged build:\t{IsTaggedBuild}", IsTaggedBuild);
Log.Information("BUILD SETUP:\nConfiguration: {Configuration}\nVersion Suffix: {VersionSuffix}\nVersion: {Version}\nTagged Build: {IsTaggedBuild}\nAnalyse Code: {AnalyseCode}",
Configuration, VersionSuffix, Version, IsTaggedBuild, AnalyseCode);
}
Target Clean => _ => _
@ -57,8 +59,11 @@ partial class Build : NukeBuild, ITest, IPack
.Executes(() =>
{
SourceDirectory.GlobDirectories("**/bin", "**/obj").ForEach(x => x.DeleteDirectory());
((IHazArtifacts) this).ArtifactsDirectory.CreateOrCleanDirectory();
((IHazArtifacts)this).ArtifactsDirectory.CreateOrCleanDirectory();
TestResultDirectory.CreateOrCleanDirectory();
});
public Configure<DotNetBuildSettings> CompileSettings => _ => _
// ensure we don't generate too much output in CI run
@ -66,9 +71,15 @@ partial class Build : NukeBuild, ITest, IPack
// 1 Displays severe warning messages
.SetWarningLevel(IsServerBuild ? 0 : 1);
public IEnumerable<Project> TestProjects => ((IHazSolution) this).Solution.AllProjects.Where(x => x.Name.EndsWith("Tests"));
public Configure<DotNetTestSettings, Project> TestProjectSettings => (testSettings, _) => testSettings
.When(GitHubActions.Instance is not null, settings => settings.AddLoggers("GitHubActions;report-warnings=false"));
public IEnumerable<Project> TestProjects =>
((IHazSolution)this).Solution.AllProjects.Where(x => x.Name.EndsWith("Tests"));
public Configure<DotNetTestSettings, Project> TestProjectSettings => (testSettings, project) => testSettings
.When(GitHubActions.Instance is not null, settings => settings.AddLoggers("GitHubActions;report-warnings=false"))
.When(AnalyseCode, settings => settings.SetCoverletOutputFormat(CoverletOutputFormat.opencover))
.When(AnalyseCode, settings => settings.EnableCollectCoverage())
.When(AnalyseCode, settings => settings.SetResultsDirectory(TestResultDirectory))
.When(AnalyseCode, settings => settings.SetCoverletOutput($"{TestResultDirectory}/opencoverCoverage.xml"))
.When(AnalyseCode, settings => settings.SetProcessArgumentConfigurator(args =>
args.Add("--collect:\"XPlat Code Coverage;Format=opencover\"")));
}

View file

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ProjectGuid>{ca65b7d5-57e8-4932-b8b8-732d040c9b3a}</ProjectGuid>
</PropertyGroup>
<ItemGroup>

View file

@ -1,5 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<ProjectGuid>{6e0b177a-a1c8-4485-bc3f-cf8e6e36d3f6}</ProjectGuid>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NSubstitute" />
<PackageReference Include="Azure.Messaging.ServiceBus" />

View file

@ -1,5 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<ProjectGuid>{ca65b7d5-57e8-4932-b8b8-732d040c9b3a}</ProjectGuid>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Proto.Persistence.Sqlite" />
</ItemGroup>