-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
/
build.cake
110 lines (94 loc) · 3.14 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
// #if (!UseApiOnly)
#addin nuget:?package=Cake.Npm&version=4.0.0
// #endif
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");
var webServerPath = "./src/Web";
var webClientPath = "./src/Web/ClientApp";
var webUrl = "https://localhost:5001/";
// #if (!UseApiOnly)
webUrl = "https://localhost:44447/";
// #endif
IProcess webProcess = null;
Task("Build")
.Does(() => {
Information("Building project...");
DotNetBuild("./CleanArchitecture.sln", new DotNetBuildSettings {
Configuration = configuration
});
// #if (!UseApiOnly)
if (DirectoryExists(webClientPath)) {
Information("Installing client app dependencies...");
NpmInstall(settings => settings.WorkingDirectory = webClientPath);
Information("Building client app...");
NpmRunScript("build", settings => settings.WorkingDirectory = webClientPath);
}
// #endif
});
Task("Run")
.Does(() => {
Information("Starting web project...");
var processSettings = new ProcessSettings {
Arguments = $"run --project {webServerPath} --configuration {configuration} --no-build --no-restore",
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()
.Does(() => {
Information("Testing project...");
var testSettings = new DotNetTestSettings {
Configuration = configuration,
NoBuild = true
};
// #if (!UseApiOnly)
if (target == "Basic") {
testSettings.Filter = "FullyQualifiedName!~AcceptanceTests";
}
// #endif
DotNetTest("./CleanArchitecture.sln", testSettings);
});
Teardown(context =>
{
if (webProcess != null) {
Information("Stopping web project...");
webProcess.Kill();
webProcess.WaitForExit();
Information("Web project stopped.");
}
});
Task("Default")
.IsDependentOn("Build")
.IsDependentOn("Run")
.IsDependentOn("Test");
Task("Basic")
.IsDependentOn("Build")
.IsDependentOn("Test");
RunTarget(target);