-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.cake
200 lines (179 loc) · 7.28 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
#tool "ILRepack"
#tool "GitVersion.CommandLine"
#load "extensions.cake"
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var target = Argument<string>("target", "Default");
var configuration = Argument<string>("configuration", "Release");
///////////////////////////////////////////////////////////////////////////////
// GLOBAL VARIABLES
///////////////////////////////////////////////////////////////////////////////
var solutionPath = File("./src/ClickTwice.sln");
var solution = ParseSolution(solutionPath);
var projects = solution.Projects;
var projectPaths = projects.Select(p => p.Path.GetDirectory());
//var testAssemblies = projects.Where(p => p.Name.Contains("Tests")).Select(p => p.Path.GetDirectory() + "/bin/" + configuration + "/" + p.Name + ".dll");
var artifacts = "./artifacts/";
//var testResultsPath = MakeAbsolute(Directory(artifacts + "./test-results"));
GitVersion versionInfo = null;
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup(() =>
{
// Executed BEFORE the first task.
Information("Running tasks...");
versionInfo = GitVersion();
Information("Building for version {0}", versionInfo.FullSemVer);
});
Teardown(() =>
{
// Executed AFTER the last task.
Information("Finished running tasks.");
});
///////////////////////////////////////////////////////////////////////////////
// TASK DEFINITIONS
///////////////////////////////////////////////////////////////////////////////
Task("Clean")
.Does(() =>
{
// Clean solution directories.
foreach(var path in projectPaths)
{
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...");
NuGetRestore(solutionPath);
});
Task("Build")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.Does(() =>
{
Information("Building solution...");
MSBuild(solutionPath, settings =>
settings.SetPlatformTarget(PlatformTarget.MSIL)
//.WithProperty("TreatWarningsAsErrors","true")
.SetVerbosity(Verbosity.Quiet)
.WithTarget("Build")
.SetConfiguration(configuration));
});
Task("Copy-Files")
.IsDependentOn("Build")
.IsDependentOn("Copy-Libs")
.IsDependentOn("Copy-Scripts")
.Does(() =>
{
CreateDirectory(artifacts + "build");
foreach (var project in projects) {
CreateDirectory(artifacts + "build/" + project.Name);
var files = GetFiles(project.Path.GetDirectory() +"/bin/" +configuration +"/" +project.Name +".*");
CopyFiles(files, artifacts + "build/" + project.Name);
}
});
Task("Copy-Libs")
.IsDependentOn("Build")
.Does(() => {
CreateDirectory(artifacts + "lib");
foreach (var project in projects) {
CreateDirectory(artifacts + "lib/" + project.Name);
var binBase = project.Path.GetDirectory() +"/bin/" +configuration + "/";
var files = GetFiles(binBase + "*.dll");
var xmldoc = GetFiles(binBase + "*.xml");
CopyFiles(files, artifacts + "lib/" + project.Name);
CopyFiles(xmldoc, artifacts + "lib/" + project.Name);
}
});
Task("Copy-Scripts")
.IsDependentOn("Copy-Libs")
.Does(() => {
var scriptDir = artifacts + "/scripts/";
CreateDirectory(scriptDir);
CreateDirectory(scriptDir + "/bin/");
var files = GetFiles(artifacts + "lib/ScriptCs.ClickTwice/*ClickTwice*.dll");
var csFiles = GetFiles(artifacts + "lib/ScriptCs.ClickTwice/*ScriptCs*.dll");
CopyFiles(files, scriptDir + "/bin/");
CopyFiles(csFiles, scriptDir + "/bin/");
CopyFiles(GetFiles("./*.csx"), artifacts + "/scripts/");
});
Task("Publish")
.IsDependentOn("Build")
.IsDependentOn("Copy-Files")
.Does(() => {
var mergeProjects = new[] {"ClickTwice.Handlers.LaunchPage", "ClickTwice.Handlers.AppDetailsPage"};
foreach (var project in mergeProjects) {
Information("Merging libraries");
var assemblyList = GetFiles("./src/" + project + "/bin/" + configuration + "/**/*.dll");
Information("Executing ILMerge to merge {0} assemblies", assemblyList.Count);
ILRepack(
artifacts + project + ".dll",
"./src/" + project + "/bin/" + configuration + "/" + project + ".dll",
assemblyList);
}
});
Task("Merge")
.IsDependentOn("Copy-Files")
.Does(() => {
var assemblyList = GetFiles("./src/ClickTwice.Publisher.Core/bin/" + configuration + "/**/*ClickTwice*.dll").ToList();
//AddIfNotExists(assemblyList, GetFiles("./src/ClickTwice.Handlers.LaunchPage/bin/" + configuration + "/**/*.dll"));
AddIfNotExists(assemblyList, GetFiles("./src/ClickTwice.Handlers.AppDetailsPage/bin/" + configuration + "/**/*.dll"));
foreach(var assembly in assemblyList) {
Information("Merging: {0}", assembly.ToString());
}
Information("Merging {0} assemblies", assemblyList.Count);
ILRepack(
artifacts + "ClickTwice.dll",
"./src/ClickTwice.Publisher.Core/bin/" + configuration + "/ClickTwice.Publisher.Core.dll",
assemblyList,
new ILRepackSettings {
Union = true,
CopyAttrs = true,
AllowMultiple = true,
XmlDocs = true
});
});
Task("Post-Build")
.IsDependentOn("Build")
.IsDependentOn("Copy-Files");
Task("NuGet")
.IsDependentOn("Post-Build")
.Does(() => {
CreateDirectory(artifacts + "package/");
CreateDirectory(artifacts + "templates/");
var specFiles = GetFiles("./**/*.nuspec");
var nuspecFiles = specFiles.Where(f => !f.FullPath.Contains("Template"));
var templateFiles = specFiles.Where(f => f.FullPath.Contains("Template"));
Information("Building {0} NuGet package(s)", specFiles.Count());
Verbose("Building: {0}{1}", Environment.NewLine, string.Join(Environment.NewLine, templateFiles));
Information("Building {0} library packages and {1} template packages", nuspecFiles.Count(), templateFiles.Count());
var versionNotes = ParseAllReleaseNotes("./ReleaseNotes.md").FirstOrDefault(v => v.Version.ToString() == versionInfo.MajorMinorPatch);
NuGetPack(nuspecFiles, new NuGetPackSettings() {
Version = versionInfo.NuGetVersionV2,
ReleaseNotes = versionNotes != null ? versionNotes.Notes.ToList() : new List<string>(),
OutputDirectory = artifacts + "/package",
BasePath = artifacts
});
NuGetPack(templateFiles, new NuGetPackSettings {
Version = versionInfo.NuGetVersionV2,
OutputDirectory = artifacts + "/templates",
});
});
///////////////////////////////////////////////////////////////////////////////
// TARGETS
///////////////////////////////////////////////////////////////////////////////
Task("Default")
.IsDependentOn("NuGet");
///////////////////////////////////////////////////////////////////////////////
// EXECUTION
///////////////////////////////////////////////////////////////////////////////
RunTarget(target);