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 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.
- **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. Set it to `on-failure` to write only when the test invocation fails. `--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
Expand Up @@ -15,6 +15,7 @@ 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,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 GitHubActionsStepSummarySections _sections;
private readonly Func<bool> _shouldDeferToArtifactPostProcessing;

Expand Down Expand Up @@ -88,6 +89,7 @@ public GitHubActionsSummaryReporter(
_logger = loggerFactory.CreateLogger<GitHubActionsSummaryReporter>();
_targetFrameworkMoniker = new(TargetFrameworkMonikerHelper.GetTargetFrameworkMonikerIncludingPlatform);
_isEnabled = GitHubActionsFeature.IsEnabled(commandLineOptions, environment, GitHubActionsCommandLineOptions.GitHubActionsStepSummary);
_writeOnFailureOnly = GitHubActionsFeature.IsStepSummaryOnFailureOnly(commandLineOptions);
_sections = GitHubActionsStepSummarySectionsParser.GetSections(commandLineOptions);
_shouldDeferToArtifactPostProcessing = shouldDeferToArtifactPostProcessing;
}
Expand Down Expand Up @@ -225,6 +227,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, _sections);

try
Expand Down Expand Up @@ -268,7 +277,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
module.GitHubActionsStepSummarySections = GitHubActionsStepSummarySectionsParser.ToPersistedValues(_sections);
return module;
}
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.GitHubActionsStepSummarySections
Expand All @@ -23,6 +24,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.GitHubActionsStepSummarySectionsParser.GetAggregateSections(System.Collections.Generic.IReadOnlyList<Microsoft.Testing.Extensions.CiRunSummaryModule!>! modules) -> Microsoft.Testing.Extensions.GitHubActionsReport.GitHubActionsStepSummarySections
static Microsoft.Testing.Extensions.GitHubActionsReport.GitHubActionsStepSummarySectionsParser.GetSections(Microsoft.Testing.Platform.CommandLine.ICommandLineOptions! commandLineOptions) -> Microsoft.Testing.Extensions.GitHubActionsReport.GitHubActionsStepSummarySections
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-step-summary-sections <section>...` | Job-summary content: `test-results`, `coverage`, `slow-tests`, or `all`; accepts repeated, space-separated, and comma-separated values | `all` |
| `--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="StepSummarySectionsOptionDescription" xml:space="preserve">
<value>Select the content included in the GitHub Actions job summary. Specify one or more values, repeated, space-separated, or comma-separated: 'test-results', 'slow-tests', 'coverage', or 'all'. Defaults to 'all'. Requires '--report-gh'.</value>
Expand Down Expand Up @@ -134,6 +134,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 @@ -137,6 +137,11 @@
<target state="new">Invalid GitHub Actions job-summary section '{0}'. Valid values are 'test-results', 'slow-tests', 'coverage', or 'all'. Values can be repeated, space-separated, or comma-separated.</target>
<note>{0} is the invalid section name. {Locked="'test-results'"}{Locked="'slow-tests'"}{Locked="'coverage'"}{Locked="'all'"}</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 @@ -178,9 +183,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="StepSummarySectionsOptionDescription">
<source>Select the content included in the GitHub Actions job summary. Specify one or more values, repeated, space-separated, or comma-separated: 'test-results', 'slow-tests', 'coverage', or 'all'. Defaults to 'all'. Requires '--report-gh'.</source>
Expand Down
Loading