Skip to content

Commit c0cbd25

Browse files
Add version history to BuildContext
A new property called 'VersionHistory' was added to the 'BuildContext' class. This was done to manage historical version data and facilitate the automatic processing of changelogs for different versions. The version data was previously stored in the 'DocumentationHelper' class, but this was renamed to 'VersionHistory' and refactored to fetch historical data from a text file ('versions.txt'). This addition and changes improve the manageability and flexibility of handling version data for documentation generation.
1 parent 2b8bc88 commit c0cbd25

File tree

5 files changed

+102
-81
lines changed

5 files changed

+102
-81
lines changed

build/BenchmarkDotNet.Build/BuildContext.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class BuildContext : FrostingContext
2727
public int Depth { get; set; }
2828

2929
public DirectoryPath RootDirectory { get; }
30+
public DirectoryPath BuildDirectory { get; }
3031
public DirectoryPath ArtifactsDirectory { get; }
3132
public DirectoryPath DocsDirectory { get; }
3233
public FilePath DocfxJsonFile { get; }
@@ -56,6 +57,8 @@ public class BuildContext : FrostingContext
5657
public bool IsLocalBuild => this.BuildSystem().IsLocalBuild;
5758
public bool IsCiBuild => !this.BuildSystem().IsLocalBuild;
5859

60+
public VersionHistory VersionHistory { get; }
61+
5962
public UnitTestRunner UnitTestRunner { get; }
6063
public DocumentationRunner DocumentationRunner { get; }
6164
public BuildRunner BuildRunner { get; }
@@ -64,6 +67,7 @@ public BuildContext(ICakeContext context)
6467
: base(context)
6568
{
6669
RootDirectory = new DirectoryPath(new DirectoryInfo(Directory.GetCurrentDirectory()).Parent?.Parent?.FullName);
70+
BuildDirectory = RootDirectory.Combine("build");
6771
ArtifactsDirectory = RootDirectory.Combine("artifacts");
6872
DocsDirectory = RootDirectory.Combine("docs");
6973
DocfxJsonFile = DocsDirectory.CombineWithFilePath("docfx.json");
@@ -133,6 +137,8 @@ public BuildContext(ICakeContext context)
133137
MsBuildSettingsBuild.WithProperty("Platform", "Any CPU");
134138
}
135139

140+
VersionHistory = new VersionHistory(this, BuildDirectory.CombineWithFilePath("versions.txt"));
141+
136142
UnitTestRunner = new UnitTestRunner(this);
137143
DocumentationRunner = new DocumentationRunner(this);
138144
BuildRunner = new BuildRunner(this);

build/BenchmarkDotNet.Build/Meta/DocumentationHelper.cs

Lines changed: 0 additions & 62 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Linq;
2+
using Cake.Core.IO;
3+
using Cake.FileHelpers;
4+
5+
namespace BenchmarkDotNet.Build.Meta;
6+
7+
public class VersionHistory
8+
{
9+
public string FirstCommit { get; }
10+
public string[] StableVersions { get; }
11+
public string NextVersion { get; }
12+
13+
public VersionHistory(BuildContext context, FilePath versionFilePath)
14+
{
15+
var lines = context.FileReadLines(versionFilePath).Where(line => !string.IsNullOrWhiteSpace(line)).ToArray();
16+
FirstCommit = lines.First();
17+
NextVersion = lines.Last();
18+
StableVersions = lines.Skip(1).SkipLast(1).ToArray();
19+
}
20+
}

build/BenchmarkDotNet.Build/Runners/DocumentationRunner.cs

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -87,39 +87,43 @@ public void Update()
8787
if (string.IsNullOrEmpty(Repo.Token))
8888
throw new Exception($"Environment variable '{Repo.TokenVar}' is not specified!");
8989

90-
var count = context.Depth;
91-
var total = DocumentationHelper.BdnAllVersions.Length;
90+
var history = context.VersionHistory;
9291

93-
if (count == 0)
92+
var depth = context.Depth;
93+
var stableVersionCount = history.StableVersions.Length;
94+
95+
if (depth == 0)
9496
{
9597
context.DocfxChangelogDownload(
96-
DocumentationHelper.BdnAllVersions.First(),
97-
DocumentationHelper.BdnFirstCommit);
98+
history.StableVersions.First(),
99+
history.FirstCommit);
98100

99-
for (int i = 1; i < total; i++)
101+
for (int i = 1; i < stableVersionCount; i++)
100102
context.DocfxChangelogDownload(
101-
DocumentationHelper.BdnAllVersions[i],
102-
DocumentationHelper.BdnAllVersions[i - 1]);
103+
history.StableVersions[i],
104+
history.StableVersions[i - 1]);
103105
}
104-
else if (count > 0)
106+
else if (depth > 0)
105107
{
106-
for (int i = Math.Max(total - count, 1); i < total; i++)
108+
for (int i = Math.Max(stableVersionCount - depth, 1); i < stableVersionCount; i++)
107109
context.DocfxChangelogDownload(
108-
DocumentationHelper.BdnAllVersions[i],
109-
DocumentationHelper.BdnAllVersions[i - 1]);
110+
history.StableVersions[i],
111+
history.StableVersions[i - 1]);
110112
}
111113

112114
context.DocfxChangelogDownload(
113-
DocumentationHelper.BdnNextVersion,
114-
DocumentationHelper.BdnAllVersions.Last(),
115+
history.NextVersion,
116+
history.StableVersions.Last(),
115117
"HEAD");
116118
}
117119

118120
public void Prepare()
119121
{
120-
foreach (var version in DocumentationHelper.BdnAllVersions)
122+
var history = context.VersionHistory;
123+
124+
foreach (var version in history.StableVersions)
121125
context.DocfxChangelogGenerate(version);
122-
context.DocfxChangelogGenerate(DocumentationHelper.BdnNextVersion);
126+
context.DocfxChangelogGenerate(history.NextVersion);
123127

124128
context.Information("DocfxChangelogGenerate: index.md");
125129
var indexContent = new StringBuilder();
@@ -129,7 +133,7 @@ public void Prepare()
129133
indexContent.AppendLine("");
130134
indexContent.AppendLine("# ChangeLog");
131135
indexContent.AppendLine("");
132-
foreach (var version in DocumentationHelper.BdnAllVersions.Reverse())
136+
foreach (var version in history.StableVersions.Reverse())
133137
indexContent.AppendLine($"* @changelog.{version}");
134138
indexContent.AppendLine("* @changelog.full");
135139
context.FileWriteText(context.ChangeLogDirectory.CombineWithFilePath("index.md"), indexContent.ToString());
@@ -142,13 +146,13 @@ public void Prepare()
142146
fullContent.AppendLine("");
143147
fullContent.AppendLine("# Full ChangeLog");
144148
fullContent.AppendLine("");
145-
foreach (var version in DocumentationHelper.BdnAllVersions.Reverse())
149+
foreach (var version in history.StableVersions.Reverse())
146150
fullContent.AppendLine($"[!include[{version}]({version}.md)]");
147151
context.FileWriteText(context.ChangeLogDirectory.CombineWithFilePath("full.md"), fullContent.ToString());
148152

149153
context.Information("DocfxChangelogGenerate: toc.yml");
150154
var tocContent = new StringBuilder();
151-
foreach (var version in DocumentationHelper.BdnAllVersions.Reverse())
155+
foreach (var version in history.StableVersions.Reverse())
152156
{
153157
tocContent.AppendLine($"- name: {version}");
154158
tocContent.AppendLine($" href: {version}.md");

build/versions.txt

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
6eda98ab1e83a0d185d09ff8b24c795711af8db1
2+
0.7.0
3+
0.7.1
4+
0.7.2
5+
0.7.3
6+
0.7.4
7+
0.7.5
8+
0.7.6
9+
0.7.7
10+
0.7.8
11+
0.8.0
12+
0.8.1
13+
0.8.2
14+
0.9.0
15+
0.9.1
16+
0.9.2
17+
0.9.3
18+
0.9.4
19+
0.9.5
20+
0.9.6
21+
0.9.7
22+
0.9.8
23+
0.9.9
24+
0.10.0
25+
0.10.1
26+
0.10.2
27+
0.10.3
28+
0.10.4
29+
0.10.5
30+
0.10.6
31+
0.10.7
32+
0.10.8
33+
0.10.9
34+
0.10.10
35+
0.10.11
36+
0.10.12
37+
0.10.13
38+
0.10.14
39+
0.11.0
40+
0.11.1
41+
0.11.2
42+
0.11.3
43+
0.11.4
44+
0.11.5
45+
0.12.0
46+
0.12.1
47+
0.13.0
48+
0.13.1
49+
0.13.2
50+
0.13.3
51+
0.13.4
52+
0.13.5
53+
0.13.6

0 commit comments

Comments
 (0)