-
Notifications
You must be signed in to change notification settings - Fork 64
[Bootstrapper] Fetch information from dotnet feeds #391
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
base: main
Are you sure you want to change the base?
Changes from 17 commits
71777a1
8c10e2d
ec96336
5ca0b5c
941bb43
80beb9c
9d02fa9
59ee658
c623aa7
6a89e20
12a155a
cbdb765
f46bccc
58580f2
9838ae3
3bbdddc
cbc2b7d
4df438d
7b35bd6
a9a47f5
1697e1e
822f5e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Runtime.InteropServices; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using System.Text.Json; | ||
| using Microsoft.Deployment.DotNet.Releases; | ||
|
|
||
| namespace Microsoft.DotNet.Tools.Bootstrapper | ||
| { | ||
| internal static class BootstrapperUtilities | ||
| { | ||
| public static string GetRID() | ||
| { | ||
| string operatingSystem = RuntimeInformation.OSDescription switch | ||
| { | ||
| string os when os.Contains("Windows") => "win", | ||
| string os when os.Contains("Linux") => "linux", | ||
| string os when os.Contains("Darwin") => "osx", | ||
| _ => null | ||
| }; | ||
| string architecture = RuntimeInformation.OSArchitecture switch | ||
| { | ||
| Architecture.X64 => "x64", | ||
| Architecture.X86 => "x86", | ||
| Architecture.Arm => "arm", | ||
| Architecture.Arm64 => "arm64", | ||
| _ => null | ||
| }; | ||
|
|
||
| if (operatingSystem == null || architecture == null) | ||
| { | ||
| throw new PlatformNotSupportedException("Unsupported OS or architecture."); | ||
| } | ||
|
|
||
| return $"{operatingSystem}-{architecture}"; | ||
| } | ||
|
|
||
| public static string GetMajorVersionToInstallInDirectory(string basePath) | ||
| { | ||
| // Get the nearest global.json file. | ||
| JsonElement globalJson = GlobalJsonUtilities.GetNearestGlobalJson(basePath); | ||
| string sdkVersion = globalJson | ||
|
||
| .GetProperty("tools") | ||
| .GetProperty("dotnet") | ||
| .ToString(); | ||
|
|
||
| ReleaseVersion version = ReleaseVersion.Parse(sdkVersion); | ||
| Console.WriteLine($"Found version {version.Major}.0 in global.json"); | ||
edvilme marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return $"{version.Major}.0"; | ||
| } | ||
|
|
||
| public static string GetInstallationDirectoryPath() | ||
| { | ||
| string globalJsonPath = GlobalJsonUtilities.GetNearestGlobalJsonPath(Environment.CurrentDirectory); | ||
|
||
| if (globalJsonPath == null) | ||
| { | ||
| throw new FileNotFoundException("No global.json file found in the directory tree."); | ||
edvilme marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| string directoryPath = Path.GetDirectoryName(globalJsonPath); | ||
| if (directoryPath == null) | ||
| { | ||
| throw new DirectoryNotFoundException("Directory path is null."); | ||
edvilme marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // TODO: Replace with the actual installation directory. | ||
| return Path.Combine(directoryPath, ".dotnet.local"); | ||
|
||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.CommandLine.Parsing; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Microsoft.DotNet.Tools.Bootstrapper | ||
| { | ||
| public abstract class CommandBase | ||
| { | ||
| protected ParseResult _parseResult; | ||
|
|
||
| protected CommandBase(ParseResult parseResult) | ||
| { | ||
| _parseResult = parseResult; | ||
| } | ||
|
|
||
| public abstract int Execute(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.CommandLine; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Microsoft.DotNet.Tools.Bootstrapper.Commands | ||
| { | ||
| internal static class Common | ||
| { | ||
| internal static Option<bool> AllowPreviewsOptions = new Option<bool>( | ||
| "--allow-previews", | ||
| description: "Include pre-release sdk versions"); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.CommandLine.Parsing; | ||
| using System.IO; | ||
| using System.IO.Compression; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.Deployment.DotNet.Releases; | ||
|
|
||
| namespace Microsoft.DotNet.Tools.Bootstrapper.Commands.Install; | ||
|
|
||
| internal class InstallCommand( | ||
| ParseResult parseResult) : CommandBase(parseResult) | ||
| { | ||
| private string _version = parseResult.ValueForArgument(InstallCommandParser.VersionArgument); | ||
| private string _rid = BootstrapperUtilities.GetRID(); | ||
| private bool _allowPreviews = parseResult.ValueForOption(InstallCommandParser.AllowPreviewsOption); | ||
|
|
||
|
|
||
| public override int Execute() | ||
| { | ||
| // If no channel is specified, use the default channel. | ||
| if (string.IsNullOrEmpty(_version)) | ||
| { | ||
| _version = BootstrapperUtilities.GetMajorVersionToInstallInDirectory( | ||
| Environment.CurrentDirectory); | ||
| } | ||
|
|
||
| ProductCollection productCollection = ProductCollection.GetAsync().Result; | ||
| Product product = productCollection | ||
| .FirstOrDefault(p => string.IsNullOrEmpty(_version) || p.ProductVersion.Equals(_version, StringComparison.OrdinalIgnoreCase)); | ||
|
|
||
| if (product == null) | ||
| { | ||
| Console.WriteLine($"No product found for channel: {_version}"); | ||
| return 1; | ||
| } | ||
|
|
||
| ProductRelease latestRelease = product.GetReleasesAsync().Result | ||
| .Where(release => !release.IsPreview || _allowPreviews) | ||
| .OrderByDescending(release => release.ReleaseDate) | ||
| .FirstOrDefault(); | ||
|
|
||
| if (latestRelease == null) | ||
| { | ||
| Console.WriteLine($"No releases found for product: {product.ProductName}"); | ||
| return 1; | ||
| } | ||
|
|
||
| Console.WriteLine($"Installing {product.ProductName} {latestRelease.Version}..."); | ||
|
|
||
| string installationDirectoryPath = BootstrapperUtilities.GetInstallationDirectoryPath(); | ||
|
|
||
| foreach (ReleaseComponent component in latestRelease.Components) | ||
| { | ||
| Console.WriteLine($"Installing {component.Name}..."); | ||
| DownloadAndExtractReleaseComponentFiles(component, installationDirectoryPath); | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| private static void DownloadAndExtractReleaseComponentFiles(ReleaseComponent component, string basePath) | ||
| { | ||
| if (component is WindowsDesktopReleaseComponent && !OperatingSystem.IsWindows()) | ||
| { | ||
| return; | ||
edvilme marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| ReleaseFile releaseFile = component.Files.FirstOrDefault(file => | ||
edvilme marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| file.Rid.Equals(BootstrapperUtilities.GetRID(), StringComparison.OrdinalIgnoreCase) && (file.Name.EndsWith(".zip") || file.Name.EndsWith(".tar.gz"))); | ||
|
|
||
| if (string.IsNullOrEmpty(releaseFile?.FileName)) | ||
| { | ||
| Console.WriteLine($"\tNo suitable file found for {component.Name}"); | ||
edvilme marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return; | ||
| } | ||
|
|
||
| string zipPath = Path.Combine(basePath, releaseFile.FileName); | ||
edvilme marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if (File.Exists(zipPath)) | ||
| { | ||
| Console.WriteLine($"\t{component.Name} already exists at {zipPath}"); | ||
| return; | ||
edvilme marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| try | ||
| { | ||
| releaseFile.DownloadAsync(zipPath)?.Wait(); | ||
|
|
||
| // Extract the downloaded file | ||
| ZipFile.ExtractToDirectory(zipPath, Path.ChangeExtension(zipPath, "")); | ||
edvilme marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
edvilme marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
edvilme marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
edvilme marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Console.WriteLine($"\tExtracted {component.Name} to {Path.ChangeExtension(zipPath, "")}"); | ||
|
|
||
| // Delete the downloaded file | ||
| File.Delete(zipPath); | ||
edvilme marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| catch (IOException) | ||
| { | ||
| return; | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using System.CommandLine; | ||
| using System.CommandLine.Invocation; | ||
| using System.CommandLine.Parsing; | ||
|
|
||
| namespace Microsoft.DotNet.Tools.Bootstrapper.Commands.Install; | ||
|
|
||
| internal class InstallCommandParser | ||
| { | ||
| internal static Argument<string> VersionArgument = new Argument<string>( | ||
| name: "version", | ||
| description: "SDK version to install. If not specified, It will take the latest.") | ||
| { | ||
| Arity = ArgumentArity.ZeroOrOne, | ||
| }; | ||
|
|
||
| internal static Option<bool> AllowPreviewsOption = Common.AllowPreviewsOptions; | ||
|
|
||
| private static readonly Command Command = ConstructCommand(); | ||
|
|
||
| public static Command GetCommand() => Command; | ||
|
|
||
| private static Command ConstructCommand() | ||
| { | ||
| Command command = new("install", "Install SDKs available for installation."); | ||
|
|
||
| command.AddArgument(VersionArgument); | ||
|
|
||
| command.AddOption(AllowPreviewsOption); | ||
|
|
||
| command.Handler = CommandHandler.Create((ParseResult parseResult) => | ||
| { | ||
| return new InstallCommand(parseResult).Execute(); | ||
| }); | ||
| return command; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.CommandLine.Parsing; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.Deployment.DotNet.Releases; | ||
| using Spectre.Console; | ||
|
|
||
| namespace Microsoft.DotNet.Tools.Bootstrapper.Commands.Search; | ||
|
|
||
| internal class SearchCommand( | ||
| ParseResult parseResult) : CommandBase(parseResult) | ||
| { | ||
| private string _channel = parseResult.ValueForArgument(SearchCommandParser.ChannelArgument); | ||
| private bool _allowPreviews = parseResult.ValueForOption(SearchCommandParser.AllowPreviewsOption); | ||
| public override int Execute() | ||
| { | ||
| List<Product> productCollection = [.. ProductCollection.GetAsync().Result]; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The releases.json only changes about once a month. You should consider caching the file on disk and only update it if there's a new version available.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should be using the same etag-based cache invalidation system that @nagilson has for the VSCode extension. ETags are the way to handle cache invalidation of HTTP-delivered resources, and we shouldn't be reinventing the wheel.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does https://github.com/dotnet/deployment-tools cache it? I would hope it does so, but at a glance it looks like it does not. I tis what is interfacing with the web request caller API. I would also hope that it handles proxies well. As well as timeouts. If it does not, I would almost question why that should not be implemented over there instead of here. Definitely wouldn't block on this for this PR but would create another issue from it.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From what I've seen, I don't think that it does. I do agree that it would make a lot of sense to implement it there
edvilme marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| productCollection = [.. | ||
| productCollection.Where(product => !product.IsOutOfSupport() && (product.SupportPhase != SupportPhase.Preview || _allowPreviews))]; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @baronfel Did we decide to only support in support installs? I understand why we'd want to do that, but it seems to limit the product use cases. I would rather emit a warning than block the behavior, but maybe that's ill-advised. |
||
|
|
||
| if (!string.IsNullOrEmpty(_channel)) | ||
| { | ||
| productCollection = [.. productCollection.Where(product => product.ProductVersion.Equals(_channel, StringComparison.OrdinalIgnoreCase))]; | ||
edvilme marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| foreach (Product product in productCollection) | ||
| { | ||
| string productHeader = $"{product.ProductName} {product.ProductVersion}"; | ||
| Console.WriteLine(productHeader); | ||
|
|
||
| Table productMetadataTable = new Table() | ||
| .AddColumn("Version") | ||
| .AddColumn("Release Date") | ||
| .AddColumn("Latest SDK") | ||
| .AddColumn("Runtime") | ||
| .AddColumn("ASP.NET Runtime") | ||
| .AddColumn("Windows Desktop Runtime"); | ||
|
|
||
| List<ProductRelease> releases = product.GetReleasesAsync().Result.ToList() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For future reference in the above issue again: Does this cache, and does it handle no internet/timeouts well? The responsibility of ownership here is interesting. Ideally this command could work offline if it has cached information.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I think this does cache, and handles updating and working offline too: |
||
| .Where(relase => !relase.IsPreview || _allowPreviews).ToList(); | ||
|
|
||
| foreach (ProductRelease release in releases) | ||
| { | ||
| // Get release.Sdks latest version | ||
| var latestSdk = release.Sdks | ||
| .OrderByDescending(sdk => sdk.Version) | ||
| .FirstOrDefault(); | ||
|
|
||
| productMetadataTable.AddRow( | ||
| release.Version.ToString(), | ||
| release.ReleaseDate.ToString("yyyy-MM-dd"), | ||
edvilme marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| latestSdk?.DisplayVersion ?? "N/A", | ||
| release.Runtime?.DisplayVersion ?? "N/A", | ||
| release.AspNetCoreRuntime?.DisplayVersion ?? "N/A", | ||
| release.WindowsDesktopRuntime?.DisplayVersion ?? "N/A"); | ||
| } | ||
| AnsiConsole.Write(productMetadataTable); | ||
| Console.WriteLine(); | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.