diff --git a/.build/Build..cs b/.build/Build..cs index 6eaddbf..ea711f1 100644 --- a/.build/Build..cs +++ b/.build/Build..cs @@ -45,6 +45,13 @@ // }, // OnPushBranches = new[] { "main" }, // AutoGenerate = false)] +[GitHubActions( + "Sonar", + GitHubActionsImage.WindowsLatest, + On = new[] { GitHubActionsTrigger.PullRequest }, + InvokedTargets = new[] { nameof(Sonar) }, + ImportSecrets = new[] { nameof(SonarToken) }, + AutoGenerate = false)] [CheckBuildProjectConfigurations] [ShutdownDotNetAfterServerBuild] partial class Build : NukeBuild @@ -131,6 +138,13 @@ protected override void OnBuildInitialized() Identity_Compile ); + Target Backend_All => _ => _ + .DependsOn( + API_All, + BFF_All, + Identity_All + ); + Target Frontend_All => _ => _ .DependsOn( Frontend_Clean, @@ -142,9 +156,7 @@ protected override void OnBuildInitialized() Target All => _ => _ .DependsOn( - API_All, - BFF_All, - Identity_All, + Backend_All, Frontend_All, Restore_Tools ); diff --git a/.build/Build.Init.cs b/.build/Build.Init.cs index 58ef028..dbab9b4 100644 --- a/.build/Build.Init.cs +++ b/.build/Build.Init.cs @@ -21,6 +21,7 @@ partial class Build : NukeBuild AbsolutePath Scheduler_DB_Cfg => RootDirectory / "Docker" / "PostgresSql" / "SchedulerDB.sh"; string postgres_db_name = "trouble_db"; + //--------------- // Build process //--------------- diff --git a/.build/Build.Sonar.cs b/.build/Build.Sonar.cs new file mode 100644 index 0000000..5d3cabc --- /dev/null +++ b/.build/Build.Sonar.cs @@ -0,0 +1,80 @@ + +using Nuke.Common; +using Nuke.Common.Tooling; +using Nuke.Common.Tools.DotNet; +using Nuke.Common.Tools.SonarScanner; +using static Nuke.Common.Tools.SonarScanner.SonarScannerTasks; + +partial class Build : NukeBuild +{ + + //--------------- + // Enviroment + //--------------- + + [Parameter] readonly string SonarToken; + const string SonarProjectKey = "trouble-training"; + string Github_Organization_Name = "damikun"; + + [Parameter("Sonar server")] + readonly string SonarServer = IsLocalBuild ? "https://sonarcloud.io" : "https://sonarcloud.io"; // change url for local server + + + string[] sonar_path_exclude = new string[]{ + "**/Generated/**/*", + "**/*.generated.cs", + "**/*.js", + "**/*.ts", + "**/*.tsx", + "**/*.html", + "**/*.css", + "**/*.cmd", + "**/*.ps1", + "**/*.json", + "**/*.sh", + "**/*.md", + // "**/bin/*", + // "**/obj/*", + "**/Tests/*", + "**/Test/*", + "**/node_modules/**/*" + }; + + //--------------- + // Build process + //--------------- + + Target SonarBegin => _ => _ + .Before( + API_Compile, + BFF_Compile, + Identity_Compile + ) + .DependsOn(Restore_Tools) + .Requires(() => SonarToken) + .Unlisted() + .Executes(() => + { + SonarScannerBegin(s => s + .SetLogin(SonarToken) + .SetProjectKey(SonarProjectKey) + .SetOrganization(Github_Organization_Name) + .SetServer(SonarServer) + .AddSourceExclusions(sonar_path_exclude) + .SetOpenCoverPaths(ArtifactsDirectory / "coverage.xml") + .SetFramework("net5.0")); + }); + + Target Sonar => _ => _ + .DependsOn(SonarBegin, Backend_All) + .Requires(() => SonarToken) + .AssuredAfterFailure() + .Executes(() => + { + SonarScannerEnd(s => s + .SetLogin(SonarToken) + .SetFramework("net5.0") + .SetProcessWorkingDirectory(RootDirectory)); + }); + +} \ No newline at end of file diff --git a/.build/_build.csproj b/.build/_build.csproj index 6f75fb0..08c6c94 100644 --- a/.build/_build.csproj +++ b/.build/_build.csproj @@ -15,6 +15,8 @@ + + diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 9bb94e9..852c74a 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -25,6 +25,12 @@ "commands": [ "dotnet-format" ] + }, + "dotnet-sonarscanner": { + "version": "5.3.2", + "commands": [ + "dotnet-sonarscanner" + ] } } } \ No newline at end of file diff --git a/.github/workflows/sonar.yml b/.github/workflows/sonar.yml new file mode 100644 index 0000000..08de1b9 --- /dev/null +++ b/.github/workflows/sonar.yml @@ -0,0 +1,56 @@ +# ------------------------------------------------------------------------------ +# +# +# This code was generated. +# +# - To turn off auto-generation set: +# +# [GitHubActions (AutoGenerate = false)] +# +# - To trigger manual generation invoke: +# +# nuke --generate-configuration GitHubActions_Sonar --host GitHubActions +# +# +# ------------------------------------------------------------------------------ + +name: Sonar + +on: [pull_request] + +############################################################# +# The only prerequisite for running SonarQube is to have Java +# (Oracle JRE 11 or OpenJDK 11) installed on your machine. +############################################################# +# Java version info +# 50 = Java 6 +# 51 = Java 7 +# 52 = Java 8 +# 53 = Java 9 +# 54 = Java 10 +# 55 = Java 11 +# 56 = Java 12 +# 57 = Java 13 + +# The V55 = Java 11 prevents ("EnvironmentInformation has been compiled by a more recent version of the Java Runtime") + +jobs: + windows-latest: + name: windows-latest + runs-on: windows-latest + steps: + - uses: actions/setup-java@v1 + with: + java-version: "11" + - uses: actions/checkout@v1 + - name: Cache .nuke/temp, ~/.nuget/packages + uses: actions/cache@v2 + with: + path: | + .nuke/temp + ~/.nuget/packages + key: ${{ runner.os }}-${{ hashFiles('**/global.json', '**/*.csproj') }} + - name: Run './build.cmd Sonar' + run: ./build.cmd Sonar + env: + SonarToken: ${{ secrets.SONAR_TOKEN }} diff --git a/.nuke/build.schema.json b/.nuke/build.schema.json index 5927607..74f8ac9 100644 --- a/.nuke/build.schema.json +++ b/.nuke/build.schema.json @@ -86,6 +86,7 @@ "API_Restore", "API_Test", "API_UnitTest", + "Backend_All", "BFF_All", "BFF_Clean", "BFF_Compile", @@ -117,6 +118,8 @@ "SetupCertificates_CI", "SetupCertificates_Local", "SetupDevCertificates", + "Sonar", + "SonarBegin", "Start_API_Server", "Start_BFF_Server", "Start_Identity_Server", @@ -132,6 +135,13 @@ "type": "string", "description": "Path to a solution file that is automatically loaded" }, + "SonarServer": { + "type": "string", + "description": "Sonar server" + }, + "SonarToken": { + "type": "string" + }, "Target": { "type": "array", "description": "List of targets to be invoked. Default is '{default_target}'", @@ -150,6 +160,7 @@ "API_Restore", "API_Test", "API_UnitTest", + "Backend_All", "BFF_All", "BFF_Clean", "BFF_Compile", @@ -181,6 +192,8 @@ "SetupCertificates_CI", "SetupCertificates_Local", "SetupDevCertificates", + "Sonar", + "SonarBegin", "Start_API_Server", "Start_BFF_Server", "Start_Identity_Server", diff --git a/.vscode/settings.json b/.vscode/settings.json index 42cd03f..3ecf521 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,5 +5,9 @@ "editor.semanticHighlighting.enabled": true, "csharp.semanticHighlighting.enabled": true, "omnisharp.enableEditorConfigSupport": true, - "omnisharp.useGlobalMono": "always" + "omnisharp.useGlobalMono": "always", + "search.exclude": { + "**/node_modules": true, + "**/tmp": true + } } \ No newline at end of file diff --git a/Src/APIServer/API/Hangfire.db b/Src/APIServer/API/Hangfire.db index 13fa0ec..db8a974 100644 Binary files a/Src/APIServer/API/Hangfire.db and b/Src/APIServer/API/Hangfire.db differ diff --git a/Src/APIServer/Persistence/api.db b/Src/APIServer/Persistence/api.db index 0066354..a2808e2 100644 Binary files a/Src/APIServer/Persistence/api.db and b/Src/APIServer/Persistence/api.db differ diff --git a/Src/IdentityServer/Persistence/identity.db b/Src/IdentityServer/Persistence/identity.db index 4686662..6100f79 100644 Binary files a/Src/IdentityServer/Persistence/identity.db and b/Src/IdentityServer/Persistence/identity.db differ