Skip to content
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
25 changes: 22 additions & 3 deletions Source/Cli/Commands/Version/SelfUpdateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ protected override async Task<int> ExecuteAsync(CommandContext context, SelfUpda
var currentVersion = VersionCommand.GetCliVersion();
var strategy = CliUpdate.DetectStrategy();

// Check for available updates before performing the update
var expectedNewVersion = settings.TargetVersion;
if (string.IsNullOrWhiteSpace(expectedNewVersion))
{
using var updateCheckCts = new CancellationTokenSource(TimeSpan.FromSeconds(10));
try
{
expectedNewVersion = await UpdateChecker.CheckForUpdate(UpdateChecker.CliPackageId, currentVersion, updateCheckCts.Token);
}
catch
{
// If we can't check for updates, proceed anyway - the update tool will handle it
}
}

if (string.Equals(format, OutputFormats.Table, StringComparison.Ordinal))
{
AnsiConsole.MarkupLine($"[bold]Updating Cratis CLI...[/] (current: {currentVersion.EscapeMarkup()})");
Expand Down Expand Up @@ -72,20 +87,24 @@ protected override async Task<int> ExecuteAsync(CommandContext context, SelfUpda
return updateResult.Value;
}

var newVersion = VersionCommand.GetCliVersion();
// Use the expected new version instead of checking the currently running assembly
// The currently running process won't change version until it's restarted
var newVersion = expectedNewVersion ?? currentVersion;
var wasUpdated = !string.IsNullOrWhiteSpace(expectedNewVersion);

if (string.Equals(format, OutputFormats.Json, StringComparison.Ordinal) || string.Equals(format, OutputFormats.JsonCompact, StringComparison.Ordinal))
{
OutputFormatter.WriteObject(format, new
{
PreviousVersion = currentVersion,
CurrentVersion = newVersion,
Updated = currentVersion != newVersion
Updated = wasUpdated
});
}
else if (currentVersion != newVersion)
else if (wasUpdated)
{
AnsiConsole.MarkupLine($"[green]Updated from {currentVersion.EscapeMarkup()} to {newVersion.EscapeMarkup()}[/]");
AnsiConsole.MarkupLine("[dim]The new version will be active when you run 'cratis' again.[/]");
}
else
{
Expand Down
Loading