forked from ChilliCream/graphql-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Build.Sonar.cs
125 lines (109 loc) · 5.1 KB
/
Build.Sonar.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using Nuke.Common;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.SonarScanner;
using static System.IO.Path;
using static Nuke.Common.Tools.DotNet.DotNetTasks;
using static Nuke.Common.Tools.SonarScanner.SonarScannerTasks;
using static Helpers;
partial class Build
{
[Parameter] readonly string SonarToken;
[Parameter] readonly string SonarServer = "https://sonarcloud.io";
Target SonarPr => _ => _
.Requires(() => GitHubRepository != null)
.Requires(() => GitHubHeadRef != null)
.Requires(() => GitHubBaseRef != null)
.Requires(() => GitHubPRNumber != null)
.Executes(() =>
{
Logger.Info($"GitHubRepository: {GitHubRepository}");
Logger.Info($"GitHubHeadRef: {GitHubHeadRef}");
Logger.Info($"GitHubBaseRef: {GitHubBaseRef}");
Logger.Info($"GitHubPRNumber: {GitHubPRNumber}");
TryDelete(SonarSolutionFile);
DotNetBuildSonarSolution(AllSolutionFile);
DotNetBuildSonarSolution(SonarSolutionFile, include: IsRelevantForSonar);
DotNetRestore(c => c
.SetProjectFile(SonarSolutionFile)
.SetProcessWorkingDirectory(RootDirectory));
SonarScannerBegin(SonarBeginPrSettings);
DotNetBuild(SonarBuildAll);
try
{
DotNetTest(
c => CoverNoBuildSettingsOnlyNet60(c, CoverProjects),
degreeOfParallelism: DegreeOfParallelism,
completeOnFailure: true);
}
catch { }
SonarScannerEnd(SonarEndSettings);
});
Target Sonar => _ => _
.Executes(() =>
{
TryDelete(SonarSolutionFile);
DotNetBuildSonarSolution(AllSolutionFile);
DotNetBuildSonarSolution(SonarSolutionFile, include: IsRelevantForSonar);
DotNetRestore(c => c
.SetProjectFile(SonarSolutionFile)
.SetProcessWorkingDirectory(RootDirectory));
Logger.Info("Creating Sonar analysis for version: {0} ...", GitVersion.SemVer);
SonarScannerBegin(SonarBeginFullSettings);
DotNetBuild(SonarBuildAll);
try
{
DotNetTest(
c => CoverNoBuildSettingsOnlyNet60(c, CoverProjects),
degreeOfParallelism: DegreeOfParallelism,
completeOnFailure: true);
}
catch { }
SonarScannerEnd(SonarEndSettings);
});
SonarScannerBeginSettings SonarBeginPrSettings(SonarScannerBeginSettings settings) =>
SonarBeginBaseSettings(settings)
.SetProcessArgumentConfigurator(t => t
.Add("/o:{0}", "chillicream")
.Add("/d:sonar.pullrequest.provider={0}", "github")
.Add("/d:sonar.pullrequest.github.repository={0}", GitHubRepository)
.Add("/d:sonar.pullrequest.key={0}", GitHubPRNumber)
.Add("/d:sonar.pullrequest.branch={0}", GitHubHeadRef)
.Add("/d:sonar.pullrequest.base={0}", GitHubBaseRef)
.Add("/d:sonar.cs.roslyn.ignoreIssues={0}", "true"))
.SetFramework(Net50);
SonarScannerBeginSettings SonarBeginFullSettings(SonarScannerBeginSettings settings) =>
SonarBeginBaseSettings(settings)
.SetVersion(GitVersion.SemVer)
.SetFramework(Net50);
SonarScannerBeginSettings SonarBeginBaseSettings(SonarScannerBeginSettings settings) =>
SonarBaseSettings(settings)
.SetProjectKey("HotChocolate")
.SetName("HotChocolate")
.SetServer(SonarServer)
.SetLogin(SonarToken)
.AddOpenCoverPaths(TestResultDirectory / "*.xml")
.SetVSTestReports(TestResultDirectory / "*.trx")
.AddSourceExclusions("**/Generated/**/*.*,**/*.Designer.cs,**/*.generated.cs,**/*.js,**/*.html,**/*.css,**/Sample/**/*.*,**/Samples.*/**/*.*,**/*Tools.*/**/*.*,**/Program.Dev.cs, **/Program.cs,**/*.ts,**/*.tsx,**/*EventSource.cs,**/*EventSources.cs,**/*.Samples.cs,**/*Tests.*/**/*.*,**/*Test.*/**/*.*")
.SetProcessArgumentConfigurator(t => t
.Add("/o:{0}", "chillicream")
.Add("/d:sonar.cs.roslyn.ignoreIssues={0}", "true"));
SonarScannerBeginSettings SonarBaseSettings(SonarScannerBeginSettings settings) =>
settings
.SetLogin(SonarToken)
.SetProcessWorkingDirectory(RootDirectory);
SonarScannerEndSettings SonarEndSettings(SonarScannerEndSettings settings) =>
settings
.SetLogin(SonarToken)
.SetProcessWorkingDirectory(RootDirectory)
.SetFramework(Net50);
DotNetBuildSettings SonarBuildAll(DotNetBuildSettings settings) =>
settings
.SetProjectFile(SonarSolutionFile)
.SetNoRestore(true)
.SetConfiguration(Debug)
.SetProcessWorkingDirectory(RootDirectory)
.SetFramework(Net60);
bool IsRelevantForSonar(string fileName)
=> !ExcludedCover.Contains(GetFileNameWithoutExtension(fileName));
}