-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.cake
More file actions
188 lines (172 loc) · 4.24 KB
/
build.cake
File metadata and controls
188 lines (172 loc) · 4.24 KB
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#tool nuget:?package=NUnit.ConsoleRunner&version=3.12.0
#tool nuget:?package=OpenCover&version=4.7.1221
#tool "nuget:?package=ReportGenerator&version=4.8.12"
#addin nuget:?package=Cake.Coverlet&version=2.5.4
using System.IO;
const string solutionFile = "./HourShifter.sln";
const string projectFile = "./src/HourShifter/HourShifter.csproj";
const string coverageFolder = "./coverage/";
const string publishFolder = "./publish/";
const string testProjectGlob = "test/**/*.csproj";
const string DEBUG = "Debug";
const string RELEASE = "Release";
const string windowsRID = "win-x64";
string target = Argument("target", "Default");
string configuration = Argument("configuration", DEBUG);
string runtimeIdentifier = Argument("rid", windowsRID);
Setup(context =>
{
Information($"Building in: {configuration}");
});
Task("Clean")
.Does(() =>
{
Information("Cleaning in Debug and Release!");
DotNetCoreClean(solutionFile, new DotNetCoreCleanSettings{
NoLogo = true,
Configuration = DEBUG,
ArgumentCustomization = (builder) => {
if (runtimeIdentifier == windowsRID) {
return builder.Append($"/p:RID={runtimeIdentifier}");
}
else
{
return builder.Append($"-p:RID={runtimeIdentifier}");
}
}
});
DotNetCoreClean(solutionFile, new DotNetCoreCleanSettings{
NoLogo = true,
Configuration = RELEASE,
ArgumentCustomization = (builder) => {
if (runtimeIdentifier == windowsRID) {
return builder.Append($"/p:RID={runtimeIdentifier}");
}
else
{
return builder.Append($"-p:RID={runtimeIdentifier}");
}
}
});
if (DirectoryExists(publishFolder))
{
DeleteDirectory(publishFolder, new DeleteDirectorySettings{
Recursive = true,
});
}
if (DirectoryExists(coverageFolder))
{
DeleteDirectory(coverageFolder, new DeleteDirectorySettings{
Recursive = true,
});
}
});
Task("Restore")
.Does(() =>
{
DotNetCoreRestore(solutionFile, new DotNetCoreRestoreSettings{
ArgumentCustomization = (builder) => {
if (runtimeIdentifier == windowsRID) {
return builder.Append($"/p:RID={runtimeIdentifier}");
}
else
{
return builder.Append($"-p:RID={runtimeIdentifier}");
}
}
});
});
Task("Build")
.IsDependentOn("Restore")
.Does(() =>
{
DotNetCoreBuild(solutionFile, new DotNetCoreBuildSettings{
NoLogo = true,
NoRestore = true,
Configuration = configuration,
ArgumentCustomization = (builder) => {
if (runtimeIdentifier == windowsRID) {
return builder.Append($"/p:RID={runtimeIdentifier}");
}
else
{
return builder.Append($"-p:RID={runtimeIdentifier}");
}
}
});
});
Task("Test")
.IsDependentOn("Build")
.Does(() =>
{
bool success = true;
foreach (FilePath item in GetFiles(testProjectGlob))
{
try
{
DotNetCoreTest(
item.ToString(),
new DotNetCoreTestSettings {
NoBuild = true,
NoRestore = true,
NoLogo = true,
Verbosity = DotNetCoreVerbosity.Normal,
Configuration = configuration,
ArgumentCustomization = (builder) => {
if (runtimeIdentifier == windowsRID) {
return builder.Append($"/p:RID={runtimeIdentifier}");
}
else
{
return builder.Append($"-p:RID={runtimeIdentifier}");
}
}
},
new CoverletSettings {
CollectCoverage = true,
CoverletOutputDirectory = Directory(coverageFolder),
CoverletOutputFormat = CoverletOutputFormat.opencover,
CoverletOutputName = $"results",
Threshold = 100,
ThresholdType = ThresholdType.Line | ThresholdType.Branch | ThresholdType.Method
}
);
}
catch
{
success = false;
}
}
if (!success)
{
throw new Exception("Tests failed or coverage check failed. See output.");
}
});
Task("GenerateReport")
.IsDependentOn("Test")
.Does(() =>
{
ReportGenerator((FilePath)"./coverage/results.opencover.xml", "./coverage/report");
});
Task("Publish")
.IsDependentOn("Test")
.Does(() =>
{
DotNetCorePublish(projectFile, new DotNetCorePublishSettings{
NoLogo = true,
Configuration = configuration,
ArgumentCustomization = (builder) => {
if (runtimeIdentifier == windowsRID) {
return builder.Append($"/p:RID={runtimeIdentifier}");
}
else
{
return builder.Append($"-p:RID={runtimeIdentifier}");
}
},
OutputDirectory = publishFolder,
});
});
Task("Default")
.IsDependentOn("Test");
RunTarget(target);