Skip to content

Commit 7176bbc

Browse files
committed
Refresh build script
1 parent b468faf commit 7176bbc

2 files changed

Lines changed: 57 additions & 23 deletions

File tree

appveyor.psm1

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,17 @@ function Invoke-AppVeyorInstall {
5151
sudo bash dotnet-install.sh --version $desiredDotNetCoreSDKVersion --install-dir /usr/share/dotnet
5252
}
5353
else {
54+
# Starting in late 2024, installing .NET SDK without specifying the installation location caused
55+
# ONLY the newly installed .NET SDK to be detected instead of being installed side-by-side with
56+
# the other version(s) of the SDK already installed. I did not notice this situation until a year
57+
# later (November 30 2025) when GitVersion.Tool 2.5.1 would error out with the following exception:
58+
# "You must install or update .NET to run this application.". Presumably, this exception was caused
59+
# by the fact that GitVersion requires a different version of the .NET SDK to be present.
60+
#
61+
# This situation is eerily similar with what I experienced on Ubuntu in AppVeyor several years ago.
62+
5463
Invoke-WebRequest 'https://dot.net/v1/dotnet-install.ps1' -OutFile dotnet-install.ps1
55-
.\dotnet-install.ps1 -Version $desiredDotNetCoreSDKVersion
64+
.\dotnet-install.ps1 -Version $desiredDotNetCoreSDKVersion -InstallDir "$env:ProgramFiles\dotnet"
5665
}
5766
}
5867
finally {

build.cake

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Install tools.
2-
#tool dotnet:?package=GitVersion.Tool&version=6.5.0
2+
#tool dotnet:?package=GitVersion.Tool&version=6.5.1
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.1
55
#tool nuget:?package=xunit.runner.console&version=2.9.3
66
#tool nuget:?package=CodecovUploader&version=0.8.0
77

@@ -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

458446
Task("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")
497485
RunTarget(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

528553
static 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

534559
static string GetBuildBranch(this ICakeContext context)

0 commit comments

Comments
 (0)