11// Install tools.
2- #tool dotnet : ? package= GitVersion . Tool & version = 6.5 .0
2+ #tool dotnet : ? package= GitVersion . Tool & version = 6.6 .0
33#tool nuget: ? package = GitReleaseManager & version = 0.20 .0
4- #tool nuget: ? package = ReportGenerator & version = 5.5 .0
4+ #tool nuget: ? package = ReportGenerator & version = 5.5 .2
55#tool nuget: ? package = xunit . runner . console & version = 2.9 .3
66#tool nuget: ? package = CodecovUploader & version = 0.8 .0
77
88// Install addins.
99#addin nuget: ? package = Cake . Git & version = 5.0 .1
10- #addin nuget: ? package = Cake . Codecov & version = 3 .0.0
10+ #addin nuget: ? package = Cake . Codecov & version = 6 .0.0
1111
1212
1313///////////////////////////////////////////////////////////////////////////////
@@ -428,19 +428,7 @@ Task("Generate-Benchmark-Report")
428428 . Append ( $ "-tl:{ terminalLogger } ")
429429 } ) ;
430430
431- using ( DiagnosticVerbosity ( ) )
432- {
433- var processResult = StartProcess (
434- publishedAppLocation ,
435- new ProcessSettings ( )
436- {
437- Arguments = $ "-f * --artifacts={ artifactsLocation } "
438- } ) ;
439- if ( processResult != 0 )
440- {
441- throw new Exception ( $ "dotnet-benchmark.exe did not complete successfully. Result code: { processResult } ") ;
442- }
443- }
431+ Context . ExecuteCommand ( publishedAppLocation , $ "-f * --artifacts={ artifactsLocation } ") ;
444432} ) ;
445433
446434
@@ -452,7 +440,7 @@ Task("Coverage")
452440 . IsDependentOn ( "Generate-Code-Coverage-Report" )
453441 . Does ( ( ) =>
454442{
455- StartProcess ( "cmd" , $ "/c start { codeCoverageDir } index.htm") ;
443+ Context . ExecuteCommand ( "cmd" , $ "/c start { codeCoverageDir } index.htm") ;
456444} ) ;
457445
458446Task( "Benchmark" )
@@ -463,7 +451,7 @@ Task("Benchmark")
463451 var htmlReports = GetFiles ( $ "{ benchmarkDir } results/*-report.html", new GlobberSettings { IsCaseSensitive = false } ) ;
464452 foreach ( var htmlReport in htmlReports )
465453 {
466- StartProcess ( "cmd" , $ "/c start { htmlReport } ") ;
454+ Context . ExecuteCommand ( "cmd" , $ "/c start { htmlReport } ") ;
467455 }
468456} ) ;
469457
@@ -497,7 +485,6 @@ Task("Default")
497485RunTarget( target ) ;
498486
499487
500-
501488///////////////////////////////////////////////////////////////////////////////
502489// PRIVATE METHODS
503490///////////////////////////////////////////////////////////////////////////////
@@ -518,17 +505,55 @@ static string TrimStart(this string source, string value, StringComparison compa
518505 return source . Substring ( startIndex ) ;
519506}
520507
521- static List < string > ExecuteCommand ( this ICakeContext context , FilePath exe , string args )
508+ static IDisposable GetDisposableVerbosity ( this ICakeContext context , Verbosity verbosity )
509+ {
510+ return verbosity switch
511+ {
512+ Verbosity . Diagnostic => context . DiagnosticVerbosity ( ) ,
513+ Verbosity . Minimal => context . MinimalVerbosity ( ) ,
514+ Verbosity . Normal => context . NormalVerbosity ( ) ,
515+ Verbosity . Quiet => context . QuietVerbosity ( ) ,
516+ Verbosity . Verbose => context . VerboseVerbosity ( ) ,
517+ _ => throw new ArgumentOutOfRangeException ( nameof ( verbosity ) , $ "Unknown verbosity: { verbosity } ") ,
518+ } ;
519+ }
520+
521+ static List< string > ExecuteCommand ( this ICakeContext context , FilePath exe , string args , bool captureStandardOutput = false , Verbosity verbosity = Verbosity . Diagnostic )
522522{
523- context . StartProcess ( exe , new ProcessSettings { Arguments = args , RedirectStandardOutput = true } , out var redirectedOutput ) ;
523+ return context. ExecuteCommand ( exe , new ProcessArgumentBuilder ( ) . Append ( args ) , captureStandardOutput , verbosity ) ;
524+ }
524525
525- return redirectedOutput. ToList ( ) ;
526+ static List< string > ExecuteCommand ( this ICakeContext context , FilePath exe , ProcessArgumentBuilder argsBuilder , bool captureStandardOutput = false , Verbosity verbosity = Verbosity . Diagnostic )
527+ {
528+ using ( context . GetDisposableVerbosity ( verbosity ) )
529+ {
530+ var processResult = context. StartProcess (
531+ exe ,
532+ new ProcessSettings ( )
533+ {
534+ Arguments = argsBuilder ,
535+ RedirectStandardOutput = captureStandardOutput ,
536+ RedirectStandardError = true
537+ } ,
538+ out var redirectedOutput ,
539+ out var redirectedError
540+ ) ;
541+
542+ if ( processResult != 0 || redirectedError . Count ( ) > 0 )
543+ {
544+ var errorMsg = string . Join ( Environment . NewLine , redirectedError . Where ( s => ! string . IsNullOrWhiteSpace ( s ) ) ) ;
545+ var innerException = ! string. IsNullOrEmpty ( errorMsg ) ? new Exception ( errorMsg ) : null ;
546+ throw new Exception ( $ "{ exe } did not complete successfully. Result code: { processResult } ", innerException ) ;
547+ }
548+
549+ return ( redirectedOutput ?? Array . Empty < string > ( ) ) . ToList ( ) ;
550+ }
526551}
527552
528553static List < string > ExecGitCmd ( this ICakeContext context , string cmd )
529554{
530555 var gitExe = context. Tools. Resolve( context . IsRunningOnWindows ( ) ? "git.exe" : "git" ) ;
531- return context . ExecuteCommand ( gitExe , cmd ) ;
556+ return context . ExecuteCommand ( gitExe , cmd , true ) ;
532557}
533558
534559static string GetBuildBranch ( this ICakeContext context )
0 commit comments