diff --git a/.github/workflows/packages.yml b/.github/workflows/packages.yml index 440d9c904..8a8f70cdc 100644 --- a/.github/workflows/packages.yml +++ b/.github/workflows/packages.yml @@ -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: diff --git a/.nuke/build.schema.json b/.nuke/build.schema.json index 3f9224ea7..1f7a97ee8 100644 --- a/.nuke/build.schema.json +++ b/.nuke/build.schema.json @@ -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", diff --git a/build/Build.cs b/build/Build.cs index e0581dd4c..9151ed62d 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -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(x => ((ICompile) x).Compile); + public static int Main() => Execute(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 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 TestProjects => ((IHazSolution) this).Solution.AllProjects.Where(x => x.Name.EndsWith("Tests")); - - public Configure TestProjectSettings => (testSettings, _) => testSettings - .When(GitHubActions.Instance is not null, settings => settings.AddLoggers("GitHubActions;report-warnings=false")); + public IEnumerable TestProjects => + ((IHazSolution)this).Solution.AllProjects.Where(x => x.Name.EndsWith("Tests")); + public Configure 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\""))); } \ No newline at end of file diff --git a/test/component/Elsa.ProtoCluster.ComponentTests/Elsa.ProtoCluster.ComponentTests.csproj b/test/component/Elsa.ProtoCluster.ComponentTests/Elsa.ProtoCluster.ComponentTests.csproj index db2d267c6..8676c2557 100644 --- a/test/component/Elsa.ProtoCluster.ComponentTests/Elsa.ProtoCluster.ComponentTests.csproj +++ b/test/component/Elsa.ProtoCluster.ComponentTests/Elsa.ProtoCluster.ComponentTests.csproj @@ -1,7 +1,7 @@ - net8.0 + {ca65b7d5-57e8-4932-b8b8-732d040c9b3a} diff --git a/test/integration/Elsa.ServiceBus.IntegrationTests/Elsa.ServiceBus.IntegrationTests.csproj b/test/integration/Elsa.ServiceBus.IntegrationTests/Elsa.ServiceBus.IntegrationTests.csproj index 588622d0a..e0dec8776 100644 --- a/test/integration/Elsa.ServiceBus.IntegrationTests/Elsa.ServiceBus.IntegrationTests.csproj +++ b/test/integration/Elsa.ServiceBus.IntegrationTests/Elsa.ServiceBus.IntegrationTests.csproj @@ -1,5 +1,9 @@  - + + + {6e0b177a-a1c8-4485-bc3f-cf8e6e36d3f6} + + diff --git a/test/integration/Elsa.Workflows.IntegrationTests/Elsa.Workflows.IntegrationTests.csproj b/test/integration/Elsa.Workflows.IntegrationTests/Elsa.Workflows.IntegrationTests.csproj index 48608935a..681d9d2a6 100644 --- a/test/integration/Elsa.Workflows.IntegrationTests/Elsa.Workflows.IntegrationTests.csproj +++ b/test/integration/Elsa.Workflows.IntegrationTests/Elsa.Workflows.IntegrationTests.csproj @@ -1,5 +1,9 @@ - + + + {ca65b7d5-57e8-4932-b8b8-732d040c9b3a} + +