Skip to content

Instantly share code, notes, and snippets.

@maddymontaquila
Created June 18, 2025 21:10
Show Gist options
  • Select an option

  • Save maddymontaquila/8779ae68eba41daacfba2bccd15325ba to your computer and use it in GitHub Desktop.

Select an option

Save maddymontaquila/8779ae68eba41daacfba2bccd15325ba to your computer and use it in GitHub Desktop.
#:package Spectre.Console@0.50.0
using Spectre.Console;
var start = DateTime.Now;
AnsiConsole.WriteLine();
var publishDuration = RunStep1PublishAssets();
PrintDivider();
var buildDuration = RunStep2PreDeployScripts();
PrintDivider();
var deployDuration = RunStep3DeployAssets();
PrintDivider();
AnsiConsole.WriteLine();
// Summary
var totalDuration = DateTime.Now - start;
AnsiConsole.MarkupLine($"Deployment [green bold]succeeded[/] in {totalDuration.TotalSeconds:F1}s");
AnsiConsole.WriteLine();
var publisherNames = new[] { "docker compose", "kubernetes", "azure" };
var publishers = new Rows(publisherNames.Select(name => new Text(name)));
// Header
var header = new Panel(publishers);
header.Header = new PanelHeader(" Targets created ");
header.Padding = new Padding(4, 0, 4, 0);
header.Border = BoxBorder.Rounded;
AnsiConsole.Write(header);
static TimeSpan RunStep1PublishAssets()
{
var publishStart = DateTime.Now;
AnsiConsole.MarkupLine("[bold]Step 1: Publishing assets[/]");
var step1Tasks = AnsiConsole.Progress()
.AutoClear(false)
.HideCompleted(false)
.Columns(
[
new SpinnerColumn(Spinner.Known.BouncingBar) { Style = Style.Parse("fuchsia") },
new TaskDescriptionColumn() { Alignment = Justify.Left },
new ElapsedTimeColumn() { Style = Style.Parse("fuchsia") },
]);
step1Tasks.Start(ctx =>
{
var task = ctx.AddTask("This is the first task of the publish step");
while (!task.IsFinished)
{
task.Increment(5);
Thread.Sleep(50);
}
task.Description("[green]βœ“ DONE:[/] This is the first task of the publish step");
});
var publishDuration = DateTime.Now - publishStart;
AnsiConsole.MarkupLine($"βœ… [green]SUCCESS:[/] Publish completed in [magenta]{publishDuration.TotalSeconds:F1}s[/]");
AnsiConsole.MarkupLine("πŸ“‚ Assets published to [teal]./mydeploymentassets[/]");
return publishDuration;
}
static TimeSpan RunStep2PreDeployScripts()
{
var buildStepStart = DateTime.Now;
AnsiConsole.MarkupLine("[bold]Step 2:[/] Building container images");
var log = "";
var buildStep = AnsiConsole.Progress()
.AutoClear(false)
.HideCompleted(false)
.Columns(
[
new SpinnerColumn(Spinner.Known.BouncingBar) { Style = Style.Parse("fuchsia") },
new TaskDescriptionColumn() { Alignment = Justify.Left },
new ElapsedTimeColumn() { Style = Style.Parse("fuchsia") },
])
.UseRenderHook((renderable, tasks) =>
{
var logLine = new Markup($"[dim]LOG: {log}[/]");
return new Rows(logLine, renderable);
}); buildStep.Start(ctx =>
{
var task1 = ctx.AddTask("Building docker things (1/15)");
log = LogMessage.InitialTaskStart.GetMessage();
var task2 = ctx.AddTask("Building dotnet projects");
Thread.Sleep(5000);
task1.Description("Building docker things (4/15)");
log = LogMessage.TaskProgressUpdate.GetMessage();
Thread.Sleep(5000);
task1.StopTask();
if (task1.IsFinished)
{
task1.Description("[Green]βœ“ DONE:[/] Building docker things (15/15)");
}
Thread.Sleep(2000);
var task3 = ctx.AddTask("Running db migrations");
task2.StopTask();
if (task2.IsFinished)
{
task2.Description("[Green]βœ“ DONE:[/] Building dotnet projects");
log = LogMessage.DatabaseMigration.GetMessage();
}
Thread.Sleep(5000);
task3.StopTask();
if (task3.IsFinished)
{
task3.Description("[Green]βœ“ DONE:[/] Running db migrations");
}
});
var buildDuration = DateTime.Now - buildStepStart;
AnsiConsole.MarkupLine($"βœ… [green]SUCCESS:[/] Container builds completed in [magenta]{buildDuration.TotalSeconds:F1}s[/]");
AnsiConsole.MarkupLine("Script logs at [teal]./logs[/]");
return buildDuration;
}
static TimeSpan RunStep3DeployAssets()
{
var deployStart = DateTime.Now;
AnsiConsole.MarkupLine("[bold]Step 3:[/] Deploy assets");
var log = "";
var pg = AnsiConsole.Progress()
.AutoClear(false)
.HideCompleted(false)
.Columns(
[
new SpinnerColumn(Spinner.Known.BouncingBar) { Style = Style.Parse("fuchsia") },
new TaskDescriptionColumn() { Alignment = Justify.Left },
new ElapsedTimeColumn() { Style = Style.Parse("fuchsia") },
])
.UseRenderHook((renderable, tasks) =>
{
var logLine = new Markup($"[dim]LOG: {log}[/]");
return new Rows(logLine, renderable);
}); pg.Start(ctx =>
{
var task1 = ctx.AddTask("Long running task like downloading files (1/15)");
log = LogMessage.DeploymentStarting.GetMessage();
var task2 = ctx.AddTask("Shorter task with indeterminate status");
Thread.Sleep(5000);
task1.Description("Long running task like downloading files (4/15)");
log = LogMessage.FilesProcessing.GetMessage();
Thread.Sleep(5000);
task1.StopTask();
if (task1.IsFinished)
{
task1.Description("[Green]βœ“ DONE:[/] Long running task like downloading files (15/15)");
}
Thread.Sleep(2000);
var task3 = ctx.AddTask("Third task");
task2.StopTask();
if (task2.IsFinished)
{
task2.Description("[Green]βœ“ DONE:[/] Shorter task with indeterminate status");
log = LogMessage.TaskCompleted.GetMessage();
}
Thread.Sleep(5000);
task3.StopTask();
if (task3.IsFinished)
{
task3.Description("[Green]βœ“ DONE:[/] Third task");
}
});
var deployDuration = DateTime.Now - deployStart;
AnsiConsole.MarkupLine($"βœ… [green]SUCCESS:[/] Deploy completed in [magenta]{deployDuration.TotalSeconds:F1}s[/]");
AnsiConsole.MarkupLine("🌐 [teal]https://mydeployment.com/test[/]"); return deployDuration;
}
static Rule CreateDivider()
{
var divider = new Rule();
divider.RuleStyle("magenta");
divider.LeftJustified();
divider.DoubleBorder();
return divider;
}
static void PrintDivider()
{
AnsiConsole.WriteLine();
AnsiConsole.Write(CreateDivider());
AnsiConsole.WriteLine();
}
public enum LogMessage
{
InitialTaskStart,
TaskProgressUpdate,
TaskCompleted,
DeploymentStarting,
FilesProcessing,
DatabaseMigration
}
public static class LogMessageExtensions
{
public static string GetMessage(this LogMessage logMessage) => logMessage switch
{
LogMessage.InitialTaskStart => "Starting initial task processing...",
LogMessage.TaskProgressUpdate => "Task is progressing, updating status...",
LogMessage.TaskCompleted => "Task has been completed successfully",
LogMessage.DeploymentStarting => "Beginning deployment sequence",
LogMessage.FilesProcessing => "Processing files and dependencies",
LogMessage.DatabaseMigration => "Running database migration scripts", _ => "Unknown log message"
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment