Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ An MTP extension (`Microsoft.Testing.Extensions.GitHubActionsReport`) that emits

- **Per-assembly log groups** (`--report-gh-groups`): emits `::group::`/`::endgroup::` workflow commands so each test assembly's output is collapsed by default in the runner UI.
- **Failure and skip annotations** (`--report-gh-annotations`): emits a `::error` workflow command for each failing test and a `::warning` workflow command for each skipped test; both surface in the workflow **Annotations** tab. The `file:line` location is taken from the failure's exception stack trace when a frame resolves inside the workspace, and otherwise from the test's own `TestFileLocationProperty` (the only location available for a skipped test), so annotations also appear on the PR "Files changed" diff gutter. `TestFileLocationProperty` is populated by the MSTest adapter and by the [VSTestBridge](#vstestbridge), which covers xUnit/NUnit and other bridged frameworks that report source information.
- **Job summary** (`--report-gh-step-summary`): writes a markdown roll-up (totals, failures, slowest tests) to the file pointed to by `GITHUB_STEP_SUMMARY`, which GitHub renders on the workflow run summary page. A capable SDK aggregates multi-module `dotnet test` runs into one authoritative overall section with per-assembly detail through artifact post-processing; older SDKs retain direct per-assembly sections.
- **Job summary** (`--report-gh-step-summary`): writes a markdown roll-up to the file pointed to by `GITHUB_STEP_SUMMARY`, which GitHub renders on the workflow run summary page. `--report-gh-step-summary-sections` independently selects `test-results`, `coverage`, `slow-tests`, or any combination (`all`, the default); values may be repeated, space-separated, or comma-separated. A capable SDK aggregates multi-module `dotnet test` runs into one authoritative overall section with per-assembly detail through artifact post-processing; mixed module selections are combined so the aggregate includes every requested section, and older fragments retain full output.
- **Slow-test notices** (`--report-gh-slow-test-notices`): emits a `::notice` workflow command for any test running past a configured threshold (default 60 seconds; set with `--report-gh-slow-test-threshold`).

When using [MSTest.Sdk](#mstestsdk), opt in with `<EnableMicrosoftTestingExtensionsGitHubActionsReport>true</EnableMicrosoftTestingExtensionsGitHubActionsReport>`; the extension is enabled automatically when `TestingExtensionsProfile` is set to `AllMicrosoft`. It is not supported in NativeAOT mode (MSTest.Sdk emits a build warning) or VSTest mode. Introduced in [PR #9541](https://github.com/microsoft/testfx/pull/9541); skipped-test `::warning` annotations were added in [PR #9641](https://github.com/microsoft/testfx/pull/9641).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Testing.Platform.CommandLine;

namespace Microsoft.Testing.Extensions.GitHubActionsReport;

internal static class GitHubActionsCommandLineOptions
Expand All @@ -9,8 +11,135 @@ internal static class GitHubActionsCommandLineOptions
public const string GitHubActionsGroups = "report-gh-groups";
public const string GitHubActionsAnnotations = "report-gh-annotations";
public const string GitHubActionsStepSummary = "report-gh-step-summary";
public const string GitHubActionsStepSummarySections = "report-gh-step-summary-sections";
public const string GitHubActionsSlowTestNotices = "report-gh-slow-test-notices";
public const string GitHubActionsSlowTestThreshold = "report-gh-slow-test-threshold";

public const int SlowTestThresholdDefaultSeconds = 60;
}

[Flags]
internal enum GitHubActionsStepSummarySections
{
None = 0,
TestResults = 1,
SlowTests = 2,
Coverage = 4,
All = TestResults | SlowTests | Coverage,
}

internal static class GitHubActionsStepSummarySectionsParser
{
internal const string AllSectionName = "all";
internal const string CoverageSectionName = "coverage";
internal const string SlowTestsSectionName = "slow-tests";
internal const string TestResultsSectionName = "test-results";

public static GitHubActionsStepSummarySections GetSections(ICommandLineOptions commandLineOptions)
=> !commandLineOptions.TryGetOptionArgumentList(
GitHubActionsCommandLineOptions.GitHubActionsStepSummarySections,
out string[]? arguments)
? GitHubActionsStepSummarySections.All
: TryParse(arguments, out GitHubActionsStepSummarySections sections, out _, out _)
? sections
: throw new InvalidOperationException("The GitHub Actions step-summary sections were not validated.");

public static bool TryParse(
IReadOnlyList<string> arguments,
out GitHubActionsStepSummarySections sections,
out string? invalidValue,
out bool hasEmptyValue)
{
sections = GitHubActionsStepSummarySections.None;
invalidValue = null;
hasEmptyValue = false;

foreach (string argument in arguments)
{
string[] values = argument.Split(',');
foreach (string normalizedValue in values.Select(static value => value.Trim()))
{
if (normalizedValue.Length == 0)
{
hasEmptyValue = true;
return false;
}

switch (normalizedValue.ToLowerInvariant())
{
case TestResultsSectionName:
sections |= GitHubActionsStepSummarySections.TestResults;
break;
case SlowTestsSectionName:
sections |= GitHubActionsStepSummarySections.SlowTests;
break;
case CoverageSectionName:
sections |= GitHubActionsStepSummarySections.Coverage;
break;
case AllSectionName:
sections = GitHubActionsStepSummarySections.All;
break;
default:
invalidValue = normalizedValue;
return false;
}
}
}

if (sections == GitHubActionsStepSummarySections.None)
{
hasEmptyValue = true;
return false;
}

return true;
}

public static string[] ToPersistedValues(GitHubActionsStepSummarySections sections)
{
var values = new List<string>(2);
if ((sections & GitHubActionsStepSummarySections.TestResults) != 0)
{
values.Add(TestResultsSectionName);
}

if ((sections & GitHubActionsStepSummarySections.SlowTests) != 0)
{
values.Add(SlowTestsSectionName);
}

if ((sections & GitHubActionsStepSummarySections.Coverage) != 0)
{
values.Add(CoverageSectionName);
}

return [.. values];
}

public static GitHubActionsStepSummarySections GetAggregateSections(IReadOnlyList<CiRunSummaryModule> modules)
{
if (modules.Count == 0)
{
return GitHubActionsStepSummarySections.All;
}

GitHubActionsStepSummarySections sections = GitHubActionsStepSummarySections.None;
foreach (CiRunSummaryModule module in modules)
{
string[]? persistedValues = module.GitHubActionsStepSummarySections;
if (persistedValues is null
|| !TryParse(persistedValues, out GitHubActionsStepSummarySections moduleSections, out _, out _))
{
return GitHubActionsStepSummarySections.All;
}

sections |= moduleSections;
if (sections == GitHubActionsStepSummarySections.All)
{
return sections;
}
}

return sections;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public GitHubActionsCommandLineProvider()
new CommandLineOption(GitHubActionsCommandLineOptions.GitHubActionsGroups, GitHubActionsResources.GroupsOptionDescription, ArgumentArity.ExactlyOne, false),
new CommandLineOption(GitHubActionsCommandLineOptions.GitHubActionsAnnotations, GitHubActionsResources.AnnotationsOptionDescription, ArgumentArity.ExactlyOne, false),
new CommandLineOption(GitHubActionsCommandLineOptions.GitHubActionsStepSummary, GitHubActionsResources.StepSummaryOptionDescription, ArgumentArity.ExactlyOne, false),
new CommandLineOption(GitHubActionsCommandLineOptions.GitHubActionsStepSummarySections, GitHubActionsResources.StepSummarySectionsOptionDescription, ArgumentArity.OneOrMore, false),
new CommandLineOption(GitHubActionsCommandLineOptions.GitHubActionsSlowTestNotices, GitHubActionsResources.SlowTestNoticesOptionDescription, ArgumentArity.ExactlyOne, false),
new CommandLineOption(GitHubActionsCommandLineOptions.GitHubActionsSlowTestThreshold, GitHubActionsResources.SlowTestThresholdOptionDescription, ArgumentArity.ExactlyOne, false),
new CommandLineOption(GitHubActionsCommandLineOptions.GitHubActionsOptionName, GitHubActionsResources.OptionDescription, ArgumentArity.Zero, false),
Expand All @@ -38,6 +39,12 @@ GitHubActionsCommandLineOptions.GitHubActionsGroups or GitHubActionsCommandLineO
GitHubActionsCommandLineOptions.GitHubActionsSlowTestThreshold
when !(TimeSpanParser.TryParse(arguments[0], TimeSpanDefaultUnit.Seconds, out TimeSpan threshold) && threshold > TimeSpan.Zero)
=> ValidationResult.InvalidTask(string.Format(CultureInfo.InvariantCulture, GitHubActionsResources.InvalidSlowTestThreshold, arguments[0])),
GitHubActionsCommandLineOptions.GitHubActionsStepSummarySections
when !GitHubActionsStepSummarySectionsParser.TryParse(arguments, out _, out string? invalidValue, out bool hasEmptyValue)
=> ValidationResult.InvalidTask(
hasEmptyValue
? GitHubActionsResources.EmptyStepSummarySections
: string.Format(CultureInfo.InvariantCulture, GitHubActionsResources.InvalidStepSummarySection, invalidValue)),
_ => ValidationResult.ValidTask,
};

Expand All @@ -48,6 +55,7 @@ public override Task<ValidationResult> ValidateCommandLineOptionsAsync(ICommandL
GitHubActionsCommandLineOptions.GitHubActionsGroups,
GitHubActionsCommandLineOptions.GitHubActionsAnnotations,
GitHubActionsCommandLineOptions.GitHubActionsStepSummary,
GitHubActionsCommandLineOptions.GitHubActionsStepSummarySections,
GitHubActionsCommandLineOptions.GitHubActionsSlowTestNotices,
GitHubActionsCommandLineOptions.GitHubActionsSlowTestThreshold,
],
Expand Down
Loading