Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

download and create local nuget from SDK repo #31

Merged
merged 2 commits into from
Jul 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Loading