Skip to content

Commit

Permalink
Remove RuntimeVersion option
Browse files Browse the repository at this point in the history
Since the option doesnt actually affect which runtime is used when running the dashboard and only affected the downloader, it should probably be added later as a downloader option
  • Loading branch information
SaifAqqad committed Jul 26, 2024
1 parent 0bcbcda commit 7caaf41
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 41 deletions.
35 changes: 8 additions & 27 deletions src/AspireRunner.Core/AspireDashboardManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,6 @@ public async Task<AspireDashboard> GetDashboardAsync(AspireDashboardOptions opti
throw new ApplicationException($"The dashboard requires version '{AspireDashboard.MinimumRuntimeVersion}' or newer of the '{AspireDashboard.AspRuntimeName}' runtime");
}

var preferredVersion = Version.TryParse(options.Runner.RuntimeVersion, out var rv) ? rv : null;
if (preferredVersion != null && !installedRuntimes.Any(v => v.IsCompatibleWith(preferredVersion)))
{
_logger.LogWarning("The specified runtime version '{RuntimeVersion}' is either not installed or incompatible with the dashboard, falling back to the latest installed version", preferredVersion);
preferredVersion = null;
}

var (isInstalled, isWorkload) = await IsInstalledAsync();
if (!isInstalled)
{
Expand All @@ -78,7 +71,7 @@ public async Task<AspireDashboard> GetDashboardAsync(AspireDashboardOptions opti
}

_logger.LogWarning("The Aspire Dashboard is not installed, downloading the latest compatible version...");
var latestVersion = await FetchLatestVersionAsync(installedRuntimes, preferredVersion);
var latestVersion = await FetchLatestVersionAsync(installedRuntimes);

var downloadedVersion = await InstallAsync(installedRuntimes, latestVersion);
if (downloadedVersion == null)
Expand All @@ -91,11 +84,11 @@ public async Task<AspireDashboard> GetDashboardAsync(AspireDashboardOptions opti
else if (!isWorkload && options.Runner.AutoDownload)
{
// We are using the runner-managed dashboards, so we can try to update
await TryUpdateAsync(installedRuntimes, preferredVersion);
await TryUpdateAsync(installedRuntimes);
}

_logger.LogTrace("Aspire Installation Source: {Source}", isWorkload ? "Workload" : "NuGet");
var installedDashboard = GetLatestInstalledVersion(isWorkload, preferredVersion);
var installedDashboard = GetLatestInstalledVersion(isWorkload);
if (installedDashboard == null)
{
throw new ApplicationException("Failed to locate the Aspire Dashboard installation path");
Expand Down Expand Up @@ -139,7 +132,7 @@ public async Task<AspireDashboard> GetDashboardAsync(AspireDashboardOptions opti

if (version == null)
{
version = await FetchLatestVersionAsync(installedRuntimes, null);
version = await FetchLatestVersionAsync(installedRuntimes);
}

var downloadSucceesful = await _nugetHelper.DownloadPackageAsync(_nugetPackageName, version, Path.Combine(_runnerFolder, AspireDashboard.DownloadFolder, version.ToString()));
Expand Down Expand Up @@ -202,7 +195,7 @@ public async Task TryUpdateAsync(Version[] installedRuntimes, Version? preferred
}
}

private (Version Version, string Path)? GetLatestInstalledVersion(bool workload, Version? preferredVersion)
private (Version Version, string Path)? GetLatestInstalledVersion(bool workload)
{
try
{
Expand All @@ -221,15 +214,6 @@ public async Task TryUpdateAsync(Version[] installedRuntimes, Version? preferred
.OrderByDescending(v => v.Version)
.ToArray();

if (preferredVersion != null)
{
var preferredDashboard = installedVersions.FirstOrDefault(v => v.Version.IsCompatibleWith(preferredVersion));
if (preferredDashboard.Path != null)
{
return (preferredDashboard.Version, Path.Combine(preferredDashboard.Path, "tools"));
}
}

// If a version is already installed, we probably already have a compatible runtime (no need to check)
var newestVersion = installedVersions
.MaxBy(d => d.Version);
Expand All @@ -242,20 +226,17 @@ public async Task TryUpdateAsync(Version[] installedRuntimes, Version? preferred
}
}

private async Task<Version> FetchLatestVersionAsync(Version[] installedRuntimes, Version? preferredVersion)
private async Task<Version> FetchLatestVersionAsync(Version[] installedRuntimes)
{
var availableVersions = await _nugetHelper.GetPackageVersionsAsync(_nugetPackageName);
if (availableVersions.Length == 0)
{
throw new ApplicationException("No versions of the Aspire Dashboard are available");
}

var latestRuntimeVersion = preferredVersion != null
? installedRuntimes.Where(v => v.IsCompatibleWith(preferredVersion)).Max()
: installedRuntimes.Max();

var latestRuntimeVersion = installedRuntimes.Max();
var versionToDownload = availableVersions
.Where(preferredVersion != null ? preferredVersion.IsCompatibleWith : v => v.Major == latestRuntimeVersion!.Major)
.Where(v => v.Major == latestRuntimeVersion!.Major)
.DefaultIfEmpty()
.Max()
?? availableVersions.First(); // Fallback to the latest version
Expand Down
8 changes: 0 additions & 8 deletions src/AspireRunner.Core/AspireDashboardOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,6 @@ public sealed class RunnerOptions
/// Automatically download the dashboard if the workload is not found.
/// </summary>
public bool AutoDownload { get; set; }

/// <summary>
/// The version of the dotnet runtime to use when downloading/running the dashboard.
/// </summary>
/// <example>
/// When setting the runtime version to 8.0, the latest 8.x version of the dashboard will be downloaded/used.
/// </example>
public string? RuntimeVersion { get; set; }
}

public enum FrontendAuthMode
Expand Down
3 changes: 0 additions & 3 deletions src/AspireRunner.Tool/Arguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ public record Arguments
[Option('m', "multiple", HelpText = "Allow running multiple instances of the dashboard, if this isn't passed, existing instances will be replaced")]
public bool AllowMultipleInstances { get; set; }

[Option('r', "runtime-version", HelpText = "The version of the .NET runtime to use")]
public string? RuntimeVersion { get; set; }

[Option('d', "auto-download", HelpText = "Automatically download the dashboard if it's not installed")]
public bool? AutoDownload { get; set; }

Expand Down
4 changes: 1 addition & 3 deletions src/AspireRunner.Tool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@
},
Runner = new RunnerOptions
{
PipeOutput = false,
AutoDownload = arguments.AutoDownload ?? true,
LaunchBrowser = arguments.LaunchBrowser,
RuntimeVersion = arguments.RuntimeVersion,
AutoDownload = arguments.AutoDownload ?? true,
SingleInstanceHandling = arguments.AllowMultipleInstances ? SingleInstanceHandling.Ignore : SingleInstanceHandling.ReplaceExisting
}
};
Expand Down

0 comments on commit 7caaf41

Please sign in to comment.