Skip to content

Commit

Permalink
Merge pull request #347 from unoplatform/dev/jela/adjust-skip
Browse files Browse the repository at this point in the history
fix: Show the skipped checks reasons
  • Loading branch information
jeromelaban authored Feb 25, 2025
2 parents 22c4982 + a13167c commit 19937a4
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 27 deletions.
82 changes: 59 additions & 23 deletions UnoCheck/CheckCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,12 @@ public override async Task<int> ExecuteAsync(CommandContext context, CheckSettin

AnsiConsole.MarkupLine(" ok");
AnsiConsole.Markup($"[bold blue]{Icon.Thinking} Scheduling appointments...[/]");
Util.UpdateSkips(settings, Util.BaseSkips);

SkipInfo[] skipList = (settings.Skip ?? [])
.Select(s => new SkipInfo(s, "Skipped by command line", false))
.Concat(Util.BaseSkips.Select(s => new SkipInfo(s, "Not required by the current configuration", false)))
.Distinct(SkipInfo.NameOnlyComparer)
.ToArray();

if (!string.IsNullOrEmpty(settings.DotNetSdkRoot))
{
Expand All @@ -108,20 +113,23 @@ public override async Task<int> ExecuteAsync(CommandContext context, CheckSettin
sharedState.SetEnvironmentVariable("UnoSdkVersion", settings.UnoSdkVersion);
if (settings.Frameworks is { Length: > 0 })
settings.TargetPlatforms = ParseTfmsToTargetPlatforms(settings);

if (!string.IsNullOrEmpty(settings.Ide))
{
switch (settings.Ide.ToLowerInvariant())
{
case "rider":
Util.UpdateSkips(settings, Util.RiderSkips);
break;
case "vs":
Util.UpdateSkips(settings, Util.VSSkips);
break;
case "vscode":
Util.UpdateSkips(settings, Util.VSCodeSkips);
break;
}
skipList = skipList.Concat(
(
settings.Ide.ToLowerInvariant() switch
{
"rider" => Util.RiderSkips,
"vs" => Util.VSSkips,
"vscode" => Util.VSCodeSkips,
_ => []
}
)
.Select(s => new SkipInfo(s, "Not required by the current configuration", false))
)
.Distinct(SkipInfo.NameOnlyComparer)
.ToArray();
}

sharedState.ContributeState(StateKey.EntryPoint, StateKey.TargetPlatforms, TargetPlatformHelper.GetTargetPlatformsFromFlags(settings.TargetPlatforms));
Expand Down Expand Up @@ -151,7 +159,7 @@ public override async Task<int> ExecuteAsync(CommandContext context, CheckSettin
continue;
}

var skipCheckup = false;
SkipInfo skipCheckup = null;

var dependencies = checkup.DeclareDependencies(checkups.Select(c => c.Id));

Expand All @@ -166,24 +174,35 @@ public override async Task<int> ExecuteAsync(CommandContext context, CheckSettin
{
if (!checkupStatus.TryGetValue(dep.CheckupId, out var depStatus) || depStatus == Models.Status.Error)
{
skipCheckup = dep.IsRequired;
if (dep.IsRequired)
{
skipCheckup = new(checkup.Id, $"The dependent check {dep.CheckupId} is required first", true);
}
break;
}
}
}
}

// See if --skip was specified
if (settings.Skip?.Any(s => s.Equals(checkup.Id, StringComparison.OrdinalIgnoreCase)
|| s.Equals(checkup.GetType().Name, StringComparison.OrdinalIgnoreCase)) ?? false)
skipCheckup = true;
// See if --skip was specified
if(skipList?.FirstOrDefault(s =>
s.CheckupId.Equals(checkup.Id, StringComparison.OrdinalIgnoreCase)
|| s.CheckupId.Equals(checkup.GetType().Name, StringComparison.OrdinalIgnoreCase)) is { } explicitSkip)
{
skipCheckup = explicitSkip;
}

if (skipCheckup)
if (skipCheckup is not null)
{
skippedChecks.Add(checkup.Id);
checkupStatus[checkup.Id] = Models.Status.Error;
checkupStatus[checkup.Id] = skipCheckup.isError ? Models.Status.Error : Models.Status.Ok;
AnsiConsole.WriteLine();
AnsiConsole.MarkupLine($"[bold red]{Icon.Error} Skipped: " + checkup.Title + "[/]");

var icon = skipCheckup.isError
? $"[bold red]{Icon.Error}"
: $"[bold gray]{Icon.Ignored}";

AnsiConsole.MarkupLine($"{icon} Skipped: {checkup.Title} ({skipCheckup.skipReason})[/]");
continue;
}

Expand Down Expand Up @@ -469,5 +488,22 @@ private void RemedyStatusUpdated(object sender, RemedyStatusEventArgs e)
{
AnsiConsole.MarkupLine(" " + e.Message);
}
}

private record SkipInfo(string CheckupId, string skipReason, bool isError)
{
public static IEqualityComparer<SkipInfo> NameOnlyComparer { get; } = new SkipInfoNameOnlyComparer();

private class SkipInfoNameOnlyComparer : IEqualityComparer<SkipInfo>
{
public bool Equals(SkipInfo x, SkipInfo y)
{
return x.CheckupId.Equals(y.CheckupId, StringComparison.OrdinalIgnoreCase);
}
public int GetHashCode(SkipInfo obj)
{
return obj.CheckupId.GetHashCode();
}
}
}
}
}
8 changes: 7 additions & 1 deletion UnoCheck/Icon.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace DotNetCheck
using Spectre.Console;

namespace DotNetCheck
{
public static class Icon
{
Expand All @@ -15,6 +17,10 @@ public static string ListItem

public static string Checking
=> PrettyBoring(":magnifying_glass_tilted_right:", "›");

public static string Ignored
=> PrettyBoring($"{Emoji.Known.RightArrowCurvingDown}", "¬");

public static string Recommend
=> PrettyBoring(":syringe:", "¤");

Expand Down
4 changes: 2 additions & 2 deletions UnoCheck/Telemetry/TelemetryClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public static void TrackStartCheck(string[] requestedFrameworks)
// Remove strings that are not of the format net8.0 or net8.0-XXXXX, using a regex
var frameworks = string.Join(
",",
requestedFrameworks
requestedFrameworks?
.OrderBy(s => s)
.Where(f => System.Text.RegularExpressions.Regex.IsMatch(f, @"^net\d+(\.0)(?:-[a-zA-Z0-9.]+)*$"))
.Select(s => s[..32])
.Take(10));
.Take(10) ?? []);

_telemetry.TrackEvent(
"check-start",
Expand Down
2 changes: 1 addition & 1 deletion UnoCheck/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public static bool Delete(string path, bool isFile)
public static Task<ShellProcessRunner.ShellProcessResult> WrapShellCommandWithSudo(string cmd, string[] args)
=> WrapShellCommandWithSudo(cmd, null, false, args);

public static Task<ShellProcessRunner.ShellProcessResult> WrapShellCommandWithSudo(string cmd, string workingDir, bool verbose, string[] args)
public static Task<ShellProcessRunner.ShellProcessResult> WrapShellCommandWithSudo(string cmd, string workingDir, bool verbose, string[] args)
{
var actualCmd = cmd;
var actualArgs = string.Join(" ", args);
Expand Down

0 comments on commit 19937a4

Please sign in to comment.