Skip to content

Commit e580465

Browse files
committed
Install daily .NET SDK for benchmarks
1 parent 470c153 commit e580465

3 files changed

Lines changed: 47 additions & 25 deletions

File tree

Runner/Helpers/DotnetHelpers.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,22 @@ public static async Task KillRemainingDotnetProcessesAsync(JobBase job)
3636
}
3737
}
3838
}
39+
40+
public static async Task InstallDotnetSdkAsync(JobBase job, string globalJsonPath, string? installDir = null) =>
41+
await InstallDotnetSdkAsyncCore(job, $"--jsonfile {globalJsonPath}", installDir);
42+
43+
public static async Task InstallDotnetDailySdkAsync(JobBase job, int version, string? installDir = null) =>
44+
await InstallDotnetSdkAsyncCore(job, $"--channel {version}.0 --quality daily", installDir);
45+
46+
private static async Task InstallDotnetSdkAsyncCore(JobBase job, string versionArgs, string? installDir = null)
47+
{
48+
installDir ??= "/usr/lib/dotnet";
49+
50+
if (!File.Exists("dotnet-install.sh"))
51+
{
52+
await job.RunProcessAsync("wget", "https://dot.net/v1/dotnet-install.sh");
53+
}
54+
55+
await job.RunProcessAsync("bash", $"dotnet-install.sh {versionArgs} --install-dir {installDir}");
56+
}
3957
}

Runner/Helpers/RuntimeHelpers.cs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -202,21 +202,7 @@ string GetMergeScript(string name)
202202

203203
public static async Task InstallRuntimeDotnetSdkAsync(JobBase job, string? installDir = null)
204204
{
205-
await InstallDotnetSdkAsync(job, "runtime/global.json", installDir);
206-
}
207-
208-
public static async Task InstallDotnetSdkAsync(JobBase job, string globalJsonPath, string? installDir = null)
209-
{
210-
AssertIsLinux();
211-
212-
installDir ??= "/usr/lib/dotnet";
213-
214-
if (!File.Exists("dotnet-install.sh"))
215-
{
216-
await job.RunProcessAsync("wget", "https://dot.net/v1/dotnet-install.sh");
217-
}
218-
219-
await job.RunProcessAsync("bash", $"dotnet-install.sh --jsonfile {globalJsonPath} --install-dir {installDir}");
205+
await DotnetHelpers.InstallDotnetSdkAsync(job, "runtime/global.json", installDir);
220206
}
221207

222208
public static async Task CopyReleaseArtifactsAsync(JobBase job, string logPrefix, string destination, string runtimeConfig = "Release")

Runner/Jobs/BenchmarkLibrariesJob.cs

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ protected override async Task RunJobCoreAsync()
3232
{
3333
await clonePerformanceTask;
3434

35-
PendingTasks.Enqueue(RuntimeHelpers.InstallDotnetSdkAsync(this, "performance/global.json", DotnetInstallDir));
35+
PendingTasks.Enqueue(Task.Run(InstallDotnetSdksAsync));
3636

3737
coreRuns = await DownloadCoreRootsAsync(entries);
3838
}
@@ -65,22 +65,20 @@ protected override async Task RunJobCoreAsync()
6565
await JitDiffJob.BuildAndCopyRuntimeBranchBitsAsync(this, "pr", uploadArtifacts: false, buildChecked: false, canSkipRebuild: false);
6666
}
6767

68-
await RuntimeHelpers.InstallRuntimeDotnetSdkAsync(this, DotnetInstallDir);
69-
70-
await RuntimeHelpers.InstallDotnetSdkAsync(this, "performance/global.json", DotnetInstallDir);
68+
await InstallDotnetSdksAsync();
7169

7270
coreRuns = ["artifacts-main/corerun", "artifacts-pr/corerun"];
7371
}
7472

7573
await WaitForPendingTasksAsync();
7674

77-
try
75+
await RunBenchmarksAsync(coreRuns);
76+
77+
async Task InstallDotnetSdksAsync()
7878
{
79-
File.Delete("../NuGet.config");
79+
await DotnetHelpers.InstallDotnetSdkAsync(this, "performance/global.json", DotnetInstallDir);
80+
await DotnetHelpers.InstallDotnetDailySdkAsync(this, GetPerformanceDotnetVersion(), DotnetInstallDir);
8081
}
81-
catch { }
82-
83-
await RunBenchmarksAsync(coreRuns);
8482
}
8583

8684
private async Task CloneDotnetPerformanceAndSetupToolsAsync()
@@ -193,6 +191,23 @@ private async Task CloneDotnetPerformanceAndSetupToolsAsync()
193191
}
194192
}
195193

194+
private int GetPerformanceDotnetVersion()
195+
{
196+
string source = File.ReadAllText("performance/src/benchmarks/micro/MicroBenchmarks.csproj");
197+
// <SupportedTargetFrameworks>net6.0;net7.0;net8.0;net9.0;net10.0;net11.0</SupportedTargetFrameworks>
198+
199+
Match match = DotnetVersionFromCsprojRegex().Match(source);
200+
201+
if (!match.Success)
202+
{
203+
throw new Exception("Failed to determine the dotnet version from MicroBenchmarks.csproj");
204+
}
205+
206+
// ["net6.0", "net7.0", ...]
207+
string[] frameworks = match.Groups[1].Value.Split(';', StringSplitOptions.RemoveEmptyEntries);
208+
return frameworks.Max(f => int.Parse(f.AsSpan(3, f.IndexOf('.') - 3)));
209+
}
210+
196211
private async Task<string[]> DownloadCoreRootsAsync(CoreRootAPI.CoreRootEntry[] entries)
197212
{
198213
for (int i = 0; i < entries.Length; i++)
@@ -229,7 +244,7 @@ private async Task RunBenchmarksAsync(string[] coreRunPaths)
229244
filter = $"*{filter}*";
230245
}
231246

232-
int dotnetVersion = RuntimeHelpers.GetDotnetVersion("performance");
247+
int dotnetVersion = GetPerformanceDotnetVersion();
233248

234249
string coreRuns = string.Join(' ', coreRunPaths.Select(p => $"\"{Path.GetFullPath(p)}\""));
235250

@@ -386,4 +401,7 @@ await RunProcessAsync(dotnetPath,
386401

387402
[GeneratedRegex(@"BenchmarkDotNet\.(\d.*?)\.nupkg")]
388403
private static partial Regex BenchmarkDotNetPackageVersionRegex();
404+
405+
[GeneratedRegex(@"Frameworks>((?:net\d+\.\d+);?)+<\/")]
406+
private static partial Regex DotnetVersionFromCsprojRegex();
389407
}

0 commit comments

Comments
 (0)