-
Notifications
You must be signed in to change notification settings - Fork 2
/
old.build.cake
235 lines (211 loc) · 7.22 KB
/
old.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
#tool "nuget:?package=GitVersion.CommandLine"
#load "build/helpers.cake"
#tool nuget:?package=docfx.console
#addin nuget:?package=Cake.DocFx
#addin nuget:?package=Cake.Docker
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
///////////////////////////////////////////////////////////////////////////////
// GLOBAL VARIABLES
///////////////////////////////////////////////////////////////////////////////
var solutionPath = File("./src/Downlink.sln");
var projects = GetProjects(solutionPath, configuration);
var artifacts = "./dist/";
var testResultsPath = MakeAbsolute(Directory(artifacts + "./test-results"));
GitVersion versionInfo = null;
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" };
var PackagedRuntimes = new List<string> { "centos", "ubuntu", "debian", "fedora", "rhel" };
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup(ctx =>
{
// Executed BEFORE the first task.
Information("Running tasks...");
//versionInfo = GetVersion();
//Information("Building for version {0}", versionInfo.FullSemVer);
Verbose("Building for " + string.Join(", ", frameworks));
});
Teardown(ctx =>
{
// Executed AFTER the last task.
Information("Finished running tasks.");
});
///////////////////////////////////////////////////////////////////////////////
// TASK DEFINITIONS
///////////////////////////////////////////////////////////////////////////////
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...");
foreach (var project in projects.AllProjectPaths) {
DotNetCoreRestore(project.FullPath);
}
});
Task("Build")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.Does(() =>
{
Information("Building solution...");
foreach(var framework in frameworks) {
foreach (var project in projects.SourceProjectPaths) {
var settings = new DotNetCoreBuildSettings {
Framework = framework,
Configuration = configuration,
NoIncremental = true,
};
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(() =>
{
DocFxBuild("./docfx/docfx.json");
Zip("./docfx/_site/", artifacts + "/docfx.zip");
})
.OnError(ex =>
{
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-Runtimes")
.IsDependentOn("Post-Build")
.Does(() =>
{
CreateDirectory(artifacts + "publish/");
foreach (var project in projects.SourceProjects) {
foreach (var framework in frameworks) {
var projectDir = $"{artifacts}publish/{project.Name}";
CreateDirectory(projectDir);
foreach(var runtime in runtimes) {
var runtimeDir = $"{projectDir}/{runtime}";
CreateDirectory(runtimeDir);
Information("Publishing {0} for {1} runtime", project.Name, runtime);
var rSettings = new DotNetCoreRestoreSettings {
ArgumentCustomization = args => args.Append("-r " + runtime)
};
DotNetCoreRestore(project.Path.FullPath, rSettings);
var settings = new DotNetCorePublishSettings {
ArgumentCustomization = args => args.Append("-r " + runtime),
Configuration = configuration
};
DotNetCorePublish(project.Path.FullPath, settings);
var publishDir = $"{project.Path.GetDirectory()}/bin/{configuration}/{framework}/{runtime}/publish/";
CopyDirectory(publishDir, runtimeDir);
CopyFiles(GetFiles("./build/*.sh"), runtimeDir);
}
}
}
});
Task("Build-Linux-Packages")
.IsDependentOn("Publish-Runtimes")
.Does(() =>
{
Information("Building packages in new container");
CreateDirectory($"{artifacts}/packages/");
foreach(var project in projects.SourceProjects) {
foreach(var runtime in runtimes.Where(rt => PackagedRuntimes.Any(r => rt.Contains(r)))) {
var publishDir = $"{artifacts}publish/{project.Name}/{runtime}";
var sourceDir = MakeAbsolute(Directory(publishDir));
var packageDir = MakeAbsolute(Directory($"{artifacts}packages/{runtime}"));
var runSettings = new DockerRunSettings {
Name = $"docker-fpm-{(runtime.Replace(".", "-"))}",
Volume = new[] { $"{sourceDir}:/src:ro", $"{packageDir}:/out:rw"},
Workdir = "/out",
Rm = true,
//User = "1000"
};
var opts = @"-s dir -a all --force
-m 'Alistair Chapman <[email protected]>'
-n 'git-profile-manager'
--after-install /src/post-install.sh
--before-remove /src/pre-remove.sh";
DockerRun(runSettings, "tenzer/fpm", $"{opts} -v {versionInfo.FullSemVer} {GetRuntimeBuild(runtime)} /src/=/usr/lib/git-profile-manager/");
}
}
});
Task("Build-Windows-Packages")
.IsDependentOn("Publish-Runtimes")
.Does(() =>
{
Information("Building Chocolatey package in new container");
CreateDirectory($"{artifacts}packages");
foreach(var project in projects.SourceProjects) {
foreach(var runtime in runtimes.Where(r => r.StartsWith("win"))) {
var publishDir = $"{artifacts}publish/{project.Name}/{runtime}";
CopyFiles(GetFiles($"./build/{runtime}.nuspec"), publishDir);
var sourceDir = MakeAbsolute(Directory(publishDir));
var packageDir = MakeAbsolute(Directory($"{artifacts}packages/{runtime}"));
var runSettings = new DockerRunSettings {
Name = $"docker-choco-{(runtime.Replace(".", "-"))}",
Volume = new[] {
$"{sourceDir}:/src/{runtime}:ro",
$"{packageDir}:/out:rw",
$"{sourceDir}/{runtime}.nuspec:/src/package.nuspec:ro"
},
Workdir = "/src",
Rm = true
};
var opts = @"-y -v
--outputdirectory /out/
/src/package.nuspec";
DockerRun(runSettings, "agc93/mono-choco", $"choco pack --version {versionInfo.NuGetVersionV2} {opts}");
}
}
});
Task("Default")
.IsDependentOn("Post-Build");
Task("Publish")
.IsDependentOn("Build-Linux-Packages")
.IsDependentOn("Build-Windows-Packages");
RunTarget(target);