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
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ namespace Microsoft.Testing.Extensions.Reporting;
internal static class AzureDevOpsCommandLineOptions
{
public const string AzureDevOpsOptionName = "report-azdo";
public const string AzureDevOpsAnnotations = "report-azdo-annotations";
public const string AzureDevOpsDemoteKnownFlaky = "report-azdo-demote-known-flaky";
public const string AzureDevOpsFlakyHistory = "report-azdo-flaky-history";
public const string AzureDevOpsGroups = "report-azdo-groups";
public const string AzureDevOpsQuarantineFile = "report-azdo-quarantine-file";
public const string AzureDevOpsReportSeverity = "report-azdo-severity";
public const string AzureDevOpsSlowTestHistory = "report-azdo-slow-test-history";
Expand All @@ -26,6 +28,9 @@ internal static class AzureDevOpsCommandLineOptions
public const string PublishAzureDevOpsRunNameOptionName = "publish-azdo-run-name";
public const string PublishAzureDevOpsTestResultsOptionName = "publish-azdo-test-results";

public const string OptionOn = "on";
public const string OptionOff = "off";

public const int SlowTestHistoryDefaultMinSample = 10;
public const double SlowTestHistoryDefaultMultiplier = 3.0;
public const int SlowTestStaticThresholdSeconds = 60;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ internal sealed class AzureDevOpsCommandLineProvider : CommandLineOptionsProvide

private static readonly string[] SeverityOptions = ["error", "warning"];

private static readonly string[] OnOffOptions =
[
AzureDevOpsCommandLineOptions.OptionOn,
AzureDevOpsCommandLineOptions.OptionOff,
];

internal const int MaxStackFrameFilterPatterns = 16;
internal const int StackFrameFilterMatchTimeoutMs = 500;

Expand Down Expand Up @@ -55,8 +61,10 @@ public AzureDevOpsCommandLineProvider()
AzureDevOpsResources.Description,
[
new CommandLineOption(AzureDevOpsCommandLineOptions.AzureDevOpsOptionName, AzureDevOpsResources.OptionDescription, ArgumentArity.Zero, false),
new CommandLineOption(AzureDevOpsCommandLineOptions.AzureDevOpsAnnotations, AzureDevOpsResources.AnnotationsOptionDescription, ArgumentArity.ExactlyOne, false),
new CommandLineOption(AzureDevOpsCommandLineOptions.AzureDevOpsDemoteKnownFlaky, DemoteKnownFlakyOptionDescriptionFormatted, ArgumentArity.Zero, false),
new CommandLineOption(AzureDevOpsCommandLineOptions.AzureDevOpsFlakyHistory, AzureDevOpsResources.FlakyHistoryOptionDescription, ArgumentArity.ExactlyOne, false),
new CommandLineOption(AzureDevOpsCommandLineOptions.AzureDevOpsGroups, AzureDevOpsResources.GroupsOptionDescription, ArgumentArity.ExactlyOne, false),
new CommandLineOption(AzureDevOpsCommandLineOptions.AzureDevOpsQuarantineFile, AzureDevOpsResources.QuarantineFileOptionDescription, ArgumentArity.ExactlyOne, false),
new CommandLineOption(AzureDevOpsCommandLineOptions.AzureDevOpsReportSeverity, AzureDevOpsResources.SeverityOptionDescription, ArgumentArity.ExactlyOne, false),
new CommandLineOption(AzureDevOpsCommandLineOptions.AzureDevOpsSlowTestHistory, AzureDevOpsResources.SlowTestHistoryOptionDescription, ArgumentArity.ExactlyOne, false),
Expand All @@ -77,6 +85,9 @@ public AzureDevOpsCommandLineProvider()
public override Task<ValidationResult> ValidateOptionArgumentsAsync(CommandLineOption commandOption, string[] arguments)
=> commandOption.Name switch
{
AzureDevOpsCommandLineOptions.AzureDevOpsAnnotations or AzureDevOpsCommandLineOptions.AzureDevOpsGroups
when !OnOffOptions.Contains(arguments[0], StringComparer.OrdinalIgnoreCase)
=> ValidationResult.InvalidTask(string.Format(CultureInfo.InvariantCulture, AzureDevOpsResources.InvalidOnOffValue, arguments[0])),
AzureDevOpsCommandLineOptions.AzureDevOpsFlakyHistory => ValidateFlakyHistoryArgumentsAsync(arguments),
AzureDevOpsCommandLineOptions.AzureDevOpsSlowTestHistory => ValidateSlowTestHistoryArgumentsAsync(arguments),
AzureDevOpsCommandLineOptions.AzureDevOpsSlowTestHistoryMinSample => ValidateSlowTestHistoryMinSampleArgumentsAsync(arguments),
Expand All @@ -96,7 +107,15 @@ public override Task<ValidationResult> ValidateCommandLineOptionsAsync(ICommandL
string? errorMessage = null;
if (!commandLineOptions.IsOptionSet(AzureDevOpsCommandLineOptions.AzureDevOpsOptionName))
{
if (commandLineOptions.IsOptionSet(AzureDevOpsCommandLineOptions.AzureDevOpsDemoteKnownFlaky))
if (commandLineOptions.IsOptionSet(AzureDevOpsCommandLineOptions.AzureDevOpsAnnotations))
{
errorMessage = AzureDevOpsResources.AzureDevOpsAnnotationsRequiresAzureDevOps;
}
else if (commandLineOptions.IsOptionSet(AzureDevOpsCommandLineOptions.AzureDevOpsGroups))
{
errorMessage = AzureDevOpsResources.AzureDevOpsGroupsRequiresAzureDevOps;
}
else if (commandLineOptions.IsOptionSet(AzureDevOpsCommandLineOptions.AzureDevOpsDemoteKnownFlaky))
{
errorMessage = AzureDevOpsResources.AzureDevOpsDemoteKnownFlakyRequiresAzureDevOps;
}
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.Extensions.Reporting;
using Microsoft.Testing.Platform.CommandLine;
using Microsoft.Testing.Platform.Helpers;

namespace Microsoft.Testing.Extensions.AzureDevOpsReport;
Expand Down Expand Up @@ -34,4 +36,14 @@ public static bool IsRunningInAzureDevOps(IEnvironment environment)
environment.GetEnvironmentVariable(TfBuildEnvironmentVariableName),
TfBuildEnabledValue,
StringComparison.OrdinalIgnoreCase);

/// <summary>
/// Returns whether an individual <c>on|off</c> feature knob is enabled. A knob is enabled unless it
/// is explicitly set to <c>off</c> (case-insensitive), so every feature defaults to <c>on</c> once
/// the extension itself is active.
/// </summary>
public static bool IsFeatureKnobEnabled(ICommandLineOptions commandLineOptions, string knobOptionName)
=> !(commandLineOptions.TryGetOptionArgumentList(knobOptionName, out string[]? arguments)
&& arguments is [string value]
&& string.Equals(value, AzureDevOpsCommandLineOptions.OptionOff, StringComparison.OrdinalIgnoreCase));
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public AzureDevOpsLogGroupReporter(
public Task<bool> IsEnabledAsync()
=> Task.FromResult(
_commandLineOptions.IsOptionSet(AzureDevOpsCommandLineOptions.AzureDevOpsOptionName)
&& AzureDevOpsConstants.IsRunningInAzureDevOps(_environment));
&& AzureDevOpsConstants.IsRunningInAzureDevOps(_environment)
&& AzureDevOpsConstants.IsFeatureKnobEnabled(_commandLineOptions, AzureDevOpsCommandLineOptions.AzureDevOpsGroups));

// No-op: this consumer subscribes to data only to be ordered in the consumer phase at session
// end (see the type-level remarks). It does not act on individual messages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,16 @@ public Task<bool> IsEnabledAsync()
EnsureEnabledConfigurationLoaded();
}

bool annotationsEnabled = AzureDevOpsConstants.IsFeatureKnobEnabled(_commandLine, AzureDevOpsCommandLineOptions.AzureDevOpsAnnotations);

if (_logger.IsEnabled(LogLevel.Trace))
{
_logger.LogTrace($"{AzureDevOpsConstants.TfBuildEnvironmentVariableName} environment variable is {(isEnabledByEnvVariable ? "enabled. Will report errors to Azure DevOps, because we are running in CI." : "disabled. Will not report errors to Azure DevOps.")}");
_logger.LogTrace($"Severity is set to '{_severity ?? "error"}', you can override it by using --report-azdo-severity parameter.");
_logger.LogTrace($"Failure annotations are {(annotationsEnabled ? "enabled" : "disabled")}, you can toggle them by using --report-azdo-annotations parameter.");
}

return Task.FromResult(isEnabledByEnvVariable);
return Task.FromResult(isEnabledByEnvVariable && annotationsEnabled);
}

public async Task ConsumeAsync(IDataProducer dataProducer, IData value, CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="AnnotationsOptionDescription" xml:space="preserve">
<value>Enable or disable Azure DevOps failure annotations ('on' or 'off'). Defaults to 'on'. Requires '--report-azdo'.</value>
<comment>{Locked="on"}{Locked="off"}{Locked="--report-azdo"}</comment>
</data>
<data name="ArtifactUploadOptionsRequireUploadArtifacts" xml:space="preserve">
<value>'--report-azdo-upload-artifact-include', '--report-azdo-upload-artifact-exclude', and '--report-azdo-upload-artifact-name' require '--report-azdo-upload-artifacts' to be set to a value other than 'off'.</value>
<comment>{Locked="--report-azdo-upload-artifact-include"}{Locked="--report-azdo-upload-artifact-exclude"}{Locked="--report-azdo-upload-artifact-name"}{Locked="--report-azdo-upload-artifacts"}{Locked="off"}</comment>
Expand All @@ -125,6 +129,10 @@
<value>Azure DevOps artifact upload was requested, but TF_BUILD is not set to 'true'; skipping Azure DevOps artifact upload and build tags.</value>
<comment>{Locked="TF_BUILD"}{Locked="true"}</comment>
</data>
<data name="AzureDevOpsAnnotationsRequiresAzureDevOps" xml:space="preserve">
<value>'--report-azdo-annotations' requires '--report-azdo' to be enabled</value>
<comment>{Locked="--report-azdo-annotations"}{Locked="--report-azdo"}</comment>
</data>
<data name="AzureDevOpsDemoteKnownFlakyRequiresAzureDevOps" xml:space="preserve">
<value>'--report-azdo-demote-known-flaky' requires '--report-azdo' to be enabled</value>
<comment>{Locked="--report-azdo-demote-known-flaky"}{Locked="--report-azdo"}</comment>
Expand All @@ -137,6 +145,10 @@
<value>'--report-azdo-flaky-history' requires '--report-azdo' to be enabled</value>
<comment>{Locked="--report-azdo-flaky-history"}{Locked="--report-azdo"}</comment>
</data>
<data name="AzureDevOpsGroupsRequiresAzureDevOps" xml:space="preserve">
<value>'--report-azdo-groups' requires '--report-azdo' to be enabled</value>
<comment>{Locked="--report-azdo-groups"}{Locked="--report-azdo"}</comment>
</data>
<data name="AzureDevOpsLivePublishingCompleteRunFailed" xml:space="preserve">
<value>Azure DevOps live publishing failed to complete the test run.</value>
</data>
Expand Down Expand Up @@ -250,6 +262,10 @@
<value>Azure DevOps flaky history for run '{0}' exceeded {1} pages or returned an unchanged continuation token. Remaining results will be ignored.</value>
<comment>{0} is the Azure DevOps run URL. {1} is the maximum number of pages.</comment>
</data>
<data name="GroupsOptionDescription" xml:space="preserve">
<value>Enable or disable per-assembly Azure DevOps log groups ('on' or 'off'). Defaults to 'on'. Requires '--report-azdo'.</value>
<comment>{Locked="on"}{Locked="off"}{Locked="--report-azdo"}</comment>
</data>
<data name="InvalidArtifactUploadGlob" xml:space="preserve">
<value>Invalid glob pattern {0}.</value>
<comment>{0} is the invalid glob pattern.</comment>
Expand All @@ -262,6 +278,10 @@
<value>Invalid value '{0}' for '--report-azdo-flaky-history'. Provide an integer between 1 and 90.</value>
<comment>{0} is the invalid value. {Locked="--report-azdo-flaky-history"}</comment>
</data>
<data name="InvalidOnOffValue" xml:space="preserve">
<value>Invalid value '{0}'. Valid values are 'on' and 'off'.</value>
<comment>{Locked="on"}{Locked="off"}</comment>
</data>
<data name="InvalidSeverity" xml:space="preserve">
<value>Invalid option {0}.</value>
<comment>{0} is the invalid option value.</comment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-transitional.xsd">
<file datatype="xml" source-language="en" target-language="cs" original="../AzureDevOpsResources.resx">
<body>
<trans-unit id="AnnotationsOptionDescription">
<source>Enable or disable Azure DevOps failure annotations ('on' or 'off'). Defaults to 'on'. Requires '--report-azdo'.</source>
<target state="new">Enable or disable Azure DevOps failure annotations ('on' or 'off'). Defaults to 'on'. Requires '--report-azdo'.</target>
<note>{Locked="on"}{Locked="off"}{Locked="--report-azdo"}</note>
</trans-unit>
<trans-unit id="ArtifactUploadOptionsRequireUploadArtifacts">
<source>'--report-azdo-upload-artifact-include', '--report-azdo-upload-artifact-exclude', and '--report-azdo-upload-artifact-name' require '--report-azdo-upload-artifacts' to be set to a value other than 'off'.</source>
<target state="translated">Parametry --report-azdo-upload-artifact-include, --report-azdo-upload-artifact-exclude a --report-azdo-upload-artifact-name vyžadují, aby parametr --report-azdo-upload-artifacts byl nastavený na jinou hodnotu než off.</target>
Expand All @@ -12,6 +17,11 @@
<target state="translated">Bylo vyžádáno nahrání artefaktu Azure DevOps, ale TF_BUILD není nastavené na hodnotu true. Nahrání artefaktu Azure DevOps a značek buildu se přeskočí.</target>
<note>{Locked="TF_BUILD"}{Locked="true"}</note>
</trans-unit>
<trans-unit id="AzureDevOpsAnnotationsRequiresAzureDevOps">
<source>'--report-azdo-annotations' requires '--report-azdo' to be enabled</source>
<target state="new">'--report-azdo-annotations' requires '--report-azdo' to be enabled</target>
<note>{Locked="--report-azdo-annotations"}{Locked="--report-azdo"}</note>
</trans-unit>
<trans-unit id="AzureDevOpsDemoteKnownFlakyRequiresAzureDevOps">
<source>'--report-azdo-demote-known-flaky' requires '--report-azdo' to be enabled</source>
<target state="translated">Aby bylo možné použít parametr --report-azdo-demote-known-flaky, musí být povolený parametr --report-azdo.</target>
Expand All @@ -27,6 +37,11 @@
<target state="translated">Aby bylo možné použít parametr ---report-azdo-flaky-history, musí být povolený parametr --report-azdo.</target>
<note>{Locked="--report-azdo-flaky-history"}{Locked="--report-azdo"}</note>
</trans-unit>
<trans-unit id="AzureDevOpsGroupsRequiresAzureDevOps">
<source>'--report-azdo-groups' requires '--report-azdo' to be enabled</source>
<target state="new">'--report-azdo-groups' requires '--report-azdo' to be enabled</target>
<note>{Locked="--report-azdo-groups"}{Locked="--report-azdo"}</note>
</trans-unit>
<trans-unit id="AzureDevOpsLivePublishingCompleteRunFailed">
<source>Azure DevOps live publishing failed to complete the test run.</source>
<target state="translated">Živému publikování Azure DevOps se nepodařilo dokončit testovací běh.</target>
Expand Down Expand Up @@ -197,6 +212,11 @@
<target state="translated">Historie nestability Azure DevOps vrátila {0} spuštění. Prověří se jenom první(ch) {1} spuštění.</target>
<note>{0} is the number of runs returned. {1} is the maximum number of runs to inspect.</note>
</trans-unit>
<trans-unit id="GroupsOptionDescription">
<source>Enable or disable per-assembly Azure DevOps log groups ('on' or 'off'). Defaults to 'on'. Requires '--report-azdo'.</source>
<target state="new">Enable or disable per-assembly Azure DevOps log groups ('on' or 'off'). Defaults to 'on'. Requires '--report-azdo'.</target>
<note>{Locked="on"}{Locked="off"}{Locked="--report-azdo"}</note>
</trans-unit>
<trans-unit id="InvalidArtifactUploadGlob">
<source>Invalid glob pattern {0}.</source>
<target state="translated">Neplatný vzor glob {0}</target>
Expand All @@ -212,6 +232,11 @@
<target state="translated">Neplatná hodnota {0} pro --report-azdo-flaky-history Zadejte celé číslo mezi 1 a 90.</target>
<note>{0} is the invalid value. {Locked="--report-azdo-flaky-history"}</note>
</trans-unit>
<trans-unit id="InvalidOnOffValue">
<source>Invalid value '{0}'. Valid values are 'on' and 'off'.</source>
<target state="new">Invalid value '{0}'. Valid values are 'on' and 'off'.</target>
<note>{Locked="on"}{Locked="off"}</note>
</trans-unit>
<trans-unit id="InvalidSeverity">
<source>Invalid option {0}.</source>
<target state="translated">Neplatná možnost {0}.</target>
Expand Down
Loading
Loading