From 46c125cbf32fe31f5b78013eccdd38562630794a Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Tue, 16 Jul 2024 16:39:18 +0100 Subject: [PATCH] download and create local nuget from SDK repo (#31) --- Build/Program.cs | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/Build/Program.cs b/Build/Program.cs index 9855e7d6b..4a6eab5d7 100644 --- a/Build/Program.cs +++ b/Build/Program.cs @@ -1,4 +1,6 @@ using System.IO.Compression; +using System.Net; +using System.Runtime.InteropServices; using Build; using GlobExpressions; using static Bullseye.Targets; @@ -14,6 +16,7 @@ const string VERSION = "version"; const string RESTORE_TOOLS = "restore-tools"; const string BUILD_SERVER_VERSION = "build-server-version"; +const string LOCAL_SDK = "add-local-sdk"; //need to pass arguments /*var arguments = new List(); @@ -178,6 +181,67 @@ void RemoveDirectory(string d) } ); +Target( + LOCAL_SDK, + async () => + { + var path = Environment.CurrentDirectory; + var gitRoot = Directory.GetParent(path)?.FullName ?? ".."; + var sdkRepo = Path.Combine(gitRoot, "speckle-sharp-sdk"); + var output = Path.Combine(sdkRepo, "output"); + var localFeed = Path.Combine(gitRoot, "speckle-local-feed"); + Console.WriteLine($"Creating/cleaning output from SDK at: {output}"); + if (Directory.Exists(localFeed)) + { + Directory.Delete(localFeed, true); + } + Directory.CreateDirectory(localFeed); + Console.WriteLine($"Creating/cleaning local repo at: {localFeed}"); + if (Directory.Exists(localFeed)) + { + Directory.Delete(localFeed, true); + } + Directory.CreateDirectory(localFeed); + var nugetCli = Path.Combine(localFeed, "nuget.exe"); + if (File.Exists(nugetCli)) + { + Console.WriteLine($"Updating nuget: {nugetCli}"); + await RunAsync(nugetCli, "update -self"); + } + else + { + Console.WriteLine($"Downloading nuget: {nugetCli}"); + using var client = new HttpClient(); + await using var s = await client.GetStreamAsync("https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"); + await using var fs = new FileStream(nugetCli, FileMode.OpenOrCreate); + await s.CopyToAsync(fs); + } + + var nugets = Glob.Files(output, "*.nupkg").ToList(); + if (!nugets.Any()) + { + Console.WriteLine($"No nugets found in: {output}"); + } + foreach (var nuget in nugets) + { + await RunAsync(nugetCli, $"add {Path.Combine(output, nuget)} -source {localFeed}"); + } + Console.WriteLine($"Adding local source: {localFeed}"); + await RunAsync( + "dotnet", + $"nuget add source {localFeed} --name \"Speckle SDK Local\"", + handleExitCode: i => + { + if (i != 0) + { + Console.WriteLine($"Adding nuget local feed failed: {i}"); + } + return true; + } + ); + } +); + Target("default", DependsOn(FORMAT, ZIP), () => Console.WriteLine("Done!")); await RunTargetsAndExitAsync(args).ConfigureAwait(true);