-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
150 lines (126 loc) · 4.76 KB
/
build.cake
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
///////////////////////////////////////////////////////////////////////////////
// Tools
///////////////////////////////////////////////////////////////////////////////
#tool nuget:?package=MSBuild.SonarQube.Runner.Tool&version=4.3.1
#tool nuget:?package=NUnit.ConsoleRunner&version=3.9.0
#tool nuget:?package=JetBrains.dotCover.CommandLineTools&version=2018.3.1
///////////////////////////////////////////////////////////////////////////////
// AddIn
///////////////////////////////////////////////////////////////////////////////
#addin nuget:?package=Cake.Sonar&version=1.1.18
#addin nuget:?package=Cake.ArgumentHelpers&version=0.3.0
///////////////////////////////////////////////////////////////////////////////
// Load custom classes
///////////////////////////////////////////////////////////////////////////////
#load "./Build/Parameters.cake"
///////////////////////////////////////////////////////////////////////////////
// Arguments
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Variables
///////////////////////////////////////////////////////////////////////////////
BuildParameters parameters = BuildParameters.GetParameters(Context);
SonarBeginSettings sonarqubeBeginSettings = null;
DotNetCoreBuildSettings coreBuildSettings = null;
DotNetCoreTestSettings coreTestsSettings = null;
DotCoverAnalyseSettings dotCoverAnalyseSettings = null;
SonarEndSettings sonarqubeEndSettings = null;
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup(context =>
{
Information("Initialize Parameters");
parameters.Initialize(context);
Information($"Initialize { nameof(DotNetCoreBuildSettings) }");
coreBuildSettings= new DotNetCoreBuildSettings()
{
Framework = "netcoreapp2.1",
Configuration = parameters.Configuration,
OutputDirectory = parameters.Paths.Directories.Bin
};
Information("Initialize NUnit3Settings");
coreTestsSettings = new DotNetCoreTestSettings ()
{
Configuration = parameters.Configuration,
Filter = "TestCategory=Unit",
NoBuild = true,
OutputDirectory = parameters.Paths.Directories.Bin
};
Information("Initialize DotCoverAnalyseSettings");
dotCoverAnalyseSettings = new DotCoverAnalyseSettings()
{
ReportType = DotCoverReportType.HTML
};
Information("Initialize SonarBeginSettings");
sonarqubeBeginSettings = new SonarBeginSettings()
{
Url = parameters.SonarqubeUrl,
Login = parameters.SonarqubeLogin,
Password = parameters.SonarqubePassword,
Key = parameters.SonarProjectKey,
Name = parameters.SonarProjectName,
Organization= parameters.SonarOrganization,
Branch = parameters.Branch,
NUnitReportsPath = parameters.Paths.Directories.ToolsReports.Combine(Directory("./UnitResultsReport.xml")).FullPath,
DotCoverReportsPath = parameters.Paths.Directories.ToolsReports.Combine(Directory("./DotCoverReport.html")).FullPath
};
Information("Initialize SonarEndSettings");
sonarqubeEndSettings = sonarqubeBeginSettings.GetEndSettings();
});
Teardown(context =>
{
});
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Task("RestorePackages")
.Does(() =>
{
NuGetRestore(parameters.Paths.Directories.Source.Combine(parameters.Solution).FullPath);
});
Task("InitializeSonar")
.Does(() =>
{
SonarBegin(sonarqubeBeginSettings);
});
Task("Build")
.Does(() =>
{
DotNetCoreBuild(parameters.Paths.Directories.Source.Combine(parameters.Solution).FullPath, coreBuildSettings);
});
Task("RunUnitTests")
.IsDependentOn("Build")
.Does(() =>
{
if (!DirectoryExists(parameters.Paths.Directories.ToolsReports.FullPath))
{
CreateDirectory(parameters.Paths.Directories.ToolsReports.FullPath);
}
DotCoverAnalyse(tool =>
{
var projectFiles = GetFiles(parameters.Paths.Directories.Source.FullPath + "/**/*.Tests.csproj");
foreach(var file in projectFiles)
{
tool.DotNetCoreTest(
file.FullPath,
coreTestsSettings);
}
},
parameters.Paths.Directories.ToolsReports.Combine("./DotCoverReport.html").FullPath,
dotCoverAnalyseSettings.WithFilter("+:BookTracker")
.WithFilter("-:BookTracker.Tests"));
});
Task("StaticAnalysis")
.IsDependentOn("InitializeSonar")
.IsDependentOn("RunUnitTests")
.Does(() =>
{
SonarEnd(sonarqubeEndSettings);
});
//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Task("Default")
.IsDependentOn("StaticAnalysis");
RunTarget(parameters.Target);