-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.cake
More file actions
321 lines (269 loc) · 7.51 KB
/
build.cake
File metadata and controls
321 lines (269 loc) · 7.51 KB
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
using System.Runtime.InteropServices;
///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
var target = Argument("t", "Build-Cli");
var configuration = Argument("c", "Release");
var runtime = Argument("r", "");
var framework = Argument("f", "");
var output = Argument<string>("o", null);
var noRestore = Argument("no-restore", false);
var noBuild = Argument("no-build", false);
string engineProjectFile = "src/Kryptor/Kryptor.csproj";
string clientProjectFile = "src/Kryptor.Client/Kryptor.Client.csproj";
string cliProjectFile = "src/Kryptor.Cli/Kryptor.Cli.csproj";
string engineTestProjectFile = "test/Kryptor.Tests/Kryptor.Tests.csproj";
///////////////////////////////////////////////////////////////////////////////
// TASKS
///////////////////////////////////////////////////////////////////////////////
bool ignoreLockFile;
bool CiBuild;
DotNetMSBuildSettings GlobalMSBuildSettings => new()
{
ContinuousIntegrationBuild = CiBuild,
};
DotNetRestoreSettings GlobalRestoreSettings => new()
{
Runtime = runtime,
UseLockFile = !ignoreLockFile,
MSBuildSettings = GlobalMSBuildSettings,
};
DotNetBuildSettings GlobalBuildSettings => new()
{
NoRestore = true,
Configuration = configuration,
Framework = framework,
Runtime = runtime,
OutputDirectory = output,
MSBuildSettings = GlobalMSBuildSettings,
};
DotNetTestSettings GlobalTestSettings => new()
{
NoRestore = true,
NoBuild = true,
Verbosity = DotNetVerbosity.Normal,
Collectors = { "XPlat Code Coverage" },
Loggers = { "trx" },
Configuration = configuration,
Framework = framework,
Runtime = runtime,
MSBuildSettings = GlobalMSBuildSettings,
};
DotNetPublishSettings GlobalPublishSettings => new()
{
NoRestore = true,
NoBuild = true,
Configuration = configuration,
Framework = framework,
Runtime = runtime,
OutputDirectory = output,
MSBuildSettings = GlobalMSBuildSettings,
};
DotNetPackSettings GlobalPackSettings => new()
{
NoRestore = true,
NoBuild = true,
Configuration = configuration,
Runtime = runtime,
OutputDirectory = output,
MSBuildSettings = GlobalMSBuildSettings,
};
string ResolveRuntimeIdentifier()
{
var rawId = RuntimeInformation.RuntimeIdentifier;
string resId;
if (IsRunningOnLinux())
{
resId = $"linux-{rawId.Split('-')[1]}";
}
else
{
resId = rawId;
}
return resId;
}
Setup(context =>
{
CiBuild = GitHubActions.IsRunningOnGitHubActions;
if (CiBuild)
{
Information("Running build in Github Actions");
}
if (context.TasksToExecute.Where(task => task.Name.StartsWith("Publish-")).Count() > 0)
{
ignoreLockFile = true;
}
else
{
ignoreLockFile = false;
}
});
Task("Restore-Engine")
.Description("Restore kryptor engine dependencies")
.WithCriteria(!noRestore && !noBuild)
.Does(() =>
{
DotNetRestore(engineProjectFile, GlobalRestoreSettings);
});
Task("Build-Engine")
.Description("Build kryptor engine")
.IsDependentOn("Restore-Engine")
.WithCriteria(!noBuild)
.Does(() =>
{
DotNetBuild(engineProjectFile, GlobalBuildSettings);
});
Task("Pack-Engine")
.Description("Create a NuGet package for kryptor engine")
.IsDependentOn("Build-Engine")
.Does(() =>
{
DotNetPack(engineProjectFile, GlobalPackSettings);
});
Task("Restore-Client")
.Description("Restore kryptor client utilities dependencies")
.IsDependentOn("Restore-Engine")
.WithCriteria(!noRestore && !noBuild)
.Does(() =>
{
DotNetRestore(clientProjectFile, GlobalRestoreSettings);
});
Task("Build-Client")
.Description("Build kryptor client utilities")
.IsDependentOn("Restore-Client")
.WithCriteria(!noBuild)
.Does(() =>
{
DotNetBuild(clientProjectFile, GlobalBuildSettings);
});
Task("Pack-Client")
.Description("Create a NuGet package for kryptor client utilities")
.IsDependentOn("Build-Client")
.Does(() =>
{
DotNetPack(clientProjectFile, GlobalPackSettings);
});
Task("Restore-Cli")
.Description("Restore kryptor command line interface dependencies")
.IsDependentOn("Restore-Client")
.WithCriteria(!noRestore && !noBuild)
.Does(() =>
{
DotNetRestore(cliProjectFile, GlobalRestoreSettings);
});
Task("Build-Cli")
.Description("Build kryptor command line interface")
.IsDependentOn("Restore-Cli")
.WithCriteria(!noBuild)
.Does(() =>
{
DotNetBuild(cliProjectFile, GlobalBuildSettings);
});
Task("Pack-Cli")
.Description("Create a NuGet package for kryptor command line interface")
.IsDependentOn("Build-Cli")
.Does(() =>
{
DotNetPack(cliProjectFile, GlobalPackSettings);
});
Task("Publish-Cli")
.Description("Publish kryptor cli")
.IsDependentOn("Build-Cli")
.Does(() =>
{
DotNetPublish(cliProjectFile, GlobalPublishSettings);
});
Task("Publish-Cli.bundle")
.Description("Publish kryptor cli bundled (self contained)")
.IsDependentOn("Build-Cli")
.Does(() =>
{
var publishSettings = GlobalPublishSettings;
publishSettings.SelfContained = true;
publishSettings.PublishTrimmed = true;
publishSettings.MSBuildSettings = new DotNetMSBuildSettings()
.WithProperty("CompileBundled", "True");
DotNetPublish(cliProjectFile, publishSettings);
});
Task("Restore-Cli.Aot")
.Description("Restore kryptor cli native AOT dependencies")
.IsDependentOn("Restore-Client")
.WithCriteria(!noRestore && !noBuild)
.Does(() =>
{
var restoreSettings = GlobalRestoreSettings;
if (string.IsNullOrEmpty(restoreSettings.Runtime))
{
restoreSettings.Runtime = ResolveRuntimeIdentifier();
}
restoreSettings.MSBuildSettings = new DotNetMSBuildSettings()
.WithProperty("CompileAot", "True");
DotNetRestore(cliProjectFile, restoreSettings);
});
Task("Publish-Cli.Aot")
.Description("Publish kryptor cli native AOT")
.IsDependentOn("Restore-Cli.Aot")
.Does(() =>
{
var publishSettings = GlobalPublishSettings;
if (string.IsNullOrEmpty(publishSettings.Runtime))
{
publishSettings.Runtime = ResolveRuntimeIdentifier();
}
if (string.IsNullOrEmpty(publishSettings.Framework))
{
publishSettings.Framework = "net10.0";
}
publishSettings.NoBuild = false;
publishSettings.MSBuildSettings = new DotNetMSBuildSettings()
.WithProperty("CompileAot", "True");
DotNetPublish(cliProjectFile, publishSettings);
});
Task("Restore-Engine.Test")
.Description("Restore kryptor engine test dependencies")
.IsDependentOn("Restore-Engine")
.WithCriteria(!noRestore && !noBuild)
.Does(() =>
{
DotNetRestore(engineTestProjectFile, GlobalRestoreSettings);
});
Task("Build-Engine.Test")
.Description("Build kryptor engine test")
.IsDependentOn("Restore-Engine.Test")
.WithCriteria(!noBuild)
.Does(() =>
{
DotNetBuild(engineTestProjectFile, GlobalBuildSettings);
});
Task("Test-Engine")
.Description("Run kryptor engine tests")
.IsDependentOn("Build-Engine.Test")
.Does(() =>
{
DotNetTest(engineTestProjectFile, GlobalTestSettings);
});
Task("Restore-All")
.Description("Restore all projects")
.IsDependentOn("Restore-Engine")
.IsDependentOn("Restore-Client")
.IsDependentOn("Restore-Cli");
Task("Restore-Tests")
.Description("Restore all test projects")
.IsDependentOn("Restore-Engine.Test");
Task("Build-All")
.Description("Build all projects")
.IsDependentOn("Build-Engine")
.IsDependentOn("Build-Client")
.IsDependentOn("Build-Cli");
Task("Build-Tests")
.Description("Build all test projects")
.IsDependentOn("Build-Engine.Test");
Task("Pack-All")
.Description("Create NuGet package for all projects")
.IsDependentOn("Pack-Engine")
.IsDependentOn("Pack-Client")
.IsDependentOn("Pack-Cli");
Task("Test-All")
.Description("Run all tests")
.IsDependentOn("Test-Engine");
RunTarget(target);