Skip to content

Commit 8a7caa7

Browse files
[build] Rework ReadmeUpdater
1 parent 398ae65 commit 8a7caa7

File tree

9 files changed

+63
-135
lines changed

9 files changed

+63
-135
lines changed

README.md

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ It's no harder than writing unit tests!
3030
Under the hood, it performs a lot of [magic](#automation) that guarantees [reliable and precise](#reliability) results thanks to the [perfolizer](https://github.com/AndreyAkinshin/perfolizer) statistical engine.
3131
BenchmarkDotNet protects you from popular benchmarking mistakes and warns you if something is wrong with your benchmark design or obtained measurements.
3232
The results are presented in a [user-friendly](#friendliness) form that highlights all the important facts about your experiment.
33-
The library is adopted by [16600+ GitHub projects](#who-uses-benchmarkdotnet) including .NET Runtime.
33+
BenchmarkDotNet is already adopted by [16600+ GitHub projects](https://github.com/dotnet/BenchmarkDotNet/network/dependents) including
34+
[.NET Runtime](https://github.com/dotnet/runtime),
35+
[.NET Compiler](https://github.com/dotnet/roslyn),
36+
[.NET Performance](https://github.com/dotnet/performance),
37+
and many others.
3438

3539
It's [easy](#simplicity) to start writing benchmarks, check out the following example
3640
(copy-pastable version is [here](https://benchmarkdotnet.org/articles/guides/getting-started.html)):
@@ -229,44 +233,6 @@ Of course, you can request any additional statistics and visualizations manually
229233
If you don't customize the summary view,
230234
the default presentation will be as much user-friendly as possible. :)
231235

232-
## Who uses BenchmarkDotNet?
233-
234-
Everyone!
235-
BenchmarkDotNet is already adopted by more than [16600+](https://github.com/dotnet/BenchmarkDotNet/network/dependents?package_id=UGFja2FnZS0xNTY3MzExMzE%3D) projects including
236-
[dotnet/performance](https://github.com/dotnet/performance) (reference benchmarks for all .NET Runtimes),
237-
[dotnet/runtime](https://github.com/dotnet/runtime/issues?utf8=%E2%9C%93&q=BenchmarkDotNet) (.NET runtime and libraries),
238-
[Roslyn](https://github.com/dotnet/roslyn/search?q=BenchmarkDotNet&type=Issues&utf8=✓) (C# and Visual Basic compiler),
239-
[Mono](https://github.com/mono/mono/tree/master/sdks/wasm/bench-runner),
240-
[ASP.NET Core](https://github.com/aspnet/AspNetCore/tree/master/src/Servers/IIS/IIS/benchmarks),
241-
[ML.NET](https://github.com/dotnet/machinelearning/tree/main/test/Microsoft.ML.PerformanceTests),
242-
[Entity Framework Core](https://github.com/dotnet/efcore/tree/master/benchmark),
243-
[PowerShell](https://github.com/PowerShell/PowerShell/tree/master/test/perf/benchmarks)
244-
[SignalR](https://github.com/aspnet/SignalR/tree/master/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks),
245-
[F#](https://github.com/fsharp/fsharp/blob/master/tests/scripts/array-perf/array-perf.fs),
246-
[Orleans](https://github.com/dotnet/orleans/tree/master/test/Benchmarks),
247-
[Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json/tree/master/Src/Newtonsoft.Json.Tests/Benchmarks),
248-
[Elasticsearch.Net](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/bool-queries.html#_perfomance_considerations),
249-
[Dapper](https://github.com/DapperLib/Dapper/tree/main/benchmarks/Dapper.Tests.Performance),
250-
[Expecto](https://github.com/haf/expecto/tree/master/Expecto.BenchmarkDotNet),
251-
[ImageSharp](https://github.com/SixLabors/ImageSharp/tree/master/tests/ImageSharp.Benchmarks),
252-
[RavenDB](https://github.com/ravendb/ravendb/tree/v4.0/bench),
253-
[NodaTime](https://github.com/nodatime/nodatime/tree/master/src/NodaTime.Benchmarks),
254-
[Jint](https://github.com/sebastienros/jint/tree/dev/Jint.Benchmark),
255-
[NServiceBus](https://github.com/Particular/NServiceBus/issues?utf8=✓&q=+BenchmarkDotNet+),
256-
[Serilog](https://github.com/serilog/serilog/tree/dev/test/Serilog.PerformanceTests),
257-
[Autofac](https://github.com/autofac/Autofac/tree/develop/bench/Autofac.Benchmarks),
258-
[Npgsql](https://github.com/npgsql/npgsql/tree/main/test/Npgsql.Benchmarks),
259-
[Avalonia](https://github.com/AvaloniaUI/Avalonia/tree/master/tests/Avalonia.Benchmarks),
260-
[ReactiveUI](https://github.com/reactiveui/ReactiveUI/tree/master/src/Benchmarks),
261-
[SharpZipLib](https://github.com/icsharpcode/SharpZipLib/tree/master/benchmark/ICSharpCode.SharpZipLib.Benchmark),
262-
[LiteDB](https://github.com/mbdavid/LiteDB/tree/master/LiteDB.Benchmarks),
263-
[GraphQL for .NET](https://github.com/graphql-dotnet/graphql-dotnet/tree/master/src/GraphQL.Benchmarks),
264-
[.NET Docs](https://github.com/dotnet/docs/tree/master/samples/snippets/csharp/safe-efficient-code/benchmark),
265-
[RestSharp](https://github.com/restsharp/RestSharp/tree/dev/benchmarks/RestSharp.Benchmarks),
266-
[MediatR](https://github.com/jbogard/MediatR/tree/master/test/MediatR.Benchmarks),
267-
[TensorFlow.NET](https://github.com/SciSharp/TensorFlow.NET/tree/master/src/TensorFlowNet.Benchmarks),
268-
[Apache Thrift](https://github.com/apache/thrift/tree/master/lib/netstd/Benchmarks/Thrift.Benchmarks).
269-
270236
## Learn more about benchmarking
271237

272238
BenchmarkDotNet is not a silver bullet that magically makes all of your benchmarks correct and analyzes the measurements for you.

build/BenchmarkDotNet.Build/BuildContext.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class BuildContext : FrostingContext
3434
public FilePathCollection AllPackableSrcProjects { get; }
3535
public FilePath VersionsFile { get; }
3636
public FilePath CommonPropsFile { get; }
37+
public FilePath ReadmeFile { get; }
3738

3839
public DotNetMSBuildSettings MsBuildSettingsRestore { get; }
3940
public DotNetMSBuildSettings MsBuildSettingsBuild { get; }
@@ -68,6 +69,7 @@ public BuildContext(ICakeContext context)
6869

6970
VersionsFile = BuildDirectory.CombineWithFilePath("versions.txt");
7071
CommonPropsFile = BuildDirectory.CombineWithFilePath("common.props");
72+
ReadmeFile = RootDirectory.CombineWithFilePath("README.md");
7173

7274
MsBuildSettingsRestore = new DotNetMSBuildSettings();
7375
MsBuildSettingsBuild = new DotNetMSBuildSettings();

build/BenchmarkDotNet.Build/CommandLineParser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ private void PrintTaskHelp(string taskName)
143143
? $"Task '{taskName}': {taskDescription}"
144144
: $"Task '{taskName}'");
145145

146-
if (string.IsNullOrWhiteSpace(helpInfo.Description))
146+
if (!string.IsNullOrWhiteSpace(helpInfo.Description))
147147
foreach (var line in helpInfo.Description.Split('\n', StringSplitOptions.RemoveEmptyEntries))
148148
{
149149
WritePrefix();
150-
WriteLine(line.Trim());
150+
WriteLine(line.TrimEnd());
151151
}
152152

153153
WriteLine();

build/BenchmarkDotNet.Build/Helpers/Utils.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Runtime.InteropServices;
4-
using BenchmarkDotNet.Build.Options;
5-
using Cake.Common.Diagnostics;
4+
using System.Text.RegularExpressions;
65
using Cake.Common.Tools.DotNet;
76
using Octokit;
87

@@ -48,4 +47,15 @@ public static GitHubClient CreateGitHubClient()
4847
client.Credentials = tokenAuth;
4948
return client;
5049
}
50+
51+
public static string ApplyRegex(string content, string pattern, string newValue)
52+
{
53+
var regex = new Regex(pattern);
54+
var match = regex.Match(content);
55+
if (!match.Success)
56+
throw new Exception("Failed to apply regex");
57+
58+
var oldValue = match.Groups[1].Value;
59+
return content.Replace(oldValue, newValue);
60+
}
5161
}

build/BenchmarkDotNet.Build/Meta/Repo.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
using System;
2+
using System.Net.Http;
3+
using System.Text.RegularExpressions;
4+
using System.Threading.Tasks;
5+
16
namespace BenchmarkDotNet.Build.Meta;
27

38
public static class Repo
@@ -10,4 +15,17 @@ public static class Repo
1015
public const string ChangelogDetailsBranch = "docs-changelog-details";
1116
public const string DocsStableBranch = "docs-stable";
1217
public const string MasterBranch = "master";
18+
19+
public static async Task<int> GetDependentProjectsNumber()
20+
{
21+
using var httpClient = new HttpClient();
22+
const string url = $"{HttpsUrlBase}/network/dependents";
23+
var response = await httpClient.GetAsync(new Uri(url));
24+
var dependentsPage = await response.Content.ReadAsStringAsync();
25+
var match = new Regex(@"([0-9\,]+)[\n\r\s]+Repositories").Match(dependentsPage);
26+
var number = int.Parse(match.Groups[1].Value.Replace(",", ""));
27+
number = number / 100 * 100;
28+
return number;
29+
}
30+
1331
}

build/BenchmarkDotNet.Build/Program.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using BenchmarkDotNet.Build.Meta;
12
using BenchmarkDotNet.Build.Options;
23
using Cake.Common;
34
using Cake.Frosting;
@@ -146,6 +147,11 @@ public HelpInfo GetHelp()
146147
{
147148
return new HelpInfo
148149
{
150+
Description = $"This task updates the following files:\n" +
151+
$"* README.md (the number of dependent projects number)\n" +
152+
$"* Last changelog footer (if {KnownOptions.Stable.CommandLineName} is specified)\n" +
153+
$"* All changelog details in docs/_changelog\n" +
154+
$" (This dir is a cloned version of this repo from branch {Repo.ChangelogDetailsBranch})",
149155
Options = new IOption[] { KnownOptions.DocsPreview, KnownOptions.DocsDepth },
150156
EnvironmentVariables = new[] { EnvVar.GitHubToken },
151157
Examples = new[]

build/BenchmarkDotNet.Build/Runners/DocumentationRunner.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.IO;
44
using System.Linq;
55
using System.Text;
6+
using BenchmarkDotNet.Build.Helpers;
67
using BenchmarkDotNet.Build.Meta;
78
using BenchmarkDotNet.Build.Options;
89
using Cake.Common.Diagnostics;
@@ -59,7 +60,7 @@ public void Update()
5960
{
6061
EnvVar.GitHubToken.AssertHasValue();
6162

62-
ReadmeUpdater.Run(context);
63+
UpdateReadme();
6364
UpdateLastFooter();
6465

6566
EnsureChangelogDetailsExist();
@@ -96,6 +97,17 @@ public void Update()
9697
"HEAD");
9798
}
9899

100+
private void UpdateReadme()
101+
{
102+
var content = Utils.ApplyRegex(
103+
context.FileReadText(context.ReadmeFile),
104+
@"\[(\d+)\+ GitHub projects\]",
105+
Repo.GetDependentProjectsNumber().Result.ToString()
106+
);
107+
108+
context.GenerateFile(context.ReadmeFile, content, true);
109+
}
110+
99111
public void Prepare()
100112
{
101113
foreach (var version in context.VersionHistory.StableVersions)

build/BenchmarkDotNet.Build/Runners/ReadmeUpdater.cs

Lines changed: 0 additions & 82 deletions
This file was deleted.

build/BenchmarkDotNet.Build/Runners/ReleaseRunner.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,11 @@ private void UpdateVersionsTxt(string versionToAppend)
6767

6868
private void UpdateCommonProps(string newCurrentVersion)
6969
{
70-
var regex = new Regex(@"<VersionPrefix>([\d\.]+)</VersionPrefix>");
71-
72-
var content = context.FileReadText(context.CommonPropsFile);
73-
var match = regex.Match(content);
74-
if (!match.Success)
75-
throw new Exception($"Failed to find VersionPrefix definition in {context.CommonPropsFile}");
76-
77-
var oldVersion = match.Groups[1].Value;
78-
context.GenerateFile(context.CommonPropsFile, content.Replace(oldVersion, newCurrentVersion));
70+
var content = Utils.ApplyRegex(
71+
context.FileReadText(context.CommonPropsFile),
72+
@"<VersionPrefix>([\d\.]+)</VersionPrefix>",
73+
newCurrentVersion);
74+
context.GenerateFile(context.CommonPropsFile, content);
7975
}
8076

8177
private async Task UpdateMilestones(string nextVersion)

0 commit comments

Comments
 (0)