-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.cake
More file actions
335 lines (292 loc) · 11.6 KB
/
Copy pathbuild.cake
File metadata and controls
335 lines (292 loc) · 11.6 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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
///////////////////////////////////////////////////////////////////////////////
// fuseraft-cli Cake Build Script
//
// Usage (after running `dotnet tool restore`):
// dotnet cake build.cake # Default (Publish)
// dotnet cake build.cake --target=Build
// dotnet cake build.cake --target=Pack --runtime=linux-x64
// dotnet cake build.cake --configuration=Debug
// dotnet cake build.cake --target=Lint
//
// Or via the bootstrappers:
// ./build.sh [--target=X] [--configuration=Y] [--runtime=Z]
// .\build.ps1 [-Target X] [-Configuration Y] [-Runtime Z]
///////////////////////////////////////////////////////////////////////////////
// Arguments
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var runtime = Argument("runtime", ""); // e.g. "linux-x64"
var skipTests = Argument("skipTests", false);
// Paths
var projectFile = "src/fuseraft.csproj";
var artifactsDir = Directory("artifacts");
var publishDir = Directory("bin");
var packDir = artifactsDir + Directory("packages");
var testResultsDir = artifactsDir + Directory("test-results");
// Version — computed once at script start from minver-cli so every task uses the same value.
var version = GetVersion();
// Helpers
// Ask minver-cli for the exact version it will stamp into the assembly.
// minver-cli is registered as a local dotnet tool in .config/dotnet-tools.json
// and restored by build.sh before Cake runs.
string GetVersion()
{
try
{
IEnumerable<string> lines;
var exit = StartProcess("dotnet", new ProcessSettings
{
Arguments = "minver --tag-prefix v",
RedirectStandardOutput = true,
RedirectStandardError = true // suppress "no tags" warnings
}, out lines);
if (exit == 0)
{
var v = string.Concat(lines).Trim();
if (!string.IsNullOrEmpty(v)) return v;
}
}
catch { /* minver unavailable — fall through */ }
return "0.0.0";
}
string GetGitHash()
{
try
{
IEnumerable<string> lines;
if (StartProcess("git", new ProcessSettings
{
Arguments = "rev-parse --short HEAD",
RedirectStandardOutput = true
}, out lines) == 0)
return string.Concat(lines).Trim();
}
catch { /* git unavailable */ }
return "unknown";
}
// Lifecycle hooks
Setup(ctx =>
{
Information("╔══════════════════════════════════════════════════════╗");
Information("║ fuseraft CLI · Multi-Agent Orchestration ║");
Information("╠══════════════════════════════════════════════════════╣");
Information($"║ Version {version,-37}║");
Information($"║ Configuration {configuration,-37}║");
Information($"║ Runtime {(string.IsNullOrEmpty(runtime) ? "(framework-dependent)" : runtime),-37}║");
Information($"║ Target {target,-37}║");
Information($"║ Git commit {GetGitHash(),-37}║");
Information("╚══════════════════════════════════════════════════════╝");
});
Teardown(ctx =>
{
if (ctx.Successful)
Information($"\n✓ '{target}' succeeded.");
else
Error($"\n✗ '{target}' failed: {ctx.ThrownException?.Message}");
});
///////////////////////////////////////////////////////////////////////////////
// TASKS
///////////////////////////////////////////////////////////////////////////////
//
// Clean: removes artifacts/ and dotnet bin/obj trees
//
Task("Clean")
.Description("Remove build artifacts and clean dotnet output directories.")
.Does(() =>
{
if (DirectoryExists(artifactsDir))
CleanDirectory(artifactsDir);
if (DirectoryExists(publishDir))
CleanDirectory(publishDir);
DotNetClean(projectFile, new DotNetCleanSettings
{
Configuration = configuration,
Verbosity = DotNetVerbosity.Minimal
});
Information("Clean complete.");
});
//
// Restore: fetch NuGet packages
//
Task("Restore")
.Description("Restore NuGet packages.")
.IsDependentOn("Clean")
.Does(() =>
{
DotNetRestore(projectFile, new DotNetRestoreSettings
{
Verbosity = DotNetVerbosity.Minimal
});
foreach (var testProject in GetFiles("tests/**/*.csproj"))
DotNetRestore(testProject.ToString(), new DotNetRestoreSettings
{
Verbosity = DotNetVerbosity.Minimal
});
Information("Restore complete.");
});
//
// Build: compile project in the requested configuration
//
Task("Build")
.Description("Compile the project.")
.IsDependentOn("Restore")
.Does(() =>
{
DotNetBuild(projectFile, new DotNetBuildSettings
{
Configuration = configuration,
NoRestore = true,
Verbosity = DotNetVerbosity.Minimal,
MSBuildSettings = new DotNetMSBuildSettings()
.WithProperty("Version", version)
.WithProperty("InformationalVersion", version)
.WithProperty("SourceRevisionId", GetGitHash())
.WithProperty("MinVerSkip", "true") // minver-cli already computed the version above
});
Information("Build complete.");
});
//
// Test: discover and run all test projects under tests/
//
Task("Test")
.Description("Run all test projects found under tests/.")
.IsDependentOn("Build")
.Does(() =>
{
if (skipTests)
{
Warning("--skipTests flag is set. Skipping.");
return;
}
var testProjects = GetFiles("tests/**/*.csproj");
if (!testProjects.Any())
{
Warning("No test projects found under tests/. Skipping.");
Information("Tip: add an xUnit project under tests/ to enable this step.");
return;
}
EnsureDirectoryExists(testResultsDir);
foreach (var testProject in testProjects)
{
Information($"Testing: {testProject.GetFilename()}");
DotNetTest(testProject.ToString(), new DotNetTestSettings
{
Configuration = configuration,
NoRestore = true,
ResultsDirectory = testResultsDir,
Loggers = new[] { "trx" },
Verbosity = DotNetVerbosity.Minimal,
MSBuildSettings = new DotNetMSBuildSettings()
.WithProperty("Version", version)
.WithProperty("InformationalVersion", version)
.WithProperty("SourceRevisionId", GetGitHash())
.WithProperty("MinVerSkip", "true")
});
}
Information("Tests complete.");
});
//
// Publish: produce a deployable output in artifacts/publish/
//
Task("Publish")
.Description("Publish to artifacts/publish/. Pass --runtime=<rid> for a self-contained binary.")
.IsDependentOn("Test")
.Does(() =>
{
EnsureDirectoryExists(publishDir);
var settings = new DotNetPublishSettings
{
Configuration = configuration,
OutputDirectory = publishDir,
NoRestore = true,
NoBuild = true,
Verbosity = DotNetVerbosity.Minimal,
MSBuildSettings = new DotNetMSBuildSettings()
.WithProperty("Version", version)
.WithProperty("InformationalVersion", version)
.WithProperty("MinVerSkip", "true")
};
if (!string.IsNullOrEmpty(runtime))
{
// Self-contained publish compiles for a specific RID — the earlier Restore and
// Build steps didn't target that RID, so both flags must be cleared.
settings.NoRestore = false;
settings.NoBuild = false;
settings.Runtime = runtime;
settings.SelfContained = true;
settings.MSBuildSettings
.WithProperty("PublishSingleFile", "true")
.WithProperty("IncludeNativeLibrariesForSelfExtract", "true")
.WithProperty("EnableCompressionInSingleFile", "true")
.WithProperty("DebugType", "none")
.WithProperty("DebugSymbols", "false");
Information($"Self-contained single-file publish for: {runtime}");
}
else
{
Information("Framework-dependent publish (no --runtime specified).");
}
DotNetPublish(projectFile, settings);
// On Windows builds, also publish the updater helper alongside the main binary.
if (!string.IsNullOrEmpty(runtime) && runtime.StartsWith("win"))
{
var updaterProject = "src/FuseraftUpdate/FuseraftUpdate.csproj";
var updaterSettings = new DotNetPublishSettings
{
Configuration = configuration,
OutputDirectory = publishDir,
Runtime = runtime,
SelfContained = true,
Verbosity = DotNetVerbosity.Minimal,
MSBuildSettings = new DotNetMSBuildSettings()
.WithProperty("PublishSingleFile", "true")
.WithProperty("EnableCompressionInSingleFile", "true")
.WithProperty("MinVerSkip", "true")
.WithProperty("DebugType", "none")
.WithProperty("DebugSymbols", "false")
};
DotNetPublish(updaterProject, updaterSettings);
Information("fuseraft-update published alongside fuseraft.exe.");
}
Information($"Publish complete → {publishDir}");
});
//
// Pack: zip artifacts/publish/ into a versioned archive
//
Task("Pack")
.Description("Zip the published output into a versioned archive under artifacts/packages/.")
.IsDependentOn("Publish")
.Does(() =>
{
EnsureDirectoryExists(packDir);
var version = GetVersion();
var rtSuffix = string.IsNullOrEmpty(runtime) ? "portable" : runtime;
var zipName = $"fuseraft-{version}-{rtSuffix}.zip";
var zipPath = packDir + File(zipName);
Zip(publishDir, zipPath);
var kb = new System.IO.FileInfo(zipPath.ToString()).Length / 1024;
Information($"Package ready: {zipName} ({kb:N0} KB)");
});
//
// Lint: verify code formatting without modifying files
//
Task("Lint")
.Description("Check code style with 'dotnet format --verify-no-changes'.")
.Does(() =>
{
var exitCode = StartProcess("dotnet", new ProcessSettings
{
Arguments = $"format \"{projectFile}\" --verify-no-changes --severity warn"
});
if (exitCode != 0)
throw new CakeException(
"Code formatting issues detected. Run 'dotnet format' to fix them.");
Information("Lint passed.");
});
//
// Default: full pipeline without the Pack step
//
Task("Default")
.Description("Full pipeline: Clean → Restore → Build → Test → Publish.")
.IsDependentOn("Publish");
RunTarget(target);