Skip to content

Commit bf020e9

Browse files
Automatically update changelog footer
1 parent d4c70ed commit bf020e9

File tree

4 files changed

+55
-11
lines changed

4 files changed

+55
-11
lines changed

build/BenchmarkDotNet.Build/BuildContext.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.IO;
34
using System.Linq;
45
using System.Text;
@@ -24,6 +25,7 @@ public class BuildContext : FrostingContext
2425
public string BuildConfiguration { get; set; } = "Release";
2526
public DotNetVerbosity BuildVerbosity { get; set; } = DotNetVerbosity.Minimal;
2627
public int Depth { get; set; }
28+
public bool VersionStable { get; }
2729

2830
public DirectoryPath RootDirectory { get; }
2931
public DirectoryPath BuildDirectory { get; }
@@ -39,6 +41,8 @@ public class BuildContext : FrostingContext
3941

4042
private bool IsCiBuild => !this.BuildSystem().IsLocalBuild;
4143

44+
public IReadOnlyCollection<string> NuGetPackageNames { get; }
45+
4246
public VersionHistory VersionHistory { get; }
4347

4448
public UnitTestRunner UnitTestRunner { get; }
@@ -73,6 +77,7 @@ public BuildContext(ICakeContext context)
7377
}
7478

7579
Depth = -1;
80+
VersionStable = false;
7681
if (context.Arguments.HasArgument("msbuild"))
7782
{
7883
var msBuildParameters = context.Arguments.GetArguments().First(it => it.Key == "msbuild").Value;
@@ -99,6 +104,9 @@ public BuildContext(ICakeContext context)
99104

100105
if (name.Equals("depth", StringComparison.OrdinalIgnoreCase))
101106
Depth = int.Parse(value);
107+
108+
if (name.Equals("VersionStable", StringComparison.OrdinalIgnoreCase) && value != "")
109+
VersionStable = true;
102110
}
103111
}
104112
}
@@ -112,6 +120,15 @@ public BuildContext(ICakeContext context)
112120
MsBuildSettingsBuild.WithProperty("Platform", "Any CPU");
113121
}
114122

123+
var nuGetPackageNames = new List<string>();
124+
nuGetPackageNames.AddRange(this
125+
.GetSubDirectories(RootDirectory.Combine("src"))
126+
.Select(directoryPath => directoryPath.GetDirectoryName())
127+
.Where(name => !name.Contains("Disassembler", StringComparison.OrdinalIgnoreCase)));
128+
nuGetPackageNames.Add("BenchmarkDotNet.Templates");
129+
nuGetPackageNames.Sort();
130+
NuGetPackageNames = nuGetPackageNames;
131+
115132
VersionHistory = new VersionHistory(this, BuildDirectory.CombineWithFilePath("versions.txt"));
116133

117134
UnitTestRunner = new UnitTestRunner(this);

build/BenchmarkDotNet.Build/Meta/VersionHistory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ public class VersionHistory
88
{
99
public string FirstCommit { get; }
1010
public string[] StableVersions { get; }
11-
public string NextVersion { get; }
11+
public string CurrentVersion { get; }
1212

1313
public VersionHistory(BuildContext context, FilePath versionFilePath)
1414
{
1515
var lines = context.FileReadLines(versionFilePath).Where(line => !string.IsNullOrWhiteSpace(line)).ToArray();
1616
FirstCommit = lines.First();
17-
NextVersion = lines.Last();
17+
CurrentVersion = lines.Last();
1818
StableVersions = lines.Skip(1).SkipLast(1).ToArray();
1919
}
2020
}

build/BenchmarkDotNet.Build/Runners/DocumentationRunner.cs

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Globalization;
23
using System.IO;
34
using System.Linq;
45
using System.Text;
@@ -26,6 +27,7 @@ public class DocumentationRunner
2627
private readonly FilePath changelogIndexFile;
2728
private readonly FilePath changelogFullFile;
2829
private readonly FilePath changelogTocFile;
30+
private readonly FilePath lastFooterFile;
2931

3032
public DocumentationRunner(BuildContext context)
3133
{
@@ -34,8 +36,8 @@ public DocumentationRunner(BuildContext context)
3436
var docsDirectory = context.RootDirectory.Combine("docs");
3537
changelogDirectory = docsDirectory.Combine("changelog");
3638
changelogSrcDirectory = docsDirectory.Combine("_changelog");
37-
docsGeneratedDirectory = docsDirectory.Combine("_site");
3839
changelogDetailsDirectory = changelogSrcDirectory.Combine("details");
40+
docsGeneratedDirectory = docsDirectory.Combine("_site");
3941

4042
redirectFile = docsDirectory.Combine("_redirects").CombineWithFilePath("_redirects");
4143
docfxJsonFile = docsDirectory.CombineWithFilePath("docfx.json");
@@ -44,13 +46,16 @@ public DocumentationRunner(BuildContext context)
4446
changelogIndexFile = changelogDirectory.CombineWithFilePath("index.md");
4547
changelogFullFile = changelogDirectory.CombineWithFilePath("full.md");
4648
changelogTocFile = changelogDirectory.CombineWithFilePath("toc.yml");
49+
lastFooterFile = changelogSrcDirectory.Combine("footer")
50+
.CombineWithFilePath("v" + context.VersionHistory.CurrentVersion + ".md");
4751
}
4852

4953
public void Update()
5054
{
51-
EnsureChangelogDetailsExist();
52-
5355
ReadmeUpdater.Run(context);
56+
UpdateLastFooter();
57+
58+
EnsureChangelogDetailsExist();
5459

5560
if (string.IsNullOrEmpty(GitHubCredentials.Token))
5661
throw new Exception($"Environment variable '{GitHubCredentials.TokenVariableName}' is not specified!");
@@ -79,17 +84,16 @@ public void Update()
7984
}
8085

8186
DocfxChangelogDownload(
82-
history.NextVersion,
87+
history.CurrentVersion,
8388
history.StableVersions.Last(),
8489
"HEAD");
8590
}
8691

87-
8892
public void Prepare()
8993
{
9094
foreach (var version in context.VersionHistory.StableVersions)
9195
DocfxChangelogGenerate(version);
92-
DocfxChangelogGenerate(context.VersionHistory.NextVersion);
96+
DocfxChangelogGenerate(context.VersionHistory.CurrentVersion);
9397

9498
GenerateIndexMd();
9599
GenerateChangelogIndex();
@@ -263,4 +267,27 @@ private void GenerateRedirects()
263267
context.GenerateFile(fullFilePath, content);
264268
}
265269
}
270+
271+
private void UpdateLastFooter()
272+
{
273+
var version = context.VersionHistory.CurrentVersion;
274+
var previousVersion = context.VersionHistory.StableVersions.Last();
275+
var date = context.VersionStable
276+
? DateTime.Now.ToString("MMMM dd, yyyy", CultureInfo.InvariantCulture)
277+
: "TBA";
278+
279+
var content = new StringBuilder();
280+
content.AppendLine($"_Date: {date}_");
281+
content.AppendLine("");
282+
content.AppendLine(
283+
$"_Milestone: [v{version}](https://github.com/dotnet/BenchmarkDotNet/issues?q=milestone%3Av{version})_");
284+
content.AppendLine(
285+
$"([List of commits](https://github.com/dotnet/BenchmarkDotNet/compare/v{previousVersion}...v{version}))");
286+
content.AppendLine("");
287+
content.AppendLine("_NuGet Packages:_");
288+
foreach (var packageName in context.NuGetPackageNames)
289+
content.AppendLine($"* https://www.nuget.org/packages/{packageName}/{version}");
290+
291+
context.GenerateFile(lastFooterFile, content);
292+
}
266293
}

docs/_changelog/footer/v0.13.6.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ _Milestone: [v0.13.6](https://github.com/dotnet/BenchmarkDotNet/issues?q=milesto
55

66
_NuGet Packages:_
77
* https://www.nuget.org/packages/BenchmarkDotNet/0.13.6
8-
* https://www.nuget.org/packages/BenchmarkDotNet.Diagnostics.Windows/0.13.6
9-
* https://www.nuget.org/packages/BenchmarkDotNet.Diagnostics.dotTrace/0.13.6
108
* https://www.nuget.org/packages/BenchmarkDotNet.Annotations/0.13.6
11-
* https://www.nuget.org/packages/BenchmarkDotNet.Templates/0.13.6
9+
* https://www.nuget.org/packages/BenchmarkDotNet.Diagnostics.dotTrace/0.13.6
10+
* https://www.nuget.org/packages/BenchmarkDotNet.Diagnostics.Windows/0.13.6
11+
* https://www.nuget.org/packages/BenchmarkDotNet.Templates/0.13.6

0 commit comments

Comments
 (0)