Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Sonar #11

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions .build/Build..cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -142,9 +156,7 @@ protected override void OnBuildInitialized()

Target All => _ => _
.DependsOn(
API_All,
BFF_All,
Identity_All,
Backend_All,
Frontend_All,
Restore_Tools
);
Expand Down
1 change: 1 addition & 0 deletions .build/Build.Init.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
//---------------
Expand Down
80 changes: 80 additions & 0 deletions .build/Build.Sonar.cs
Original file line number Diff line number Diff line change
@@ -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));
});

}
2 changes: 2 additions & 0 deletions .build/_build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<PackageReference Include="Nuke.Common" Version="5.3.0" />

<PackageDownload Include="dotnet-ef" Version="[5.0.11]" />

<PackageDownload Include="dotnet-sonarscanner" Version="[5.3.2]" />
<PackageDownload Include="GitVersion.Tool" Version="[5.8.1]" />
<PackageDownload Include="xunit.runner.console" Version="[2.4.1]" />
</ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
"commands": [
"dotnet-format"
]
},
"dotnet-sonarscanner": {
"version": "5.3.2",
"commands": [
"dotnet-sonarscanner"
]
}
}
}
56 changes: 56 additions & 0 deletions .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# ------------------------------------------------------------------------------
# <auto-generated>
#
# 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
#
# </auto-generated>
# ------------------------------------------------------------------------------

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 }}
13 changes: 13 additions & 0 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"API_Restore",
"API_Test",
"API_UnitTest",
"Backend_All",
"BFF_All",
"BFF_Clean",
"BFF_Compile",
Expand Down Expand Up @@ -117,6 +118,8 @@
"SetupCertificates_CI",
"SetupCertificates_Local",
"SetupDevCertificates",
"Sonar",
"SonarBegin",
"Start_API_Server",
"Start_BFF_Server",
"Start_Identity_Server",
Expand All @@ -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}'",
Expand All @@ -150,6 +160,7 @@
"API_Restore",
"API_Test",
"API_UnitTest",
"Backend_All",
"BFF_All",
"BFF_Clean",
"BFF_Compile",
Expand Down Expand Up @@ -181,6 +192,8 @@
"SetupCertificates_CI",
"SetupCertificates_Local",
"SetupDevCertificates",
"Sonar",
"SonarBegin",
"Start_API_Server",
"Start_BFF_Server",
"Start_Identity_Server",
Expand Down
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Binary file modified Src/APIServer/API/Hangfire.db
Binary file not shown.
Binary file modified Src/APIServer/Persistence/api.db
Binary file not shown.
Binary file modified Src/IdentityServer/Persistence/identity.db
Binary file not shown.