From 900cbfd24b8d7375a5808d491cab68176ec9e66d Mon Sep 17 00:00:00 2001 From: JasonTaylorDev Date: Tue, 12 Nov 2024 14:30:57 +1000 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20Added=20Cake=20build?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + build.cake | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 build.cake diff --git a/.gitignore b/.gitignore index 284f22a86..164fea3b1 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ mono_crash.* # Build results +tools/ [Dd]ebug/ [Dd]ebugPublic/ [Rr]elease/ diff --git a/build.cake b/build.cake new file mode 100644 index 000000000..37c148ee4 --- /dev/null +++ b/build.cake @@ -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); \ No newline at end of file