forked from iftikhar-ahmad-dar/BenchmarkDotNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
executable file
·294 lines (262 loc) · 7.95 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
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
#addin "Cake.FileHelpers"
// ARGUMENTS
var target = Argument("Target", "Default");
var configuration = Argument("Configuration", "Release");
var skipTests = Argument("SkipTests", false);
// GLOBAL VARIABLES
var toolsDirectory = "./tools/";
var docfxExe = toolsDirectory + "docfx/docfx.exe";
var docfxVersion = "2.57.2";
var changelogDir = "./docs/changelog/";
var changelogGenDir = "./docs/_changelog/";
var bdnAllVersions = new string[] {
"v0.7.0",
"v0.7.1",
"v0.7.2",
"v0.7.3",
"v0.7.4",
"v0.7.5",
"v0.7.6",
"v0.7.7",
"v0.7.8",
"v0.8.0",
"v0.8.1",
"v0.8.2",
"v0.9.0",
"v0.9.1",
"v0.9.2",
"v0.9.3",
"v0.9.4",
"v0.9.5",
"v0.9.6",
"v0.9.7",
"v0.9.8",
"v0.9.9",
"v0.10.0",
"v0.10.1",
"v0.10.2",
"v0.10.3",
"v0.10.4",
"v0.10.5",
"v0.10.6",
"v0.10.7",
"v0.10.8",
"v0.10.9",
"v0.10.10",
"v0.10.11",
"v0.10.12",
"v0.10.13",
"v0.10.14",
"v0.11.0",
"v0.11.1",
"v0.11.2",
"v0.11.3",
"v0.11.4",
"v0.11.5",
"v0.12.0",
"v0.12.1",
"v0.13.0"
};
var bdnNextVersion = "v0.13.1";
var bdnFirstCommit = "6eda98ab1e83a0d185d09ff8b24c795711af8db1";
var artifactsDirectory = Directory("./artifacts");
var solutionFile = "./BenchmarkDotNet.sln";
var integrationTestsProjectPath = "./tests/BenchmarkDotNet.IntegrationTests/BenchmarkDotNet.IntegrationTests.csproj";
var isRunningOnWindows = IsRunningOnWindows();
var IsOnAppVeyorAndNotPR = AppVeyor.IsRunningOnAppVeyor && !AppVeyor.Environment.PullRequest.IsPullRequest;
var msBuildSettings = new DotNetCoreMSBuildSettings
{
MaxCpuCount = 1
};
Setup(_ =>
{
if(!isRunningOnWindows)
{
StartProcess("mono", new ProcessSettings { Arguments = "--version" });
var frameworkPathOverride = new FilePath(typeof(object).Assembly.Location).GetDirectory().FullPath;
// setup correct version
frameworkPathOverride = System.IO.Path.Combine(System.IO.Directory.GetParent(frameworkPathOverride).FullName, "4.6-api/");
Information("Build will use FrameworkPathOverride={0} since not building on Windows.", frameworkPathOverride);
msBuildSettings.WithProperty("FrameworkPathOverride", frameworkPathOverride);
}
msBuildSettings.WithProperty("UseSharedCompilation", "false");
});
Task("Clean")
.Does(() =>
{
CleanDirectory(artifactsDirectory);
});
Task("Restore")
.IsDependentOn("Clean")
.Does(() =>
{
DotNetCoreRestore(solutionFile);
});
Task("Build")
.IsDependentOn("Restore")
.Does(() =>
{
var path = MakeAbsolute(new DirectoryPath(solutionFile));
DotNetCoreBuild(path.FullPath, new DotNetCoreBuildSettings
{
Configuration = configuration,
NoRestore = true,
DiagnosticOutput = true,
MSBuildSettings = msBuildSettings,
Verbosity = DotNetCoreVerbosity.Minimal
});
});
Task("FastTests")
.IsDependentOn("Build")
.WithCriteria(!skipTests)
.Does(() =>
{
string[] targetVersions = IsRunningOnWindows() ?
new []{"net461", "net5.0"}
:
new []{"net5.0"};
foreach(var version in targetVersions)
{
DotNetCoreTest("./tests/BenchmarkDotNet.Tests/BenchmarkDotNet.Tests.csproj", GetTestSettingsParameters(version));
}
});
Task("SlowTestsNet461")
.IsDependentOn("Build")
.WithCriteria(!skipTests && isRunningOnWindows)
.Does(() =>
{
DotNetCoreTest(integrationTestsProjectPath, GetTestSettingsParameters("net461"));
});
Task("SlowTestsNetCore2")
.IsDependentOn("Build")
.WithCriteria(!skipTests)
.Does(() =>
{
DotNetCoreTest(integrationTestsProjectPath, GetTestSettingsParameters("net5.0"));
});
Task("Pack")
.IsDependentOn("Build")
.WithCriteria((IsOnAppVeyorAndNotPR || string.Equals(target, "pack", StringComparison.OrdinalIgnoreCase)) && isRunningOnWindows)
.Does(() =>
{
var settings = new DotNetCorePackSettings
{
Configuration = configuration,
OutputDirectory = artifactsDirectory,
ArgumentCustomization = args=>args.Append("--include-symbols").Append("-p:SymbolPackageFormat=snupkg")
};
var projects = GetFiles("./src/**/*.csproj");
foreach(var project in projects.Where(p => !p.FullPath.Contains("Disassembler")))
{
DotNetCorePack(project.FullPath, settings);
}
});
Task("DocFX_Install")
.Does(() => {
if (!FileExists(docfxExe)) {
DownloadFile(
"https://github.com/dotnet/docfx/releases/download/v" + docfxVersion + "/docfx.zip",
toolsDirectory + "docfx.zip");
Unzip(toolsDirectory + "docfx.zip", toolsDirectory + "docfx");
}
});
Task("DocFX_Changelog_Download")
.IsDependentOn("DocFX_Install")
.Does(() => {
DocfxChangelogDownload(bdnAllVersions.First(), bdnFirstCommit);
for (int i = 1; i < bdnAllVersions.Length; i++)
DocfxChangelogDownload(bdnAllVersions[i], bdnAllVersions[i - 1]);
DocfxChangelogDownload(bdnNextVersion, bdnAllVersions.Last(), "HEAD");
});
Task("DocFX_Changelog_Generate")
.IsDependentOn("DocFX_Install")
.Does(() => {
foreach (var version in bdnAllVersions)
DocfxChangelogGenerate(version);
DocfxChangelogGenerate(bdnNextVersion);
CopyFile(changelogGenDir + "index.md", changelogDir + "index.md");
CopyFile(changelogGenDir + "full.md", changelogDir + "full.md");
});
Task("DocFX_Build")
.IsDependentOn("DocFX_Install")
.IsDependentOn("DocFX_Changelog_Generate")
.Does(() => {
RunDocfx("docs/docfx.json");
});
Task("DocFX_Serve")
.IsDependentOn("DocFX_Install")
.IsDependentOn("DocFX_Changelog_Generate")
.Does(() => {
RunDocfx("docs/docfx.json --serve");
});
Task("Default")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.IsDependentOn("Build")
.IsDependentOn("FastTests")
.IsDependentOn("SlowTestsNetCore2")
.IsDependentOn("SlowTestsNet461")
.IsDependentOn("Pack");
RunTarget(target);
// HELPERS
private DotNetCoreTestSettings GetTestSettingsParameters(string tfm)
{
return new DotNetCoreTestSettings
{
Configuration = configuration,
Framework = tfm,
NoBuild = true,
NoRestore = true,
Logger = "trx"
};
}
private void RunDocfx(string args)
{
if (!isRunningOnWindows)
StartProcess("mono", new ProcessSettings { Arguments = docfxExe + " " + args });
else
StartProcess(docfxExe, new ProcessSettings { Arguments = args });
}
private void DocfxChangelogGenerate(string version)
{
Verbose("DocfxChangelogGenerate: " + version);
var header = changelogGenDir + "header/" + version + ".md";
var footer = changelogGenDir + "footer/" + version + ".md";
var details = changelogGenDir + "details/" + version + ".md";
var release = changelogDir + version + ".md";
var content = new StringBuilder();
content.AppendLine("---");
content.AppendLine("uid: changelog." + version);
content.AppendLine("---");
content.AppendLine("");
content.AppendLine("# BenchmarkDotNet " + version);
content.AppendLine("");
content.AppendLine("");
if (FileExists(header)) {
content.AppendLine(FileReadText(header));
content.AppendLine("");
content.AppendLine("");
}
if (FileExists(details)) {
content.AppendLine(FileReadText(details));
content.AppendLine("");
content.AppendLine("");
}
if (FileExists(footer)) {
content.AppendLine("## Additional details");
content.AppendLine("");
content.AppendLine(FileReadText(footer));
}
FileWriteText(release, content.ToString());
}
private void DocfxChangelogDownload(string version, string versionPrevious, string lastCommit = "")
{
Verbose("DocfxChangelogDownload: " + version);
// Required environment variables: GITHIB_PRODUCT, GITHUB_TOKEN
StartProcess("dotnet", new ProcessSettings
{
WorkingDirectory = changelogGenDir + "ChangeLogBuilder",
Arguments = "run -- " + version + " " + versionPrevious + " " + lastCommit
});
CopyFile(changelogGenDir + "ChangeLogBuilder/" + version + ".md", changelogGenDir + "details/" + version + ".md");
}