Skip to content

Commit

Permalink
download and create local nuget from SDK repo (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhathcock authored Jul 16, 2024
1 parent 1123054 commit 46c125c
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions Build/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.IO.Compression;
using System.Net;
using System.Runtime.InteropServices;
using Build;
using GlobExpressions;
using static Bullseye.Targets;
Expand All @@ -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<string>();
Expand Down Expand Up @@ -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);

0 comments on commit 46c125c

Please sign in to comment.