Skip to content

Commit 319f0e2

Browse files
Remove hardcoded markdown from code, generate dynamically
This update makes the handling of changelog information more flexible and maintainable. Previously, chunks of markdown text were hardcoded into the code. This approach is unwieldy, and potentially error-prone, as it necessitates manually updating the code with each change. Now, the relevant data is dynamically generated, streamlining the process and reducing the possibility for manual entry errors.
1 parent d46c32a commit 319f0e2

File tree

5 files changed

+56
-233
lines changed

5 files changed

+56
-233
lines changed

build/Program.cs

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class BuildContext : FrostingContext
4444

4545
public DirectoryPath ChangeLogDirectory { get; }
4646
public DirectoryPath ChangeLogGenDirectory { get; }
47-
47+
4848
public DirectoryPath RedirectRootDirectory { get; }
4949
public DirectoryPath RedirectTargetDirectory { get; }
5050

@@ -53,13 +53,17 @@ public class BuildContext : FrostingContext
5353
public FilePath IntegrationTestsProjectFile { get; }
5454
public FilePath TemplatesTestsProjectFile { get; }
5555
public FilePathCollection AllPackableSrcProjects { get; }
56-
56+
5757
public DotNetMSBuildSettings MsBuildSettings { get; }
5858

5959
private IAppVeyorProvider AppVeyor => this.BuildSystem().AppVeyor;
6060
public bool IsRunningOnAppVeyor => AppVeyor.IsRunningOnAppVeyor;
6161
public bool IsOnAppVeyorAndNotPr => IsRunningOnAppVeyor && !AppVeyor.Environment.PullRequest.IsPullRequest;
62-
public bool IsOnAppVeyorAndBdnNightlyCiCd => IsOnAppVeyorAndNotPr && AppVeyor.Environment.Repository.Branch == "master" && this.IsRunningOnWindows();
62+
63+
public bool IsOnAppVeyorAndBdnNightlyCiCd => IsOnAppVeyorAndNotPr &&
64+
AppVeyor.Environment.Repository.Branch == "master" &&
65+
this.IsRunningOnWindows();
66+
6367
public bool IsLocalBuild => this.BuildSystem().IsLocalBuild;
6468
public bool IsCiBuild => !this.BuildSystem().IsLocalBuild;
6569

@@ -80,9 +84,9 @@ public BuildContext(ICakeContext context)
8084

8185
ChangeLogDirectory = RootDirectory.Combine("docs").Combine("changelog");
8286
ChangeLogGenDirectory = RootDirectory.Combine("docs").Combine("_changelog");
83-
87+
8488
RedirectRootDirectory = RootDirectory.Combine("docs").Combine("_redirects");
85-
RedirectTargetDirectory = RootDirectory.Combine("docs").Combine("_site");
89+
RedirectTargetDirectory = RootDirectory.Combine("docs").Combine("_site");
8690

8791
SolutionFile = RootDirectory.CombineWithFilePath("BenchmarkDotNet.sln");
8892
UnitTestsProjectFile = RootDirectory.Combine("tests").Combine("BenchmarkDotNet.Tests")
@@ -189,7 +193,7 @@ public void DocfxChangelogGenerate(string version)
189193
public void RunDocfx(FilePath docfxJson)
190194
{
191195
this.Information($"Running docfx for '{docfxJson}'");
192-
196+
193197
var currentDirectory = Directory.GetCurrentDirectory();
194198
Directory.SetCurrentDirectory(docfxJson.GetDirectory().FullPath);
195199
Microsoft.DocAsCode.Dotnet.DotnetApiCatalog.GenerateManagedReferenceYamlFiles(docfxJson.FullPath).Wait();
@@ -350,7 +354,7 @@ public override void Run(BuildContext context)
350354
? new[] { "net462", "net7.0" }
351355
: new[] { "net7.0" };
352356

353-
foreach (var targetFramework in targetFrameworks)
357+
foreach (var targetFramework in targetFrameworks)
354358
context.RunTests(context.UnitTestsProjectFile, "UnitTests", targetFramework);
355359
}
356360
}
@@ -361,7 +365,8 @@ public class SlowFullFrameworkTestsTask : FrostingTask<BuildContext>
361365
{
362366
public override bool ShouldRun(BuildContext context)
363367
{
364-
return !context.SkipTests && !context.SkipSlowTests && context.IsRunningOnWindows() && !context.IsRunningOnAppVeyor;
368+
return !context.SkipTests && !context.SkipSlowTests && context.IsRunningOnWindows() &&
369+
!context.IsRunningOnAppVeyor;
365370
}
366371

367372
public override void Run(BuildContext context)
@@ -416,7 +421,7 @@ public override void Run(BuildContext context)
416421

417422
foreach (var project in context.AllPackableSrcProjects)
418423
context.DotNetPack(project.FullPath, settingsSrc);
419-
424+
420425
var settingsTemplate = new DotNetPackSettings
421426
{
422427
Configuration = context.BuildConfiguration,
@@ -445,15 +450,17 @@ public override void Run(BuildContext context)
445450
context.DocfxChangelogDownload(
446451
DocumentationHelper.BdnAllVersions.First(),
447452
DocumentationHelper.BdnFirstCommit);
448-
453+
449454
for (int i = 1; i < DocumentationHelper.BdnAllVersions.Length; i++)
450455
context.DocfxChangelogDownload(
451456
DocumentationHelper.BdnAllVersions[i],
452457
DocumentationHelper.BdnAllVersions[i - 1]);
453458
}
454459
else if (context.Argument("LatestVersions", false))
455460
{
456-
for (int i = DocumentationHelper.BdnAllVersions.Length - 3; i < DocumentationHelper.BdnAllVersions.Length; i++)
461+
for (int i = DocumentationHelper.BdnAllVersions.Length - 3;
462+
i < DocumentationHelper.BdnAllVersions.Length;
463+
i++)
457464
context.DocfxChangelogDownload(
458465
DocumentationHelper.BdnAllVersions[i],
459466
DocumentationHelper.BdnAllVersions[i - 1]);
@@ -475,10 +482,42 @@ public override void Run(BuildContext context)
475482
context.DocfxChangelogGenerate(version);
476483
context.DocfxChangelogGenerate(DocumentationHelper.BdnNextVersion);
477484

478-
context.CopyFile(context.ChangeLogGenDirectory.CombineWithFilePath("index.md"),
479-
context.ChangeLogDirectory.CombineWithFilePath("index.md"));
480-
context.CopyFile(context.ChangeLogGenDirectory.CombineWithFilePath("full.md"),
481-
context.ChangeLogDirectory.CombineWithFilePath("full.md"));
485+
context.Information("DocfxChangelogGenerate: index.md");
486+
var indexContent = new StringBuilder();
487+
indexContent.AppendLine("---");
488+
indexContent.AppendLine("uid: changelog");
489+
indexContent.AppendLine("---");
490+
indexContent.AppendLine("");
491+
indexContent.AppendLine("# ChangeLog");
492+
indexContent.AppendLine("");
493+
foreach (var version in DocumentationHelper.BdnAllVersions.Reverse())
494+
indexContent.AppendLine($"* @changelog.{version}");
495+
indexContent.AppendLine("* @changelog.full");
496+
context.FileWriteText(context.ChangeLogDirectory.CombineWithFilePath("index.md"), indexContent.ToString());
497+
498+
context.Information("DocfxChangelogGenerate: full.md");
499+
var fullContent = new StringBuilder();
500+
fullContent.AppendLine("---");
501+
fullContent.AppendLine("uid: changelog");
502+
fullContent.AppendLine("---");
503+
fullContent.AppendLine("");
504+
fullContent.AppendLine("# Full ChangeLog");
505+
fullContent.AppendLine("");
506+
foreach (var version in DocumentationHelper.BdnAllVersions.Reverse())
507+
indexContent.AppendLine($"[!include[{version}]({version}.md)]");
508+
context.FileWriteText(context.ChangeLogDirectory.CombineWithFilePath("full.md"), fullContent.ToString());
509+
510+
context.Information("DocfxChangelogGenerate: toc.yml");
511+
var tocContent = new StringBuilder();
512+
foreach (var version in DocumentationHelper.BdnAllVersions.Reverse())
513+
{
514+
tocContent.AppendLine($"- name: {version}");
515+
tocContent.AppendLine($" href: {version}.md");
516+
}
517+
518+
tocContent.AppendLine("- name: Full ChangeLog");
519+
tocContent.AppendLine(" href: full.md");
520+
context.FileWriteText(context.ChangeLogDirectory.CombineWithFilePath("toc.yml"), tocContent.ToString());
482521
}
483522
}
484523

docs/_changelog/full.md

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

docs/_changelog/index.md

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

docs/changelog/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
*.md
1+
*.md
2+
*.yml

docs/changelog/toc.yml

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

0 commit comments

Comments
 (0)