Skip to content

Commit 39f9f28

Browse files
nohwnd-botEvangelinkCopilot
authored
Emit ::warning annotations for skipped tests in GitHubActionsReport by @Evangelink in #9641 (backport to rel/4.3) (#9644)
Co-authored-by: Amaury Levé <amauryleve@microsoft.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 55e54e0 commit 39f9f28

18 files changed

Lines changed: 227 additions & 32 deletions

‎src/Platform/Microsoft.Testing.Extensions.GitHubActionsReport/GitHubActionsAnnotationReporter.cs‎

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ namespace Microsoft.Testing.Extensions.GitHubActionsReport;
1515
/// <summary>
1616
/// Emits a GitHub Actions <c>::error</c> workflow command for each failing test so the failure surfaces
1717
/// both in the workflow run's Annotations tab and, when the source location can be resolved, on the
18-
/// pull request's "Files changed" diff gutter.
18+
/// pull request's "Files changed" diff gutter. Skipped tests are surfaced as title-only <c>::warning</c>
19+
/// workflow commands so they are visible in the Annotations tab too.
1920
/// </summary>
2021
internal sealed class GitHubActionsAnnotationReporter :
2122
IDataConsumer,
@@ -87,6 +88,14 @@ public async Task ConsumeAsync(IDataProducer dataProducer, IData value, Cancella
8788

8889
if (failure is null)
8990
{
91+
// Skipped tests carry no exception (and therefore no source location); surface them as a
92+
// title-only '::warning' so intentionally or unexpectedly skipped tests are visible in the
93+
// workflow Annotations tab alongside failures, rather than being silently absent.
94+
if (nodeState is SkippedTestNodeStateProperty skipped)
95+
{
96+
await WriteSkippedAnnotationAsync(GetTestName(nodeUpdateMessage.TestNode), skipped.Explanation, cancellationToken).ConfigureAwait(false);
97+
}
98+
9099
return;
91100
}
92101

@@ -155,6 +164,39 @@ private async Task WriteAnnotationAsync(string testName, string? explanation, Ex
155164
GitHubActionsEscaper.EscapeData(message));
156165
}
157166

167+
private async Task WriteSkippedAnnotationAsync(string testName, string? explanation, CancellationToken cancellationToken)
168+
{
169+
if (_logger.IsEnabled(LogLevel.Trace))
170+
{
171+
_logger.LogTrace("Skip received.");
172+
}
173+
174+
string line = GetSkippedAnnotation(testName, explanation);
175+
176+
if (_logger.IsEnabled(LogLevel.Trace))
177+
{
178+
_logger.LogTrace($"Showing skip annotation '{line}'.");
179+
}
180+
181+
// Prepend a newline for the same reason as the failure annotation: it guarantees the '::warning'
182+
// workflow command starts at column 0 on its own line so GitHub recognizes it.
183+
await _outputDisplay.DisplayAsync(this, new FormattedTextOutputDeviceData($"\n{line}"), cancellationToken).ConfigureAwait(false);
184+
}
185+
186+
internal static /* for testing */ string GetSkippedAnnotation(string testName, string? explanation)
187+
{
188+
string message = explanation ?? GitHubActionsResources.NoSkipReasonFallback;
189+
string title = string.Format(CultureInfo.InvariantCulture, GitHubActionsResources.SkippedAnnotationTitle, testName);
190+
191+
// Skipped nodes never carry a stack trace, so there is no file/line to pin the annotation to; a
192+
// title-only '::warning' still surfaces in the workflow Annotations tab.
193+
return string.Format(
194+
CultureInfo.InvariantCulture,
195+
"::warning title={0}::{1}",
196+
GitHubActionsEscaper.EscapeProperty(title),
197+
GitHubActionsEscaper.EscapeData(message));
198+
}
199+
158200
private static string GetTestName(TestNode testNode)
159201
=> TestNodeIdentity.GetTestName(testNode);
160202

‎src/Platform/Microsoft.Testing.Extensions.GitHubActionsReport/PACKAGE.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ dotnet add package Microsoft.Testing.Extensions.GitHubActionsReport
1515
This package extends Microsoft.Testing.Platform with:
1616

1717
- **Per-assembly log groups**: emits `::group::` / `::endgroup::` workflow commands so each test assembly's output is collapsed by default in the runner UI
18-
- **Failure annotations**: emits an `::error` workflow command for each failing test so failures appear in the workflow Annotations tab and, when the source location can be resolved, on the pull request's "Files changed" diff gutter
18+
- **Failure annotations**: emits an `::error` workflow command for each failing test so failures appear in the workflow Annotations tab and, when the source location can be resolved, on the pull request's "Files changed" diff gutter. Skipped tests are surfaced as title-only `::warning` annotations so they are visible in the Annotations tab too
1919
- **Job summary**: appends 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
2020
- **Slow-test notices**: emits a `::notice` workflow command for any test still running past a threshold (default 60 seconds)
2121

@@ -25,7 +25,7 @@ The extension activates when the test run is on GitHub Actions (`GITHUB_ACTIONS=
2525
|---|---|---|
2626
| `--report-gh` | Master switch that turns the extension on (required, in addition to running on GitHub Actions) | off |
2727
| `--report-gh-groups on\|off` | Per-assembly log groups | on |
28-
| `--report-gh-annotations on\|off` | Failure annotations | on |
28+
| `--report-gh-annotations on\|off` | Failure and skip annotations | on |
2929
| `--report-gh-step-summary on\|off` | Markdown job summary | on |
3030
| `--report-gh-slow-test-notices on\|off` | Slow-test notices | on |
3131
| `--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 |

‎src/Platform/Microsoft.Testing.Extensions.GitHubActionsReport/Resources/GitHubActionsResources.resx‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,23 @@
6262
<value>GitHub Actions report generator to emit workflow commands so test runs produce a first-class experience on GitHub Actions.</value>
6363
</data>
6464
<data name="AnnotationsOptionDescription" xml:space="preserve">
65-
<value>Enable or disable GitHub Actions failure annotations. 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>
65+
<value>Enable or disable GitHub Actions annotations for failed and skipped tests. 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>
6666
<comment>{Locked="on"}{Locked="off"}{Locked="true"}{Locked="enable"}{Locked="1"}{Locked="false"}{Locked="disable"}{Locked="0"}</comment>
6767
</data>
6868
<data name="AnnotationTitle" xml:space="preserve">
6969
<value>Test failed: {0}</value>
7070
<comment>{0} is the fully qualified test name.</comment>
7171
</data>
72+
<data name="SkippedAnnotationTitle" xml:space="preserve">
73+
<value>Test skipped: {0}</value>
74+
<comment>{0} is the fully qualified test name.</comment>
75+
</data>
7276
<data name="NoFailureMessageFallback" xml:space="preserve">
7377
<value>The test failed without providing a failure message.</value>
7478
</data>
79+
<data name="NoSkipReasonFallback" xml:space="preserve">
80+
<value>The test was skipped without providing a reason.</value>
81+
</data>
7582
<data name="StepSummaryOptionDescription" xml:space="preserve">
7683
<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>
7784
<comment>{Locked="on"}{Locked="off"}{Locked="true"}{Locked="enable"}{Locked="1"}{Locked="false"}{Locked="disable"}{Locked="0"}{Locked="GITHUB_STEP_SUMMARY"}</comment>

‎src/Platform/Microsoft.Testing.Extensions.GitHubActionsReport/Resources/xlf/GitHubActionsResources.cs.xlf‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<note>{0} is the fully qualified test name.</note>
99
</trans-unit>
1010
<trans-unit id="AnnotationsOptionDescription">
11-
<source>Enable or disable GitHub Actions failure annotations. 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>
12-
<target state="new">Enable or disable GitHub Actions failure annotations. 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>
11+
<source>Enable or disable GitHub Actions annotations for failed and skipped tests. 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>
12+
<target state="new">Enable or disable GitHub Actions annotations for failed and skipped tests. 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>
1313
<note>{Locked="on"}{Locked="off"}{Locked="true"}{Locked="enable"}{Locked="1"}{Locked="false"}{Locked="disable"}{Locked="0"}</note>
1414
</trans-unit>
1515
<trans-unit id="Description">
@@ -47,11 +47,21 @@
4747
<target state="new">The test failed without providing a failure message.</target>
4848
<note />
4949
</trans-unit>
50+
<trans-unit id="NoSkipReasonFallback">
51+
<source>The test was skipped without providing a reason.</source>
52+
<target state="new">The test was skipped without providing a reason.</target>
53+
<note />
54+
</trans-unit>
5055
<trans-unit id="OptionDescription">
5156
<source>Enable GitHub Actions report generator to emit workflow commands so test runs produce a first-class experience on GitHub Actions.</source>
5257
<target state="new">Enable GitHub Actions report generator to emit workflow commands so test runs produce a first-class experience on GitHub Actions.</target>
5358
<note />
5459
</trans-unit>
60+
<trans-unit id="SkippedAnnotationTitle">
61+
<source>Test skipped: {0}</source>
62+
<target state="new">Test skipped: {0}</target>
63+
<note>{0} is the fully qualified test name.</note>
64+
</trans-unit>
5565
<trans-unit id="SlowTestNoticeTitle">
5666
<source>Slow test: {0}</source>
5767
<target state="new">Slow test: {0}</target>

‎src/Platform/Microsoft.Testing.Extensions.GitHubActionsReport/Resources/xlf/GitHubActionsResources.de.xlf‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<note>{0} is the fully qualified test name.</note>
99
</trans-unit>
1010
<trans-unit id="AnnotationsOptionDescription">
11-
<source>Enable or disable GitHub Actions failure annotations. 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>
12-
<target state="new">Enable or disable GitHub Actions failure annotations. 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>
11+
<source>Enable or disable GitHub Actions annotations for failed and skipped tests. 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>
12+
<target state="new">Enable or disable GitHub Actions annotations for failed and skipped tests. 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>
1313
<note>{Locked="on"}{Locked="off"}{Locked="true"}{Locked="enable"}{Locked="1"}{Locked="false"}{Locked="disable"}{Locked="0"}</note>
1414
</trans-unit>
1515
<trans-unit id="Description">
@@ -47,11 +47,21 @@
4747
<target state="new">The test failed without providing a failure message.</target>
4848
<note />
4949
</trans-unit>
50+
<trans-unit id="NoSkipReasonFallback">
51+
<source>The test was skipped without providing a reason.</source>
52+
<target state="new">The test was skipped without providing a reason.</target>
53+
<note />
54+
</trans-unit>
5055
<trans-unit id="OptionDescription">
5156
<source>Enable GitHub Actions report generator to emit workflow commands so test runs produce a first-class experience on GitHub Actions.</source>
5257
<target state="new">Enable GitHub Actions report generator to emit workflow commands so test runs produce a first-class experience on GitHub Actions.</target>
5358
<note />
5459
</trans-unit>
60+
<trans-unit id="SkippedAnnotationTitle">
61+
<source>Test skipped: {0}</source>
62+
<target state="new">Test skipped: {0}</target>
63+
<note>{0} is the fully qualified test name.</note>
64+
</trans-unit>
5565
<trans-unit id="SlowTestNoticeTitle">
5666
<source>Slow test: {0}</source>
5767
<target state="new">Slow test: {0}</target>

‎src/Platform/Microsoft.Testing.Extensions.GitHubActionsReport/Resources/xlf/GitHubActionsResources.es.xlf‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<note>{0} is the fully qualified test name.</note>
99
</trans-unit>
1010
<trans-unit id="AnnotationsOptionDescription">
11-
<source>Enable or disable GitHub Actions failure annotations. 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>
12-
<target state="new">Enable or disable GitHub Actions failure annotations. 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>
11+
<source>Enable or disable GitHub Actions annotations for failed and skipped tests. 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>
12+
<target state="new">Enable or disable GitHub Actions annotations for failed and skipped tests. 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>
1313
<note>{Locked="on"}{Locked="off"}{Locked="true"}{Locked="enable"}{Locked="1"}{Locked="false"}{Locked="disable"}{Locked="0"}</note>
1414
</trans-unit>
1515
<trans-unit id="Description">
@@ -47,11 +47,21 @@
4747
<target state="new">The test failed without providing a failure message.</target>
4848
<note />
4949
</trans-unit>
50+
<trans-unit id="NoSkipReasonFallback">
51+
<source>The test was skipped without providing a reason.</source>
52+
<target state="new">The test was skipped without providing a reason.</target>
53+
<note />
54+
</trans-unit>
5055
<trans-unit id="OptionDescription">
5156
<source>Enable GitHub Actions report generator to emit workflow commands so test runs produce a first-class experience on GitHub Actions.</source>
5257
<target state="new">Enable GitHub Actions report generator to emit workflow commands so test runs produce a first-class experience on GitHub Actions.</target>
5358
<note />
5459
</trans-unit>
60+
<trans-unit id="SkippedAnnotationTitle">
61+
<source>Test skipped: {0}</source>
62+
<target state="new">Test skipped: {0}</target>
63+
<note>{0} is the fully qualified test name.</note>
64+
</trans-unit>
5565
<trans-unit id="SlowTestNoticeTitle">
5666
<source>Slow test: {0}</source>
5767
<target state="new">Slow test: {0}</target>

‎src/Platform/Microsoft.Testing.Extensions.GitHubActionsReport/Resources/xlf/GitHubActionsResources.fr.xlf‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<note>{0} is the fully qualified test name.</note>
99
</trans-unit>
1010
<trans-unit id="AnnotationsOptionDescription">
11-
<source>Enable or disable GitHub Actions failure annotations. 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>
12-
<target state="new">Enable or disable GitHub Actions failure annotations. 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>
11+
<source>Enable or disable GitHub Actions annotations for failed and skipped tests. 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>
12+
<target state="new">Enable or disable GitHub Actions annotations for failed and skipped tests. 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>
1313
<note>{Locked="on"}{Locked="off"}{Locked="true"}{Locked="enable"}{Locked="1"}{Locked="false"}{Locked="disable"}{Locked="0"}</note>
1414
</trans-unit>
1515
<trans-unit id="Description">
@@ -47,11 +47,21 @@
4747
<target state="new">The test failed without providing a failure message.</target>
4848
<note />
4949
</trans-unit>
50+
<trans-unit id="NoSkipReasonFallback">
51+
<source>The test was skipped without providing a reason.</source>
52+
<target state="new">The test was skipped without providing a reason.</target>
53+
<note />
54+
</trans-unit>
5055
<trans-unit id="OptionDescription">
5156
<source>Enable GitHub Actions report generator to emit workflow commands so test runs produce a first-class experience on GitHub Actions.</source>
5257
<target state="new">Enable GitHub Actions report generator to emit workflow commands so test runs produce a first-class experience on GitHub Actions.</target>
5358
<note />
5459
</trans-unit>
60+
<trans-unit id="SkippedAnnotationTitle">
61+
<source>Test skipped: {0}</source>
62+
<target state="new">Test skipped: {0}</target>
63+
<note>{0} is the fully qualified test name.</note>
64+
</trans-unit>
5565
<trans-unit id="SlowTestNoticeTitle">
5666
<source>Slow test: {0}</source>
5767
<target state="new">Slow test: {0}</target>

‎src/Platform/Microsoft.Testing.Extensions.GitHubActionsReport/Resources/xlf/GitHubActionsResources.it.xlf‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<note>{0} is the fully qualified test name.</note>
99
</trans-unit>
1010
<trans-unit id="AnnotationsOptionDescription">
11-
<source>Enable or disable GitHub Actions failure annotations. 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>
12-
<target state="new">Enable or disable GitHub Actions failure annotations. 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>
11+
<source>Enable or disable GitHub Actions annotations for failed and skipped tests. 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>
12+
<target state="new">Enable or disable GitHub Actions annotations for failed and skipped tests. 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>
1313
<note>{Locked="on"}{Locked="off"}{Locked="true"}{Locked="enable"}{Locked="1"}{Locked="false"}{Locked="disable"}{Locked="0"}</note>
1414
</trans-unit>
1515
<trans-unit id="Description">
@@ -47,11 +47,21 @@
4747
<target state="new">The test failed without providing a failure message.</target>
4848
<note />
4949
</trans-unit>
50+
<trans-unit id="NoSkipReasonFallback">
51+
<source>The test was skipped without providing a reason.</source>
52+
<target state="new">The test was skipped without providing a reason.</target>
53+
<note />
54+
</trans-unit>
5055
<trans-unit id="OptionDescription">
5156
<source>Enable GitHub Actions report generator to emit workflow commands so test runs produce a first-class experience on GitHub Actions.</source>
5257
<target state="new">Enable GitHub Actions report generator to emit workflow commands so test runs produce a first-class experience on GitHub Actions.</target>
5358
<note />
5459
</trans-unit>
60+
<trans-unit id="SkippedAnnotationTitle">
61+
<source>Test skipped: {0}</source>
62+
<target state="new">Test skipped: {0}</target>
63+
<note>{0} is the fully qualified test name.</note>
64+
</trans-unit>
5565
<trans-unit id="SlowTestNoticeTitle">
5666
<source>Slow test: {0}</source>
5767
<target state="new">Slow test: {0}</target>

0 commit comments

Comments
 (0)