Skip to content

Commit a77fe8a

Browse files
authored
.NET 8 compat test adjustments: 1) do not trim SDK, 2) support pattern to match output, 3) modify output truncation length (actions#3427)
1 parent 7e84ae0 commit a77fe8a

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

Diff for: src/Runner.Common/Constants.cs

+2
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ public static class System
281281
public static readonly string JobRequestType = "system.jobRequestType";
282282
public static readonly string OrchestrationId = "system.orchestrationId";
283283
public static readonly string TestDotNet8Compatibility = "system.testDotNet8Compatibility";
284+
public static readonly string DotNet8CompatibilityOutputLength = "system.dotNet8CompatibilityOutputLength";
285+
public static readonly string DotNet8CompatibilityOutputPattern = "system.dotNet8CompatibilityOutputPattern";
284286
public static readonly string DotNet8CompatibilityWarning = "system.dotNet8CompatibilityWarning";
285287
}
286288
}

Diff for: src/Runner.Worker/OSWarningChecker.cs

+18-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4+
using System.Text.RegularExpressions;
45
using System.Threading;
56
using System.Threading.Tasks;
67
using GitHub.DistributedTask.WebApi;
@@ -17,6 +18,8 @@ public interface IOSWarningChecker : IRunnerService
1718

1819
public sealed class OSWarningChecker : RunnerService, IOSWarningChecker
1920
{
21+
private static TimeSpan s_regexTimeout = TimeSpan.FromSeconds(1);
22+
2023
public async Task CheckOSAsync(IExecutionContext context)
2124
{
2225
ArgUtil.NotNull(context, nameof(context));
@@ -68,13 +71,23 @@ public async Task CheckOSAsync(IExecutionContext context)
6871
var outputStr = string.Join("\n", output).Trim();
6972
if (exitCode != 0 || !string.Equals(outputStr, "Hello from .NET 8!", StringComparison.Ordinal))
7073
{
74+
var pattern = context.Global.Variables.System_DotNet8CompatibilityOutputPattern;
75+
if (!string.IsNullOrEmpty(pattern))
76+
{
77+
var regex = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant, s_regexTimeout);
78+
if (!regex.IsMatch(outputStr))
79+
{
80+
return;
81+
}
82+
}
83+
7184
var warningMessage = context.Global.Variables.System_DotNet8CompatibilityWarning;
7285
if (!string.IsNullOrEmpty(warningMessage))
7386
{
7487
context.Warning(warningMessage);
7588
}
7689

77-
context.Global.JobTelemetry.Add(new JobTelemetry() { Type = JobTelemetryType.General, Message = $".NET 8 OS compatibility test failed with exit code '{exitCode}' and output: {GetShortOutput(output)}" });
90+
context.Global.JobTelemetry.Add(new JobTelemetry() { Type = JobTelemetryType.General, Message = $".NET 8 OS compatibility test failed with exit code '{exitCode}' and output: {GetShortOutput(context, output)}" });
7891
}
7992
}
8093
}
@@ -83,14 +96,15 @@ public async Task CheckOSAsync(IExecutionContext context)
8396
{
8497
Trace.Error("An error occurred while testing .NET 8 compatibility'");
8598
Trace.Error(ex);
86-
context.Global.JobTelemetry.Add(new JobTelemetry() { Type = JobTelemetryType.General, Message = $".NET 8 OS compatibility test encountered exception type '{ex.GetType().FullName}', message: '{ex.Message}', process output: '{GetShortOutput(output)}'" });
99+
context.Global.JobTelemetry.Add(new JobTelemetry() { Type = JobTelemetryType.General, Message = $".NET 8 OS compatibility test encountered exception type '{ex.GetType().FullName}', message: '{ex.Message}', process output: '{GetShortOutput(context, output)}'" });
87100
}
88101
}
89102

90-
private static string GetShortOutput(List<string> output)
103+
private static string GetShortOutput(IExecutionContext context, List<string> output)
91104
{
105+
var length = context.Global.Variables.System_DotNet8CompatibilityOutputLength ?? 200;
92106
var outputStr = string.Join("\n", output).Trim();
93-
return outputStr.Length > 200 ? string.Concat(outputStr.Substring(0, 200), "[...]") : outputStr;
107+
return outputStr.Length > length ? string.Concat(outputStr.Substring(0, length), "[...]") : outputStr;
94108
}
95109
}
96110
}

Diff for: src/Runner.Worker/Variables.cs

+4
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ public Variables(IHostContext hostContext, IDictionary<string, VariableValue> co
7474

7575
public string System_DotNet8CompatibilityWarning => Get(Constants.Variables.System.DotNet8CompatibilityWarning);
7676

77+
public string System_DotNet8CompatibilityOutputPattern => Get(Constants.Variables.System.DotNet8CompatibilityOutputPattern);
78+
79+
public int? System_DotNet8CompatibilityOutputLength => GetInt(Constants.Variables.System.DotNet8CompatibilityOutputLength);
80+
7781
public string System_PhaseDisplayName => Get(Constants.Variables.System.PhaseDisplayName);
7882

7983
public bool System_TestDotNet8Compatibility => GetBoolean(Constants.Variables.System.TestDotNet8Compatibility) ?? false;

Diff for: src/TestDotNet8Compatibility/TestDotNet8Compatibility.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<OutputType>Exe</OutputType>
66
<RuntimeIdentifiers>win-x64;win-x86;linux-x64;linux-arm64;linux-arm;osx-x64;osx-arm64;win-arm64</RuntimeIdentifiers>
77
<SelfContained>true</SelfContained>
8-
<PublishTrimmed>true</PublishTrimmed>
98
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
109
<Version>$(Version)</Version>
1110
<PredefinedCulturesOnly>false</PredefinedCulturesOnly>

0 commit comments

Comments
 (0)