-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.cake
271 lines (235 loc) · 7.94 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
#tool "GitReleaseNotes";
#tool "GitVersion.CommandLine";
#tool "NUnit.ConsoleRunner";
#addin "Cake.FileHelpers"
public void PrintUsage()
{
Console.WriteLine($"Usage: build.cake [options]{Environment.NewLine}" +
$"Options:{Environment.NewLine}" +
$"\t-target\t\t\t\tCake build entry point.\tDefaults to 'BuildOnCommit'.{Environment.NewLine}" +
$"\t-framework\t\t\tFramework to target. Defaults to 'all' if not specified.{Environment.NewLine}" +
$"\t-configuration\t\t\tBuild configuration [Debug|Release]. Defaults to 'Release'.{Environment.NewLine}" +
$"\t-verbosity\t\t\tVerbosity [Quiet|Minimal|Normal|Verbose|Diagnostic]. Defaults to 'Minimal'.{Environment.NewLine}" +
$"\t-branch\t\tThe branch being built. Required{Environment.NewLine}");
}
private Verbosity ParseVerbosity(string verbosity)
{
Verbosity typedVerbosity;
if(Enum.TryParse<Verbosity>(verbosity, out typedVerbosity)){
return typedVerbosity;
}
return Verbosity.Minimal;
}
private DotNetCoreVerbosity MapVerbosityToDotNetCoreVerbosity(Verbosity verbosity)
{
switch(verbosity)
{
case Verbosity.Diagnostic:
return DotNetCoreVerbosity.Diagnostic;
case Verbosity.Verbose:
return DotNetCoreVerbosity.Detailed;
case Verbosity.Quiet:
return DotNetCoreVerbosity.Quiet;
case Verbosity.Minimal:
return DotNetCoreVerbosity.Minimal;
default:
return DotNetCoreVerbosity.Normal;
}
}
private NuGetVerbosity MapVerbosityToNuGetVerbosity(Verbosity verbosity)
{
switch(verbosity)
{
case Verbosity.Diagnostic:
case Verbosity.Verbose:
return NuGetVerbosity.Detailed;
case Verbosity.Quiet:
return NuGetVerbosity.Quiet;
default:
return NuGetVerbosity.Normal;
}
}
private bool IsFrameworkSpecified => !string.IsNullOrEmpty(framework) && framework != "all";
//////////////////////////////////////////////////////////////////////
// ARGUMENTS
//////////////////////////////////////////////////////////////////////
var target = Argument("target", "BuildOnCommit");
var framework = Argument("framework", "all");
var configuration = Argument("configuration", "Release");
var verbosity = ParseVerbosity(Argument("verbosity", "Minimal"));
//////////////////////////////////////////////////////////////////////
// PREPARATION
//////////////////////////////////////////////////////////////////////
var solution = "./CircularStack.sln";
var outputDir = "./artifacts";
EnsureDirectoryExists(Directory(outputDir).Path);
GitVersion gitVersion = null;
//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
var settings = new DotNetCoreCleanSettings
{
Configuration = configuration,
Verbosity = MapVerbosityToDotNetCoreVerbosity(verbosity)
};
DotNetCoreClean(solution,settings);
});
Task("Restore")
.Does(() =>
{
NuGetRestore(solution, new NuGetRestoreSettings
{
Verbosity = MapVerbosityToNuGetVerbosity(verbosity)
});
var settings = new DotNetCoreRestoreSettings
{
PackagesDirectory = "./packages",
Verbosity = MapVerbosityToDotNetCoreVerbosity(verbosity)
};
DotNetCoreRestore(solution,settings);
});
Task("Version")
.Does(() => {
GitVersion(new GitVersionSettings{
UpdateAssemblyInfo = true,
OutputType = GitVersionOutput.BuildServer
});
gitVersion = GitVersion(new GitVersionSettings{ OutputType = GitVersionOutput.Json });
Information($"AssemblySemVer: {gitVersion.AssemblySemVer}{Environment.NewLine}"+
$"SemVer: {gitVersion.AssemblySemVer}{Environment.NewLine}" +
$"FullSemVer: {gitVersion.FullSemVer}{Environment.NewLine}" +
$"MajorMinorPatch: {gitVersion.MajorMinorPatch}{Environment.NewLine}" +
$"NuGetVersionV2: {gitVersion.NuGetVersionV2}{Environment.NewLine}" +
$"NuGetVersion: {gitVersion.NuGetVersion}{Environment.NewLine}" +
$"BranchName: {gitVersion.BranchName}{Environment.NewLine}" +
$"Sha: {gitVersion.Sha}{Environment.NewLine}" +
$"Pre-Release Label: {gitVersion.PreReleaseLabel}{Environment.NewLine}" +
$"Pre-Release Number: {gitVersion.PreReleaseNumber}{Environment.NewLine}" +
$"Pre-Release Tag: {gitVersion.PreReleaseTag}{Environment.NewLine}" +
$"Pre-Release Tag with dash: {gitVersion.PreReleaseTagWithDash}{Environment.NewLine}" +
$"Build MetaData: {gitVersion.BuildMetaData}{Environment.NewLine}" +
$"Build MetaData Padded: {gitVersion.BuildMetaDataPadded}{Environment.NewLine}" +
$"Full Build MetaData: {gitVersion.FullBuildMetaData}{Environment.NewLine}");
if (gitVersion.BranchName == "master")
{
gitVersion.NuGetVersionV2 = $"{gitVersion.MajorMinorPatch}-unstable";
}
Information($"Versioning with '{gitVersion.NuGetVersionV2}'");
var projectFiles = GetFiles("./src/*.csproj");
foreach(var file in projectFiles)
{
ReplaceTextInFiles(file.ToString(), "<VersionPrefix>1.0.0</VersionPrefix>", $"<VersionPrefix>{gitVersion.NuGetVersionV2}</VersionPrefix>");
ReplaceTextInFiles(file.ToString(), "<VersionSuffix>local</VersionSuffix>", "");
}
});
Task("Build")
.Does(() =>
{
var settings = new DotNetCoreBuildSettings
{
Configuration = configuration,
Verbosity = MapVerbosityToDotNetCoreVerbosity(verbosity),
NoRestore = true
};
if (IsFrameworkSpecified)
{
settings.Framework = framework;
}
DotNetCoreBuild(solution,settings);
});
Task("Test")
.Does(() =>
{
var settings = new DotNetCoreTestSettings
{
Configuration = configuration,
Verbosity = MapVerbosityToDotNetCoreVerbosity(verbosity),
NoRestore = true,
NoBuild = true,
Logger = "trx"
};
if (IsFrameworkSpecified)
{
settings.Framework = framework;
}
DotNetCoreTest("./tests", settings);
});
Task("Package")
.Does(() =>
{
var settings = new DotNetCorePackSettings
{
OutputDirectory = outputDir,
Verbosity = MapVerbosityToDotNetCoreVerbosity(verbosity),
Configuration = configuration,
NoBuild = true
};
var projectFiles = GetFiles("./src/*.csproj");
foreach(var file in projectFiles)
{
DotNetCorePack(file.ToString(), settings);
}
});
Task("Generate-Release-Notes")
.Does(() =>
{
var releaseNotesExitCode = StartProcess(@"tools\GitReleaseNotes.0.7.0\tools\gitreleasenotes.exe",
new ProcessSettings { Arguments = ". /o artifacts/releasenotes.md" }
);
if (string.IsNullOrEmpty(System.IO.File.ReadAllText("./artifacts/releasenotes.md")))
{
System.IO.File.WriteAllText("./artifacts/releasenotes.md", "No issues closed since last release");
}
if (releaseNotesExitCode != 0)
{
throw new Exception("Failed to generate release notes");
}
});
Task("Upload-Artifacts")
.WithCriteria(AppVeyor.IsRunningOnAppVeyor)
.Does(() =>
{
foreach (var file in GetFiles(outputDir + "/*"))
AppVeyor.UploadArtifact(file.FullPath);
foreach (var file in GetFiles("./tests/TestResults/*"))
AppVeyor.UploadTestResults(file.FullPath, AppVeyorTestResultsType.MSTest);
});
//////////////////////////////////////////////////////////////////////
// TASK TARGETS
//////////////////////////////////////////////////////////////////////
Task("BuildOnCommit")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.IsDependentOn("Build")
.IsDependentOn("Test")
.OnError(exception =>
{
PrintUsage();
});
Task("FullBuild")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.IsDependentOn("Version")
.IsDependentOn("Build")
.IsDependentOn("Test")
.IsDependentOn("Package")
.IsDependentOn("Generate-Release-Notes")
.IsDependentOn("Upload-Artifacts")
.OnError(exception =>
{
PrintUsage();
});
//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////
if (target=="Help")
{
PrintUsage();
}
else
{
RunTarget(target);
}