-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.cake
203 lines (177 loc) · 5.93 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
#load "build/helpers.cake"
#tool "nuget:?package=GitVersion.CommandLine"
#tool nuget:?package=docfx.console&version=2.18.5
#addin nuget:?package=Cake.DocFx&version=0.5.0
#addin nuget:?package=Cake.Docker&version=0.8.2
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var tag = Argument("tag", "latest");
var fallbackVersion = Argument<string>("force-version", EnvironmentVariable("FALLBACK_VERSION") ?? "0.2.0");
///////////////////////////////////////////////////////////////////////////////
// VERSIONING
///////////////////////////////////////////////////////////////////////////////
var packageVersion = string.Empty;
#load "build/version.cake"
///////////////////////////////////////////////////////////////////////////////
// GLOBAL VARIABLES
///////////////////////////////////////////////////////////////////////////////
var solution = File("./src/Downlink.sln");
var projects = GetProjects(solution, configuration);
var artifacts = "./dist/";
var testResultsPath = MakeAbsolute(Directory(artifacts + "./test-results"));
var frameworks = new List<string> { "netcoreapp2.0" };
var runtimes = new List<string> { "win10-x64", "osx.10.12-x64", "ubuntu.16.04-x64", "ubuntu.14.04-x64", "centos.7-x64", "debian.8-x64", "rhel.7-x64" };
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup(ctx =>
{
// Executed BEFORE the first task.
Information("Running tasks...");
CreateDirectory(artifacts);
Verbose("Building for " + string.Join(", ", frameworks));
packageVersion = BuildVersion(fallbackVersion);
if (FileExists("./build/.dotnet/dotnet.exe")) {
Information("Using local install of `dotnet` SDK!");
Context.Tools.RegisterFile("./build/.dotnet/dotnet.exe");
}
});
Teardown(ctx =>
{
// Executed AFTER the last task.
Information("Finished running tasks.");
});
///////////////////////////////////////////////////////////////////////////////
// TASKS
///////////////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
// Clean solution directories.
foreach(var path in projects.AllProjectPaths)
{
Information("Cleaning {0}", path);
CleanDirectories(path + "/**/bin/" + configuration);
CleanDirectories(path + "/**/obj/" + configuration);
}
Information("Cleaning common files...");
CleanDirectory(artifacts);
});
Task("Restore")
.Does(() =>
{
// Restore all NuGet packages.
Information("Restoring solution...");
DotNetCoreRestore(solution);
});
Task("Build")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.Does(() =>
{
Information("Building solution...");
foreach (var project in projects.SourceProjectPaths) {
Information($"Building {project.GetDirectoryName()} for {configuration}");
var settings = new DotNetCoreBuildSettings {
Configuration = configuration,
ArgumentCustomization = args => args.Append("/p:NoWarn=NU1701"),
};
DotNetCoreBuild(project.FullPath, settings);
}
});
Task("Run-Unit-Tests")
.IsDependentOn("Build")
.Does(() =>
{
CreateDirectory(testResultsPath);
if (projects.TestProjects.Any()) {
var settings = new DotNetCoreTestSettings {
Configuration = configuration
};
foreach(var project in projects.TestProjects) {
DotNetCoreTest(project.Path.FullPath, settings);
}
}
});
Task("Generate-Docs")
.Does(() =>
{
Information("Building metadata...");
DocFxMetadata("./docfx/docfx.json");
Information("Building docs...");
DocFxBuild("./docfx/docfx.json");
Information("Packaging built docs...");
Zip("./docfx/_site/", artifacts + "/docfx.zip");
})
.OnError(ex =>
{
Warning(ex.Message);
Warning("Error generating documentation!");
});
Task("Post-Build")
.IsDependentOn("Build")
.IsDependentOn("Run-Unit-Tests")
.IsDependentOn("Generate-Docs")
.Does(() =>
{
CreateDirectory(artifacts + "build");
foreach (var project in projects.SourceProjects) {
CreateDirectory(artifacts + "build/" + project.Name);
foreach (var framework in frameworks) {
var frameworkDir = $"{artifacts}build/{project.Name}/{framework}";
CreateDirectory(frameworkDir);
var files = GetFiles($"{project.Path.GetDirectory()}/bin/{configuration}/{framework}/*.*");
CopyFiles(files, frameworkDir);
}
}
});
Task("Publish")
.IsDependentOn("Post-Build")
.Does(() =>
{
CreateDirectory(artifacts + "publish/");
var project = projects.SourceProjects.First(p => p.Name == "Downlink.Host");
foreach (var framework in frameworks) {
var projectDir = $"{artifacts}publish/Downlink"; // BAD
CreateDirectory(projectDir);
Information("Publishing {0} to {1}", project.Name, projectDir);
var settings = new DotNetCorePublishSettings {
Configuration = configuration,
OutputDirectory = projectDir
};
DotNetCorePublish(project.Path.FullPath, settings);
}
});
Task("Docker-Build")
.IsDependentOn("Publish")
.Does(() =>
{
CopyFileToDirectory("./build/Dockerfile", artifacts);
CopyFileToDirectory("./build/appsettings.json", artifacts);
var dSettings = new DockerImageBuildSettings {
Tag = new[] {
$"agc93/downlink:{tag}",
$"agc93/downlink:{packageVersion}"
}
};
DockerBuild(dSettings, artifacts);
DeleteFile(artifacts + "Dockerfile");
DeleteFile(artifacts + "appsettings.json");
});
#load "build/nuget.cake"
Task("Default")
.IsDependentOn("Publish")
.IsDependentOn("NuGet");
Task("CI-Build")
.IsDependentOn("Publish")
.IsDependentOn("NuGet")
.IsDependentOn("Generate-Docs")
.Does(() =>
{
CopyFileToDirectory("./build/Dockerfile", artifacts);
CopyFileToDirectory("./build/appsettings.json", artifacts);
});
RunTarget(target);