Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 (totals, failures, slowest tests) to the file pointed to by `GITHUB_STEP_SUMMARY`, which GitHub renders on the workflow run summary page. Set it to `on-failure` to write only when the test invocation fails. 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.
- **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
Expand Up @@ -12,5 +12,6 @@ internal static class GitHubActionsCommandLineOptions
public const string GitHubActionsSlowTestNotices = "report-gh-slow-test-notices";
public const string GitHubActionsSlowTestThreshold = "report-gh-slow-test-threshold";

public const string StepSummaryOnFailureValue = "on-failure";
public const int SlowTestThresholdDefaultSeconds = 60;
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ public GitHubActionsCommandLineProvider()
public override Task<ValidationResult> ValidateOptionArgumentsAsync(CommandLineOption commandOption, string[] arguments)
=> commandOption.Name switch
{
GitHubActionsCommandLineOptions.GitHubActionsGroups or GitHubActionsCommandLineOptions.GitHubActionsAnnotations or GitHubActionsCommandLineOptions.GitHubActionsStepSummary or GitHubActionsCommandLineOptions.GitHubActionsSlowTestNotices
GitHubActionsCommandLineOptions.GitHubActionsStepSummary
when !CommandLineOptionArgumentValidator.IsValidBooleanArgument(arguments[0])
&& !arguments[0].Equals(GitHubActionsCommandLineOptions.StepSummaryOnFailureValue, StringComparison.OrdinalIgnoreCase)
=> ValidationResult.InvalidTask(string.Format(CultureInfo.InvariantCulture, GitHubActionsResources.InvalidStepSummaryValue, arguments[0])),
GitHubActionsCommandLineOptions.GitHubActionsGroups or GitHubActionsCommandLineOptions.GitHubActionsAnnotations or GitHubActionsCommandLineOptions.GitHubActionsSlowTestNotices
when !CommandLineOptionArgumentValidator.IsValidBooleanArgument(arguments[0])
=> ValidationResult.InvalidTask(string.Format(CultureInfo.InvariantCulture, GitHubActionsResources.InvalidOnOffValue, arguments[0])),
GitHubActionsCommandLineOptions.GitHubActionsSlowTestThreshold
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public static bool IsKnobEnabled(ICommandLineOptions commandLine, string knobOpt
&& arguments is [string value]
&& CommandLineOptionArgumentValidator.IsOffValue(value));

public static bool IsStepSummaryOnFailureOnly(ICommandLineOptions commandLine)
=> commandLine.TryGetOptionArgumentList(GitHubActionsCommandLineOptions.GitHubActionsStepSummary, out string[]? arguments)
&& arguments is [string value]
&& value.Equals(GitHubActionsCommandLineOptions.StepSummaryOnFailureValue, StringComparison.OrdinalIgnoreCase);

public static bool IsEnabled(ICommandLineOptions commandLine, IEnvironment environment, string knobOptionName)
=> IsMasterEnabled(commandLine, environment) && IsKnobEnabled(commandLine, knobOptionName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,15 @@ internal sealed class GitHubActionsSummaryArtifactPostProcessor(
await CiRunSummaryAggregation.WriteOutputAsync(outputPath, markdown).ConfigureAwait(false);

string? stepSummaryPath = environment.GetEnvironmentVariable(StepSummaryEnvironmentVariable);
if (!RoslynString.IsNullOrWhiteSpace(stepSummaryPath))
bool writeOnFailureOnly = aggregate.Modules.Count > 0
&& aggregate.Modules.All(static module => module.WriteOnFailureOnly);
bool runFailed = aggregate.IsPartial
|| aggregate.FailedTests > 0
|| (aggregate.ExitCode is int exitCode
? GitHubActionsExitCode.IndicatesFailure(exitCode)
: aggregate.Modules.Any(static module => GitHubActionsExitCode.IndicatesFailure(module.ExitCode)));
Comment thread
Evangelink marked this conversation as resolved.
Resolved
if (!RoslynString.IsNullOrWhiteSpace(stepSummaryPath)
&& (!writeOnFailureOnly || runFailed))
{
await GitHubActionsSummaryReporter.UpsertStepSummaryWithRetryAsync(
fileSystem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ internal sealed partial class GitHubActionsSummaryReporter :
private readonly ILogger _logger;
private readonly Lazy<string> _targetFrameworkMoniker;
private readonly bool _isEnabled;
private readonly bool _writeOnFailureOnly;
private readonly Func<bool> _shouldDeferToArtifactPostProcessing;

#if NET9_0_OR_GREATER
Expand Down Expand Up @@ -87,6 +88,7 @@ public GitHubActionsSummaryReporter(
_logger = loggerFactory.CreateLogger<GitHubActionsSummaryReporter>();
_targetFrameworkMoniker = new(TargetFrameworkMonikerHelper.GetTargetFrameworkMonikerIncludingPlatform);
_isEnabled = GitHubActionsFeature.IsEnabled(commandLineOptions, environment, GitHubActionsCommandLineOptions.GitHubActionsStepSummary);
_writeOnFailureOnly = GitHubActionsFeature.IsStepSummaryOnFailureOnly(commandLineOptions);
_shouldDeferToArtifactPostProcessing = shouldDeferToArtifactPostProcessing;
}

Expand Down Expand Up @@ -223,6 +225,13 @@ await _messageBus.PublishAsync(
return;
}

if (_writeOnFailureOnly
&& !snapshot.Any(static record => record.Kind == TerminalKind.Failed)
&& !GitHubActionsExitCode.IndicatesFailure(exitCode))
Comment thread
Evangelink marked this conversation as resolved.
Resolved
{
return;
}

string markdown = BuildMarkdown(snapshot, assemblyName, _targetFrameworkMoniker.Value, exitCode, coverage);

try
Expand Down Expand Up @@ -265,7 +274,8 @@ private CiRunSummaryModule CreateModule(
testSessionContext.SessionUid.Value,
GetAttemptNumber(),
_testApplicationProcessExitCode.GetProcessExitCode(),
coverage: coverage);
coverage: coverage,
writeOnFailureOnly: _writeOnFailureOnly);
Comment thread
Evangelink marked this conversation as resolved.
Resolved

private int GetAttemptNumber()
=> int.TryParse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ abstract Microsoft.Testing.Extensions.SlowTestReporterBase.GetDisplayLabel(Micro
Microsoft.Testing.Extensions.GitHubActionsReport.GitHubActionsAnnotationReporter.GitHubActionsAnnotationReporter(Microsoft.Testing.Platform.CommandLine.ICommandLineOptions! commandLine, Microsoft.Testing.Platform.Helpers.IEnvironment! environment, Microsoft.Testing.Platform.Helpers.IFileSystem! fileSystem, Microsoft.Testing.Platform.OutputDevice.IOutputDevice! outputDisplay, Microsoft.Testing.Platform.Services.ITestApplicationProcessExitCode! testApplicationProcessExitCode, Microsoft.Testing.Platform.Logging.ILoggerFactory! loggerFactory) -> void
Microsoft.Testing.Extensions.GitHubActionsReport.GitHubActionsAnnotationReporter.OnTestSessionFinishingAsync(Microsoft.Testing.Platform.Services.ITestSessionContext! testSessionContext) -> System.Threading.Tasks.Task!
Microsoft.Testing.Extensions.GitHubActionsReport.GitHubActionsAnnotationReporter.OnTestSessionStartingAsync(Microsoft.Testing.Platform.Services.ITestSessionContext! testSessionContext) -> System.Threading.Tasks.Task!
const Microsoft.Testing.Extensions.GitHubActionsReport.GitHubActionsCommandLineOptions.StepSummaryOnFailureValue = "on-failure" -> string!
override Microsoft.Testing.Extensions.GitHubActionsReport.GitHubActionsCommandLineProvider.ValidateCommandLineOptionsAsync(Microsoft.Testing.Platform.CommandLine.ICommandLineOptions! commandLineOptions) -> System.Threading.Tasks.Task<Microsoft.Testing.Platform.Extensions.ValidationResult>!
Microsoft.Testing.Extensions.GitHubActionsReport.GitHubActionsExitCode
Microsoft.Testing.Extensions.GitHubActionsReport.GitHubActionsSummaryReporter.GitHubActionsSummaryReporter(Microsoft.Testing.Platform.CommandLine.ICommandLineOptions! commandLineOptions, Microsoft.Testing.Platform.Configurations.IConfiguration! configuration, Microsoft.Testing.Platform.Helpers.IEnvironment! environment, Microsoft.Testing.Platform.Helpers.IFileSystem! fileSystem, Microsoft.Testing.Platform.Messages.IMessageBus! messageBus, Microsoft.Testing.Platform.OutputDevice.IOutputDevice! outputDevice, Microsoft.Testing.Platform.Services.ITestApplicationModuleInfo! testApplicationModuleInfo, Microsoft.Testing.Platform.Services.ITestApplicationProcessExitCode! testApplicationProcessExitCode, Microsoft.Testing.Platform.Services.ITestCoverageResult! testCoverageResult, Microsoft.Testing.Platform.Logging.ILoggerFactory! loggerFactory, System.Func<bool>! shouldDeferToArtifactPostProcessing) -> void
Expand All @@ -16,6 +17,7 @@ static Microsoft.Testing.Extensions.GitHubActionsReport.GitHubActionsExitCode.Ge
static Microsoft.Testing.Extensions.GitHubActionsReport.GitHubActionsExitCode.GetReason(int exitCode) -> string!
static Microsoft.Testing.Extensions.GitHubActionsReport.GitHubActionsExitCode.IndicatesFailure(int exitCode) -> bool
static Microsoft.Testing.Extensions.GitHubActionsReport.GitHubActionsExitCode.IsTestResultOutcome(int exitCode) -> bool
static Microsoft.Testing.Extensions.GitHubActionsReport.GitHubActionsFeature.IsStepSummaryOnFailureOnly(Microsoft.Testing.Platform.CommandLine.ICommandLineOptions! commandLine) -> bool
static Microsoft.Testing.Extensions.GitHubActionsReport.GitHubActionsSlowTestReporter.BuildNoticeLine(string! testLabel, System.TimeSpan elapsed) -> string!
static Microsoft.Testing.Extensions.GitHubActionsReport.GitHubActionsSummaryReporter.BuildMarkdown(System.Collections.Generic.IReadOnlyList<Microsoft.Testing.Extensions.TestRecord>! records, string! assemblyName, string! targetFrameworkMoniker, int exitCode) -> string!
static Microsoft.Testing.Extensions.GitHubActionsReport.GitHubActionsSummaryReporter.BuildAggregateMarkdown(Microsoft.Testing.Extensions.CiRunSummaryAggregate! aggregate) -> string!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The extension activates when the test run is on GitHub Actions (`GITHUB_ACTIONS=
| `--report-gh` | Master switch that turns the extension on (required, in addition to running on GitHub Actions) | off |
| `--report-gh-groups on\|off` | Per-assembly log groups | on |
| `--report-gh-annotations on\|off` | Failure and skip annotations | on |
| `--report-gh-step-summary on\|off` | Markdown job summary | on |
| `--report-gh-step-summary on\|off\|on-failure` | Markdown job summary; `on-failure` writes it only when the test invocation fails | on |
| `--report-gh-slow-test-notices on\|off` | Slow-test notices | on |
| `--report-gh-slow-test-threshold <duration>` | Time before a slow-test notice is emitted; accepts a bare number of seconds or a unit suffix such as `90s`, `2m`, `1.5h` | 60s |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@
<value>The test was skipped without providing a reason.</value>
</data>
<data name="StepSummaryOptionDescription" xml:space="preserve">
<value>Enable or disable writing a markdown job summary to the GITHUB_STEP_SUMMARY file. Valid values are 'on' (also accepts 'true', 'enable', '1') or 'off' (also accepts 'false', 'disable', '0'). Defaults to 'on' when running on GitHub Actions.</value>
<comment>{Locked="on"}{Locked="off"}{Locked="true"}{Locked="enable"}{Locked="1"}{Locked="false"}{Locked="disable"}{Locked="0"}{Locked="GITHUB_STEP_SUMMARY"}</comment>
<value>Control writing a markdown job summary to the GITHUB_STEP_SUMMARY file. Valid values are 'on' (also accepts 'true', 'enable', '1'), 'off' (also accepts 'false', 'disable', '0'), or 'on-failure' to write only when the test invocation fails. Defaults to 'on' when running on GitHub Actions.</value>
<comment>{Locked="'on'"}{Locked="'off'"}{Locked="'true'"}{Locked="'enable'"}{Locked="'1'"}{Locked="'false'"}{Locked="'disable'"}{Locked="'0'"}{Locked="'on-failure'"}{Locked="GITHUB_STEP_SUMMARY"}</comment>
</data>
<data name="StepSummaryWriteFailedWarning" xml:space="preserve">
<value>Failed to write the GitHub Actions job summary to '{0}': {1}</value>
Expand Down Expand Up @@ -122,6 +122,10 @@
<value>Invalid value '{0}'. Valid values are 'on' (or 'true', 'enable', '1') or 'off' (or 'false', 'disable', '0').</value>
<comment>{Locked="on"}{Locked="off"}{Locked="true"}{Locked="enable"}{Locked="1"}{Locked="false"}{Locked="disable"}{Locked="0"}</comment>
</data>
<data name="InvalidStepSummaryValue" xml:space="preserve">
<value>Invalid value '{0}'. Valid values are 'on' (or 'true', 'enable', '1'), 'off' (or 'false', 'disable', '0'), or 'on-failure'.</value>
<comment>{Locked="'on'"}{Locked="'off'"}{Locked="'true'"}{Locked="'enable'"}{Locked="'1'"}{Locked="'false'"}{Locked="'disable'"}{Locked="'0'"}{Locked="'on-failure'"}{0} is the invalid value.</comment>
</data>
<data name="SubOptionsRequireReportGh" xml:space="preserve">
<value>The GitHub Actions report sub-options require '--{0}' to be specified.</value>
<comment>Validation error when a sub-option is used without the report option. {0} is the report option name. {Locked="'--{0}'"}</comment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@
<target state="new">Invalid value '{0}'. The slow-test threshold must be a positive duration, e.g. '60', '90s', or '2m'.</target>
<note>{Locked="s"}{Locked="m"}</note>
</trans-unit>
<trans-unit id="InvalidStepSummaryValue">
<source>Invalid value '{0}'. Valid values are 'on' (or 'true', 'enable', '1'), 'off' (or 'false', 'disable', '0'), or 'on-failure'.</source>
<target state="new">Invalid value '{0}'. Valid values are 'on' (or 'true', 'enable', '1'), 'off' (or 'false', 'disable', '0'), or 'on-failure'.</target>
<note>{Locked="'on'"}{Locked="'off'"}{Locked="'true'"}{Locked="'enable'"}{Locked="'1'"}{Locked="'false'"}{Locked="'disable'"}{Locked="'0'"}{Locked="'on-failure'"}{0} is the invalid value.</note>
</trans-unit>
<trans-unit id="NoFailureMessageFallback">
<source>The test failed without providing a failure message.</source>
<target state="translated">Test neproběhl úspěšně bez poskytnutí zprávy o chybě.</target>
Expand Down Expand Up @@ -168,9 +173,9 @@
<note>{Locked="s"}{Locked="m"}{Locked="h"}</note>
</trans-unit>
<trans-unit id="StepSummaryOptionDescription">
<source>Enable or disable writing a markdown job summary to the GITHUB_STEP_SUMMARY file. Valid values are 'on' (also accepts 'true', 'enable', '1') or 'off' (also accepts 'false', 'disable', '0'). Defaults to 'on' when running on GitHub Actions.</source>
<target state="new">Enable or disable writing a markdown job summary to the GITHUB_STEP_SUMMARY file. Valid values are 'on' (also accepts 'true', 'enable', '1') or 'off' (also accepts 'false', 'disable', '0'). Defaults to 'on' when running on GitHub Actions.</target>
<note>{Locked="on"}{Locked="off"}{Locked="true"}{Locked="enable"}{Locked="1"}{Locked="false"}{Locked="disable"}{Locked="0"}{Locked="GITHUB_STEP_SUMMARY"}</note>
<source>Control writing a markdown job summary to the GITHUB_STEP_SUMMARY file. Valid values are 'on' (also accepts 'true', 'enable', '1'), 'off' (also accepts 'false', 'disable', '0'), or 'on-failure' to write only when the test invocation fails. Defaults to 'on' when running on GitHub Actions.</source>
<target state="new">Control writing a markdown job summary to the GITHUB_STEP_SUMMARY file. Valid values are 'on' (also accepts 'true', 'enable', '1'), 'off' (also accepts 'false', 'disable', '0'), or 'on-failure' to write only when the test invocation fails. Defaults to 'on' when running on GitHub Actions.</target>
<note>{Locked="'on'"}{Locked="'off'"}{Locked="'true'"}{Locked="'enable'"}{Locked="'1'"}{Locked="'false'"}{Locked="'disable'"}{Locked="'0'"}{Locked="'on-failure'"}{Locked="GITHUB_STEP_SUMMARY"}</note>
</trans-unit>
<trans-unit id="StepSummaryWriteFailedWarning">
<source>Failed to write the GitHub Actions job summary to '{0}': {1}</source>
Expand Down
Loading
Loading