Skip to content

Commit

Permalink
Replace file notices with an overall summary
Browse files Browse the repository at this point in the history
File notices don't seem to work as expected for us, see https://github.com/devlooped/dotnet-trx/actions/runs/9913373866.

So we instead just report the overall markup as the job summary.
  • Loading branch information
kzu committed Jul 12, 2024
1 parent aaa9b4d commit b7f95df
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/dotnet-trx/TrxCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,12 @@ public override int Execute(CommandContext context, TrxSettings settings)
if (Environment.GetEnvironmentVariable("CI") == "true")
{
GitHubReport(summary, details);
if (failures.Count > 0 && Environment.GetEnvironmentVariable("CI") == "true")
if (failures.Count > 0)
{
// Send workflow commands for each failure to be annotated in GH CI
foreach (var failure in failures)
WriteLine($"::error file={failure.File},line={failure.Line},title={failure.Title}::{failure.Message}");
// TODO: somehow the notice does not end up pointing to the right file/line
//foreach (var failure in failures)
// WriteLine($"::error file={failure.File},line={failure.Line},title={failure.Title}::{failure.Message}");
}
}

Expand Down Expand Up @@ -270,7 +271,7 @@ static void GitHubReport(Summary summary, StringBuilder details)

static string Link(string image, string? url) => url == null ? image + " " : $"[{image}]({url}) ";

static void AppendBadges(Summary summary, StringBuilder builder, string elapsed, string? jobUrl)
static StringBuilder AppendBadges(Summary summary, StringBuilder builder, string elapsed, string? jobUrl)
{
// ![5 passed](https://img.shields.io/badge/❌-linux%20in%2015m%206s-blue) ![5 passed](https://img.shields.io/badge/os-macOS%20✅-blue)
if (summary.Failed > 0)
Expand All @@ -288,6 +289,7 @@ static void AppendBadges(Summary summary, StringBuilder builder, string elapsed,
builder.Append(Link($"![{summary.Skipped} skipped](https://img.shields.io/badge/skipped-{summary.Skipped}-silver)", jobUrl));

builder.AppendLine();
return builder;
}

// Find potentially existing comment to update
Expand Down Expand Up @@ -343,6 +345,18 @@ static void AppendBadges(Summary summary, StringBuilder builder, string elapsed,
File.WriteAllText(input, body);
TryExecute("gh", $"pr comment {pr} --body-file {input}", out _);
}

if (Environment.GetEnvironmentVariable("GITHUB_STEP_SUMMARY") is { Length: > 0 } summaryPath &&
File.Exists(summaryPath))
{
File.AppendAllText(summaryPath,
AppendBadges(summary, new(), elapsed, jobUrl)
.AppendLine()
.Append(details)
.AppendLine()
.AppendLine($"from [dotnet-trx](https://github.com/devlooped/dotnet-trx) on {RuntimeInformation.FrameworkDescription} with [:purple_heart:](https://github.com/sponsors/devlooped)")
.ToString());
}
}

void WriteError(string baseDir, List<Failed> failures, XElement result, StringBuilder details)
Expand Down

0 comments on commit b7f95df

Please sign in to comment.