-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.cake
261 lines (224 loc) · 8.01 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
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var target = Argument<string>("target", "Default");
var configuration = Argument<string>("configuration", "Release");
var verbosity = Argument<string>("verbosity", "Minimal");
///////////////////////////////////////////////////////////////////////////////
// GLOBAL VARIABLES
///////////////////////////////////////////////////////////////////////////////
var sourceDir = Directory("./src");
var solutions = GetFiles("./**/*.sln");
var projects = new []
{
sourceDir.Path + "/HelloWorld/HelloWorld.csproj",
};
// BUILD OUTPUT DIRECTORIES
var artifactsDir = Directory("./artifacts");
var publishDir = Directory("./publish/");
// VERBOSITY
var dotNetCoreVerbosity = Cake.Common.Tools.DotNetCore.DotNetCoreVerbosity.Normal;
if (!Enum.TryParse(verbosity, true, out dotNetCoreVerbosity))
{
dotNetCoreVerbosity = Cake.Common.Tools.DotNetCore.DotNetCoreVerbosity.Normal;
Warning(
"Verbosity could not be parsed into type 'Cake.Common.Tools.DotNetCore.DotNetCoreVerbosity'. Defaulting to {0}",
dotNetCoreVerbosity);
}
///////////////////////////////////////////////////////////////////////////////
// COMMON FUNCTION DEFINITIONS
///////////////////////////////////////////////////////////////////////////////
string GetProjectName(string project)
{
return project
.Split(new [] {'/'}, StringSplitOptions.RemoveEmptyEntries)
.Last()
.Replace(".csproj", string.Empty);
}
///////////////////////////////////////////////////////////////////////////////
// SETUP / TEARDOWN
///////////////////////////////////////////////////////////////////////////////
Setup(ctx =>
{
// Executed BEFORE the first task.
EnsureDirectoryExists(artifactsDir);
EnsureDirectoryExists(publishDir);
Information("Running tasks...");
});
Teardown(ctx =>
{
// Executed AFTER the last task.
Information("Finished running tasks.");
});
///////////////////////////////////////////////////////////////////////////////
// TASK DEFINITIONS
///////////////////////////////////////////////////////////////////////////////
Task("Clean")
.Description("Cleans all directories that are used during the build process.")
.Does(() =>
{
foreach(var solution in solutions)
{
Information("Cleaning {0}", solution.FullPath);
CleanDirectories(solution.FullPath + "/**/bin/" + configuration);
CleanDirectories(solution.FullPath + "/**/obj/" + configuration);
Information("{0} was clean.", solution.FullPath);
}
CleanDirectory(artifactsDir);
CleanDirectory(publishDir);
});
Task("Restore")
.Description("Restores all the NuGet packages that are used by the specified solution.")
.Does(() =>
{
var settings = new DotNetCoreRestoreSettings
{
DisableParallel = false,
NoCache = true,
Verbosity = dotNetCoreVerbosity
};
foreach(var solution in solutions)
{
Information("Restoring NuGet packages for '{0}'...", solution);
DotNetCoreRestore(solution.FullPath, settings);
Information("NuGet packages restored for '{0}'.", solution);
}
});
Task("Build")
.Description("Builds all the different parts of the project.")
.Does(() =>
{
var msBuildSettings = new DotNetCoreMSBuildSettings
{
TreatAllWarningsAs = MSBuildTreatAllWarningsAs.Error,
Verbosity = dotNetCoreVerbosity
};
var settings = new DotNetCoreBuildSettings
{
Configuration = configuration,
MSBuildSettings = msBuildSettings,
NoRestore = true
};
foreach(var solution in solutions)
{
Information("Building '{0}'...", solution);
DotNetCoreBuild(solution.FullPath, settings);
Information("'{0}' has been built.", solution);
}
});
Task("Test-Unit")
.Description("Tests all the different parts of the project.")
.Does(() =>
{
var settings = new DotNetCoreTestSettings
{
Configuration = configuration,
NoRestore = true,
NoBuild = true
};
var projectFiles = GetFiles("./test/**/*.csproj");
foreach(var file in projectFiles)
{
Information("Testing '{0}'...", file);
DotNetCoreTest(file.FullPath, settings);
Information("'{0}' has been tested.", file);
}
});
Task("Publish")
.Description("Publish the Lambda Functions.")
.Does(() =>
{
foreach(var project in projects)
{
var projectName = project
.Split(new [] {'/'}, StringSplitOptions.RemoveEmptyEntries)
.Last()
.Replace(".csproj", string.Empty);
var outputDirectory = System.IO.Path.Combine(publishDir, projectName);
var msBuildSettings = new DotNetCoreMSBuildSettings
{
TreatAllWarningsAs = MSBuildTreatAllWarningsAs.Error,
Verbosity = dotNetCoreVerbosity
};
var settings = new DotNetCorePublishSettings
{
Configuration = configuration,
MSBuildSettings = msBuildSettings,
NoRestore = true,
OutputDirectory = outputDirectory,
Verbosity = dotNetCoreVerbosity
};
Information("Publishing '{0}'...", projectName);
DotNetCorePublish(project, settings);
Information("'{0}' has been published.", projectName);
}
});
Task("Pack")
.Description("Packs all the different parts of the project.")
.Does(() =>
{
foreach(var project in projects)
{
var projectName = GetProjectName(project);
Information("Packing '{0}'...", projectName);
var path = System.IO.Path.Combine(publishDir, projectName);
var files = GetFiles(path + "/*.*");
Zip(
path,
System.IO.Path.Combine(artifactsDir, $"{projectName}.zip"),
files);
Information("'{0}' has been packed.", projectName);
}
});
Task("Run-Local")
.Description("Runs all the acceptance tests locally.")
.Does(() =>
{
var settings = new ProcessSettings
{
Arguments = "local invoke \"HelloWorld\" -e event.json",
};
Information("Starting the SAM local...");
using(var process = StartAndReturnProcess("sam", settings))
{
process.WaitForExit();
Information("Exit code: {0}", process.GetExitCode());
}
Information("SAM local has finished.");
});
///////////////////////////////////////////////////////////////////////////////
// TARGETS
///////////////////////////////////////////////////////////////////////////////
Task("Package")
.Description("This is the task which will run if target Package is passed in.")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.IsDependentOn("Build")
.IsDependentOn("Test-Unit")
.IsDependentOn("Publish")
.IsDependentOn("Pack")
.Does(() => { Information("Package target ran."); });
Task("Test")
.Description("This is the task which will run if target Test is passed in.")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.IsDependentOn("Build")
.IsDependentOn("Test-Unit")
.Does(() => { Information("Test target ran."); });
Task("Run")
.Description("This is the task which will run if target Run is passed in.")
.IsDependentOn("Clean")
.IsDependentOn("Restore")
.IsDependentOn("Build")
.IsDependentOn("Test-Unit")
.IsDependentOn("Publish")
.IsDependentOn("Pack")
.IsDependentOn("Run-Local")
.Does(() => { Information("Run target ran."); });
Task("Default")
.Description("This is the default task which will run if no specific target is passed in.")
.IsDependentOn("Package");
///////////////////////////////////////////////////////////////////////////////
// EXECUTION
///////////////////////////////////////////////////////////////////////////////
RunTarget(target);