Skip to content

Commit

Permalink
🔨 Added Cake build
Browse files Browse the repository at this point in the history
  • Loading branch information
jasontaylordev committed Nov 12, 2024
1 parent 37ddbe9 commit 900cbfd
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
mono_crash.*

# Build results
tools/
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
Expand Down
84 changes: 84 additions & 0 deletions build.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);

0 comments on commit 900cbfd

Please sign in to comment.