1
1
using System ;
2
2
using System . Collections . Generic ;
3
3
using System . IO ;
4
+ using System . Threading ;
4
5
using System . Threading . Tasks ;
5
- using System . Text . RegularExpressions ;
6
6
using GitHub . DistributedTask . WebApi ;
7
- using GitHub . DistributedTask . Pipelines ;
8
7
using GitHub . Runner . Common ;
9
8
using GitHub . Runner . Sdk ;
10
9
@@ -13,75 +12,85 @@ namespace GitHub.Runner.Worker
13
12
[ ServiceLocator ( Default = typeof ( OSWarningChecker ) ) ]
14
13
public interface IOSWarningChecker : IRunnerService
15
14
{
16
- Task CheckOSAsync ( IExecutionContext context , IList < OSWarning > osWarnings ) ;
15
+ Task CheckOSAsync ( IExecutionContext context ) ;
17
16
}
18
17
19
- #if OS_WINDOWS || OS_OSX
20
18
public sealed class OSWarningChecker : RunnerService , IOSWarningChecker
21
19
{
22
- public Task CheckOSAsync ( IExecutionContext context , IList < OSWarning > osWarnings )
20
+ public async Task CheckOSAsync ( IExecutionContext context )
23
21
{
24
22
ArgUtil . NotNull ( context , nameof ( context ) ) ;
25
- ArgUtil . NotNull ( osWarnings , nameof ( osWarnings ) ) ;
26
- return Task . CompletedTask ;
27
- }
28
- }
29
- #else
30
- public sealed class OSWarningChecker : RunnerService , IOSWarningChecker
31
- {
32
- private static readonly TimeSpan s_matchTimeout = TimeSpan . FromMilliseconds ( 100 ) ;
33
- private static readonly RegexOptions s_regexOptions = RegexOptions . CultureInvariant | RegexOptions . IgnoreCase ;
34
-
35
- public async Task CheckOSAsync ( IExecutionContext context , IList < OSWarning > osWarnings )
36
- {
37
- ArgUtil . NotNull ( context , nameof ( context ) ) ;
38
- ArgUtil . NotNull ( osWarnings , nameof ( osWarnings ) ) ;
39
- foreach ( var osWarning in osWarnings )
23
+ if ( ! context . Global . Variables . System_TestDotNet8Compatibility )
40
24
{
41
- if ( string . IsNullOrEmpty ( osWarning . FilePath ) )
42
- {
43
- Trace . Error ( "The file path is not specified in the OS warning check." ) ;
44
- continue ;
45
- }
25
+ return ;
26
+ }
46
27
47
- if ( string . IsNullOrEmpty ( osWarning . RegularExpression ) )
28
+ context . Output ( "Testing runner upgrade compatibility" ) ;
29
+ List < string > output = new ( ) ;
30
+ object outputLock = new ( ) ;
31
+ try
32
+ {
33
+ using ( var process = HostContext . CreateService < IProcessInvoker > ( ) )
48
34
{
49
- Trace . Error ( "The regular expression is not specified in the OS warning check." ) ;
50
- continue ;
51
- }
35
+ process . OutputDataReceived += delegate ( object sender , ProcessDataReceivedEventArgs stdout )
36
+ {
37
+ if ( ! string . IsNullOrEmpty ( stdout . Data ) )
38
+ {
39
+ lock ( outputLock )
40
+ {
41
+ output . Add ( stdout . Data ) ;
42
+ Trace . Info ( stdout . Data ) ;
43
+ }
44
+ }
45
+ } ;
52
46
53
- if ( string . IsNullOrEmpty ( osWarning . Warning ) )
54
- {
55
- Trace . Error ( "The warning message is not specified in the OS warning check." ) ;
56
- continue ;
57
- }
47
+ process . ErrorDataReceived += delegate ( object sender , ProcessDataReceivedEventArgs stderr )
48
+ {
49
+ if ( ! string . IsNullOrEmpty ( stderr . Data ) )
50
+ {
51
+ lock ( outputLock )
52
+ {
53
+ output . Add ( stderr . Data ) ;
54
+ Trace . Error ( stderr . Data ) ;
55
+ }
56
+ }
57
+ } ;
58
58
59
- try
60
- {
61
- if ( File . Exists ( osWarning . FilePath ) )
59
+ using ( var cancellationTokenSource = new CancellationTokenSource ( TimeSpan . FromSeconds ( 10 ) ) )
62
60
{
63
- var lines = await File . ReadAllLinesAsync ( osWarning . FilePath , context . CancellationToken ) ;
64
- var regex = new Regex ( osWarning . RegularExpression , s_regexOptions , s_matchTimeout ) ;
65
- foreach ( var line in lines )
61
+ int exitCode = await process . ExecuteAsync (
62
+ workingDirectory : HostContext . GetDirectory ( WellKnownDirectory . Root ) ,
63
+ fileName : Path . Combine ( HostContext . GetDirectory ( WellKnownDirectory . Bin ) , "testDotNet8Compatibility" , $ "TestDotNet8Compatibility{ IOUtil . ExeExtension } ") ,
64
+ arguments : string . Empty ,
65
+ environment : null ,
66
+ cancellationToken : cancellationTokenSource . Token ) ;
67
+
68
+ var outputStr = string . Join ( "\n " , output ) . Trim ( ) ;
69
+ if ( exitCode != 0 || ! string . Equals ( outputStr , "Hello from .NET 8!" , StringComparison . Ordinal ) )
66
70
{
67
- if ( regex . IsMatch ( line ) )
71
+ var warningMessage = context . Global . Variables . System_DotNet8CompatibilityWarning ;
72
+ if ( ! string . IsNullOrEmpty ( warningMessage ) )
68
73
{
69
- context . Warning ( osWarning . Warning ) ;
70
- context . Global . JobTelemetry . Add ( new JobTelemetry ( ) { Type = JobTelemetryType . General , Message = $ "OS warning: { osWarning . Warning } " } ) ;
71
- return ;
74
+ context . Warning ( warningMessage ) ;
72
75
}
76
+
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 ) } " } ) ;
73
78
}
74
79
}
75
80
}
76
- catch ( Exception ex )
77
- {
78
- Trace . Error ( "An error occurred while checking OS warnings for file '{0}' and regex '{1}'." , osWarning . FilePath , osWarning . RegularExpression ) ;
79
- Trace . Error ( ex ) ;
80
- context . Global . JobTelemetry . Add ( new JobTelemetry ( ) { Type = JobTelemetryType . General , Message = $ "An error occurred while checking OS warnings for file ' { osWarning . FilePath } ' and regex ' { osWarning . RegularExpression } ': { ex . Message } " } ) ;
81
- }
81
+ }
82
+ catch ( Exception ex )
83
+ {
84
+ Trace . Error ( "An error occurred while testing .NET 8 compatibility'" ) ;
85
+ 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 ) } '" } ) ;
82
87
}
83
88
}
89
+
90
+ private static string GetShortOutput ( List < string > output )
91
+ {
92
+ var outputStr = string . Join ( "\n " , output ) . Trim ( ) ;
93
+ return outputStr . Length > 200 ? string . Concat ( outputStr . Substring ( 0 , 200 ) , "[...]" ) : outputStr ;
94
+ }
84
95
}
85
- #endif
86
96
}
87
-
0 commit comments