-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.cake
154 lines (127 loc) · 4.31 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
151
152
153
154
#tool "nuget:?package=NUnit.ConsoleRunner"
#tool "nuget:?package=OpenCover"
#tool "nuget:?package=ReportGenerator"
#tool "nuget:?package=Machine.Specifications.runner.console"
#tool "nuget:?package=ReportUnit"
#addin Cake.VsMetrics
// #addin "Cake.CodeAnalysisReporting"
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
var solutionPath = "";
var pathCoverage = File("./coverage.xml");
var tempDir = Directory(System.IO.Path.GetTempPath());
///////////////////////////////////////////////////////////////////////////////
// TASKS
///////////////////////////////////////////////////////////////////////////////
Task("Detect-Solution")
.Does(() => {
var files = GetFiles("./*.sln");
if (files.Count == 0) {
throw new FileNotFoundException("Not found solution");
}
var solutionName = files.First().GetFilename().FullPath;
solutionPath = System.IO.Path.Combine(".", solutionName);
Information("Solution Path: " + solutionPath);
});
Task("Clean")
.IsDependentOn("Detect-Solution")
.Does(() =>
{
MSBuild(solutionPath, settings =>
settings.SetConfiguration(configuration)
.WithTarget("Clean"));
// CreateMsBuildCodeAnalysisReport(
// "./msbuild.log",
// CodeAnalysisReport.MsBuildXmlFileLoggerByAssembly,
// "./msbuild_output.html");
});
Task("Restore-NuGet-Packages")
.IsDependentOn("Clean")
.Does(() =>
{
NuGetRestore(solutionPath);
});
Task("Build")
.IsDependentOn("Restore-NuGet-Packages")
.Does(() =>
{
MSBuild(solutionPath, settings =>
settings.SetConfiguration(configuration)
.AddFileLogger(new MSBuildFileLogger
{
Encoding = "UTF-8"
}));
});
Task("vs-metrics")
.IsDependentOn("Build")
.Does(() => {
var projects = GetFiles("./WcfService/bin/WcfService.dll");
var settings = new VsMetricsSettings()
{
SuccessFile = true,
IgnoreGeneratedCode = true
};
VsMetrics(projects, "./metrics_result.xml", settings);
});
Task("Run-Unit-Tests")
.IsDependentOn("Build")
.Does(() =>
{
var testLibraries = GetFiles("./**/bin/" + configuration + "/*.Tests.dll")
.Select(test => test.FullPath);
OpenCover(tool => {
tool.NUnit3("./WcfService.Tests/bin/" + configuration +"/WcfService.Tests.dll",
new NUnit3Settings {
ShadowCopy = false,
});
},
new FilePath(pathCoverage),
new OpenCoverSettings()
.WithFilter("+[WcfService]*")
.WithFilter("-[WcfService]WcfService.Properties.*")
.WithFilter("-[WcfService.Tests]*"));
});
Task("Run-Spec-Tests")
.IsDependentOn("Build")
.Does(() => {
var testAssemblies = GetFiles("./WcfService.Specs/bin/" + configuration + "/*.Specs.dll");
MSpec(testAssemblies);
});
Task("Reporting")
.IsDependentOn("Run-Unit-Tests")
.Does(() =>
{
var reportOutput = tempDir + Directory("report-coverage");
var unitTestOutput = tempDir + Directory("unit-test");
ReportGenerator(pathCoverage, reportOutput);
ReportUnit(Directory("./"), unitTestOutput, new ReportUnitSettings());
var rerpotIndexFile = reportOutput + File("index.htm");
var unitTestIndexFile = unitTestOutput + File("Index.html");
Action<string> startPage = url => {
if (FileExists(url))
{
System.Diagnostics.Process.Start(url);
}
else
{
Warning("Index Report not found");
}
};
startPage(rerpotIndexFile);
startPage(unitTestIndexFile);
});
//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Task("Default")
.IsDependentOn("Reporting");
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
RunTarget(target);