Skip to content

Commit

Permalink
Increase console verbosity to get better progress
Browse files Browse the repository at this point in the history
If no console logger is specified, add one with normal verbosity to increase from the default minimal. Only do this in non-CI and Windows env, which is verified to work.
  • Loading branch information
kzu committed Aug 7, 2024
1 parent 75bad3a commit 43f2da5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/dotnet-retest/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"profiles": {
"dotnet-retest": {
"commandName": "Project",
"commandLineArgs": "-- ..\\Sample\\Sample.csproj --logger \"html;logfilename=testResults.html\" --results-directory bin",
"workingDirectory": "."
"commandLineArgs": "",
"workingDirectory": "..\\Sample"
}
}
}
28 changes: 20 additions & 8 deletions src/dotnet-retest/RetestCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using CliWrap;
Expand Down Expand Up @@ -43,10 +44,16 @@ public override async Task<int> ExecuteAsync(CommandContext context, RetestSetti

string? path = null;
var hastrx = false;
var hasconsole = false;

new OptionSet
{
{ "l|logger=", v => hastrx = v.StartsWith("trx") },
{ "l|logger=", v =>
{
hastrx = v.StartsWith("trx");
hasconsole = v.StartsWith("console");
}
},
{ "results-directory=", v => path = v },
}.Parse(args);

Expand All @@ -66,6 +73,16 @@ public override async Task<int> ExecuteAsync(CommandContext context, RetestSetti
args.Insert(1, trx.Path);
}

var ci = Environment.GetEnvironmentVariable("CI") == "true";

// Ensure we add the console logger to get more detailed progress in non-CI environments
// Limiting to Windows which is what I personally tested. Linux fails with multiple loggers too.
if (!hasconsole && !ci && RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
args.Insert(0, "--logger");
args.Insert(1, "console;verbosity=normal");
}

// Ensure we add the trx logger. Note that there can be other loggers too
if (!hastrx)
{
Expand All @@ -79,15 +96,10 @@ public override async Task<int> ExecuteAsync(CommandContext context, RetestSetti
var attempts = 0;
BufferedCommandResult? runFailure = null;

var ci = Environment.GetEnvironmentVariable("CI") == "true";

ProgressColumn[] columns = ci ?
[new TaskDescriptionColumn { Alignment = Justify.Left }] :
[new SpinnerColumn(), new ElapsedTimeColumn(), new MultilineTaskDescriptionColumn()];

// 11 = spinner + elapsed time + padding
var maxwith = AnsiConsole.Console.Profile.Width - 11;

var exitCode = await Progress()
.Columns(columns)
.StartAsync(async ctx =>
Expand Down Expand Up @@ -115,11 +127,11 @@ public override async Task<int> ExecuteAsync(CommandContext context, RetestSetti
{
if (ci)
{
WriteLine(line);
WriteLine(line.EscapeMarkup());
}
else if (line.Trim() is { Length: > 0 } description)
{
task.Description = prefix + $": [grey]{description.Substring(0, Math.Min(maxwith - prefix.Length, description.Length))}...[/]";
task.Description = prefix + $": [grey]{description.EscapeMarkup()}[/]";
}
}));

Expand Down

0 comments on commit 43f2da5

Please sign in to comment.