forked from jasontaylordev/CleanArchitecture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.cake
84 lines (74 loc) · 2.44 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
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var webPath = "./src/Web";
var webUrl = "https://localhost:44447/";
IProcess webProcess = null;
Task("Build")
.Does(() => {
Information("Building project...");
DotNetBuild("./CleanArchitecture.sln", new DotNetBuildSettings {
Configuration = configuration
});
});
Task("StartWeb")
.IsDependentOn("Build")
.Does(() => {
Information("Starting web project...");
var processSettings = new ProcessSettings {
Arguments = $"run --project {webPath} --configuration {configuration}",
RedirectStandardOutput = true,
RedirectStandardError = true
};
webProcess = StartAndReturnProcess("dotnet", processSettings);
Information("Waiting for web project to be available...");
var maxRetries = 30;
var delay = 2000; // 2 seconds
var retries = 0;
var isAvailable = false;
while (retries < maxRetries && !isAvailable) {
try {
using (var client = new System.Net.Http.HttpClient()) {
var response = client.GetAsync(webUrl).Result;
if (response.IsSuccessStatusCode) {
isAvailable = true;
}
}
} catch {
// Ignore exceptions and retry
}
if (!isAvailable) {
retries++;
System.Threading.Thread.Sleep(delay);
}
}
if (!isAvailable) {
throw new Exception("Web project is not available after waiting.");
}
Information("Web project is available.");
});
Task("Test")
.ContinueOnError()
.IsDependentOn("StartWeb")
.Does(() => {
Information("Testing project...");
DotNetTest("./CleanArchitecture.sln", new DotNetTestSettings {
Configuration = configuration,
NoBuild = true
});
});
Task("StopWeb")
.IsDependentOn("Test")
.Does(() => {
if (webProcess != null) {
Information("Stopping web project...");
webProcess.Kill();
webProcess.WaitForExit();
Information("Web project stopped.");
}
});
Task("Default")
.IsDependentOn("Build")
.IsDependentOn("StartWeb")
.IsDependentOn("Test")
.IsDependentOn("StopWeb");
RunTarget(target);