Skip to content

Commit

Permalink
(build) Enabled analysing with sonarcloud
Browse files Browse the repository at this point in the history
  • Loading branch information
AdmiringWorm committed Mar 20, 2020
1 parent a17bb44 commit 19a4664
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .build/sonarcloud.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const string SonarQubeTool = "#tool nuget:?package=MSBuild.SonarQube.Runner.Tool&version=4.6.0";
const string SonarQubeAddin = "#addin nuget:?package=Cake.Sonar&version=1.1.22";

Task("SonarCloud-Begin")
.IsDependentOn("DotNetCore-Restore")
.IsDependeeOf("DotNetCore-Build")
.WithCriteria(() => HasEnvironmentVariable("SONARCLOUD_TOKEN"), "Missing sonar cloud token environment variable")
.WithCriteria(() => HasEnvironmentVariable("SONARCLOUD_ORGANIZATION"), "Missing sonar cloud organization environment variable")
.WithCriteria(() => HasEnvironmentVariable("SONARCLOUD_PROJECT_KEY"), "Missing sonar cloud project key environment variable")
.Does(() => RequireTool(SonarQubeTool,
() =>
{
Information("Starting SonarCloud analysing");

RequireAddin(SonarQubeAddin + @"
SonarBegin(new SonarBeginSettings {
Key = EnvironmentVariable(""TEMP_PROJECT_KEY""),
Branch = EnvironmentVariable(""TEMP_BUILD_BRANCH""),
Organization = EnvironmentVariable(""TEMP_ORGANIZATION""),
Url = ""https://sonarcloud.io"",
Exclusions = ""**/*.Tests,**/GlobalSuppressions.cs"", // Global suppresions is added to prevent sonar cloud to report suppressed warnings
OpenCoverReportsPath = EnvironmentVariable(""TEMP_OPENCOVER_FILTER""),
Login = EnvironmentVariable(""TEMP_TOKEN""),
Version = EnvironmentVariable(""TEMP_VERSION""),
XUnitReportsPath = EnvironmentVariable(""TEMP_TEST_RESULTS""),
});",
new Dictionary<string, string> {
{ "TEMP_PROJECT_KEY", EnvironmentVariable("SONARCLOUD_PROJECT_KEY") },
{ "TEMP_BUILD_BRANCH", BuildParameters.BuildProvider.Repository.Branch },
{ "TEMP_ORGANIZATION", EnvironmentVariable("SONARCLOUD_ORGANIZATION") },
{ "TEMP_OPENCOVER_FILTER", BuildParameters.Paths.Files.TestCoverageOutputFilePath.ToString().Replace(".xml", "*.xml") },
{ "TEMP_TOKEN", EnvironmentVariable("SONARCLOUD_TOKEN") },
{ "TEMP_VERSION", BuildParameters.Version.SemVersion },
{ "TEMP_TEST_RESULTS", BuildParameters.Paths.Directories.TestResults.CombineWithFilePath("TestResults.xml").ToString() },
});
}));

Task("SonarCloud-End")
.IsDependentOn("Test")
.IsDependeeOf("Analyze")
.WithCriteria(() => HasEnvironmentVariable("SONARCLOUD_TOKEN"), "Missing sonar cloud token environment variable")
.WithCriteria(() => HasEnvironmentVariable("SONARCLOUD_ORGANIZATION"), "Missing sonar cloud organization environment variable")
.WithCriteria(() => HasEnvironmentVariable("SONARCLOUD_PROJECT_KEY"), "Missing sonar cloud project key environment variable")
.Does(() => RequireTool(SonarQubeTool, () => RequireAddin(SonarQubeAddin + @"
SonarEnd(new SonarEndSettings {
Login = EnvironmentVariable(""TEMP_TOKEN""),
});",
new Dictionary<string, string> {
{ "TEMP_TOKEN", EnvironmentVariable("SONARCLOUD_TOKEN") },
})
));
1 change: 1 addition & 0 deletions setup.cake
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#load "nuget:https://f.feedz.io/wormiecorp/packages/nuget/index.json?package=Cake.Recipe&version=2.0.0-alpha0036&prerelease"
#load "./.build/*.cake"

Environment.SetVariableNames();

Expand Down

0 comments on commit 19a4664

Please sign in to comment.