Created
June 18, 2025 21:11
-
-
Save maddymontaquila/35e47bdfa804ac9b4e96e5ddf0155388 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #:package Spectre.Console@0.50.0 | |
| using Spectre.Console; | |
| var start = DateTime.Now; | |
| // Header | |
| AnsiConsole.MarkupLine(":rocket: [bold]Deploying app to dev environment[/]"); | |
| AnsiConsole.WriteLine(); | |
| var publishDuration = RunStep1PublishAssets(); | |
| PrintDivider(); | |
| var buildDuration = RunStep2PreDeployScripts(); | |
| PrintDivider(); | |
| // var deployDuration = RunStep3DeployAssets(); | |
| // PrintDivider(); | |
| AnsiConsole.WriteLine(); | |
| // Summary | |
| var totalDuration = DateTime.Now - start; | |
| AnsiConsole.MarkupLine($"Deploy [red bold]failed[/] after {totalDuration.TotalSeconds:F1}s"); | |
| AnsiConsole.WriteLine(); | |
| static TimeSpan RunStep1PublishAssets() | |
| { | |
| var publishStart = DateTime.Now; | |
| AnsiConsole.MarkupLine("[bold]Step 1:[/] Publish 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(250); | |
| } | |
| 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(3000); | |
| task1.Description("Building docker things (4/15)"); | |
| log = LogMessage.TaskProgressUpdate.GetMessage(); | |
| Thread.Sleep(3000); | |
| 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("[Red]β ERROR: Running db migrations[/]"); | |
| } | |
| }); | |
| var buildDuration = DateTime.Now - buildStepStart; | |
| AnsiConsole.MarkupLine($"β [red]FAILED: Container builds failed in {buildDuration.TotalSeconds:F1}s with message (message)[/]"); | |
| AnsiConsole.MarkupLine("Logs located in [teal link]./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.Aesthetic) { Style = Style.Parse("magenta") }, | |
| // new TaskDescriptionColumn() { Alignment = Justify.Left }, | |
| // new ElapsedTimeColumn() { Style = Style.Parse("dim") }, | |
| // ]) | |
| // .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