From 7de12a1d3ee2b37351465ff2175d03d2898f045e Mon Sep 17 00:00:00 2001 From: Andrey Akinshin Date: Wed, 12 Jul 2023 16:01:38 +0400 Subject: [PATCH] [build] rework command line argument parsing --- .github/workflows/generate-changelog.yaml | 3 +- .github/workflows/generate-gh-pages.yaml | 3 +- build/BenchmarkDotNet.Build/BuildContext.cs | 12 +- .../BenchmarkDotNet.Build/ChangeLogBuilder.cs | 11 +- .../CommandLineParser.cs | 157 +++++++++--------- build/BenchmarkDotNet.Build/HelpInfo.cs | 5 +- .../Options/BoolOption.cs | 20 +++ .../BenchmarkDotNet.Build/Options/IOption.cs | 8 + .../Options/KnownOptions.cs | 37 +++++ build/BenchmarkDotNet.Build/Options/Option.cs | 40 +++++ .../Options/StringOption.cs | 19 +++ build/BenchmarkDotNet.Build/Program.cs | 24 ++- .../Runners/DocumentationRunner.cs | 50 ++++-- .../.template.config/template.json | 2 +- .../.template.config/template.json | 2 +- .../.template.config/template.json | 2 +- 16 files changed, 277 insertions(+), 118 deletions(-) create mode 100644 build/BenchmarkDotNet.Build/Options/BoolOption.cs create mode 100644 build/BenchmarkDotNet.Build/Options/IOption.cs create mode 100644 build/BenchmarkDotNet.Build/Options/KnownOptions.cs create mode 100644 build/BenchmarkDotNet.Build/Options/Option.cs create mode 100644 build/BenchmarkDotNet.Build/Options/StringOption.cs diff --git a/.github/workflows/generate-changelog.yaml b/.github/workflows/generate-changelog.yaml index 9589b92fc8..54dd5c2250 100644 --- a/.github/workflows/generate-changelog.yaml +++ b/.github/workflows/generate-changelog.yaml @@ -20,9 +20,8 @@ jobs: ref: master - name: Download changelog - run: ./build.cmd DocsUpdate /p:Depth=1 + run: ./build.cmd DocsUpdate --depth 1 --preview env: - GITHUB_PRODUCT: ChangelogBuilder GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Push changelog diff --git a/.github/workflows/generate-gh-pages.yaml b/.github/workflows/generate-gh-pages.yaml index 41bc3f9b59..868fa49c5c 100644 --- a/.github/workflows/generate-gh-pages.yaml +++ b/.github/workflows/generate-gh-pages.yaml @@ -23,9 +23,8 @@ jobs: run: ./build.cmd Build - name: Download changelog - run: ./build.cmd DocsUpdate /p:Depth=1 + run: ./build.cmd DocsUpdate --depth 1 --preview env: - GITHUB_PRODUCT: ChangelogBuilder GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Build documentation diff --git a/build/BenchmarkDotNet.Build/BuildContext.cs b/build/BenchmarkDotNet.Build/BuildContext.cs index d7b12205f9..d20e5891e7 100644 --- a/build/BenchmarkDotNet.Build/BuildContext.cs +++ b/build/BenchmarkDotNet.Build/BuildContext.cs @@ -16,7 +16,6 @@ using Cake.Core.IO; using Cake.FileHelpers; using Cake.Frosting; -using Cake.Git; namespace BenchmarkDotNet.Build; @@ -24,7 +23,6 @@ public class BuildContext : FrostingContext { public string BuildConfiguration { get; set; } = "Release"; public DotNetVerbosity BuildVerbosity { get; set; } = DotNetVerbosity.Minimal; - public int Depth { get; set; } public bool VersionStable { get; } public string NextVersion { get; } public bool PushMode { get; } @@ -85,7 +83,6 @@ public BuildContext(ICakeContext context) MsBuildSettingsBuild.WithProperty("UseSharedCompilation", "false"); } - Depth = -1; VersionStable = false; NextVersion = ""; PushMode = false; @@ -113,9 +110,6 @@ public BuildContext(ICakeContext context) BuildVerbosity = parsedVerbosity.Value; } - if (name.Equals("depth", StringComparison.OrdinalIgnoreCase)) - Depth = int.Parse(value); - if (name.Equals("VersionStable", StringComparison.OrdinalIgnoreCase) && value != "") VersionStable = true; @@ -160,14 +154,18 @@ public void GenerateFile(FilePath filePath, StringBuilder content) GenerateFile(filePath, content.ToString()); } - public void GenerateFile(FilePath filePath, string content) + public void GenerateFile(FilePath filePath, string content, bool reportNoChanges = false) { var relativePath = RootDirectory.GetRelativePath(filePath); if (this.FileExists(filePath)) { var oldContent = this.FileReadText(filePath); if (content == oldContent) + { + if (reportNoChanges) + this.Information("[NoChanges] " + relativePath); return; + } this.FileWriteText(filePath, content); this.Information("[Updated] " + relativePath); diff --git a/build/BenchmarkDotNet.Build/ChangeLogBuilder.cs b/build/BenchmarkDotNet.Build/ChangeLogBuilder.cs index 046c5fc728..a7537c51c6 100644 --- a/build/BenchmarkDotNet.Build/ChangeLogBuilder.cs +++ b/build/BenchmarkDotNet.Build/ChangeLogBuilder.cs @@ -1,12 +1,12 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; -using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using BenchmarkDotNet.Build.Helpers; using BenchmarkDotNet.Build.Meta; +using Cake.Common.Diagnostics; using Cake.Core.IO; using Octokit; @@ -174,17 +174,18 @@ private void AppendList(string title, IReadOnlyList items, Func } } - public static async Task Run(DirectoryPath path, string currentVersion, string previousVersion, string lastCommit) + public static void Run(BuildContext context, DirectoryPath path, + string currentVersion, string previousVersion, string lastCommit) { try { var config = new Config(currentVersion, previousVersion, lastCommit); - var releaseNotes = await MarkdownBuilder.Build(config); - await File.WriteAllTextAsync(path.Combine($"v{config.CurrentVersion}.md").FullPath, releaseNotes); + var releaseNotes = MarkdownBuilder.Build(config).Result; + context.GenerateFile(path.Combine($"v{config.CurrentVersion}.md").FullPath, releaseNotes, true); } catch (Exception e) { - await Console.Error.WriteLineAsync(e.ToString()); + context.Error(e.ToString()); } } } \ No newline at end of file diff --git a/build/BenchmarkDotNet.Build/CommandLineParser.cs b/build/BenchmarkDotNet.Build/CommandLineParser.cs index 95dc065875..5e797e6375 100644 --- a/build/BenchmarkDotNet.Build/CommandLineParser.cs +++ b/build/BenchmarkDotNet.Build/CommandLineParser.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; +using System.Runtime.InteropServices; +using BenchmarkDotNet.Build.Options; using Cake.Frosting; namespace BenchmarkDotNet.Build; @@ -10,6 +12,9 @@ public class CommandLineParser { private const string ScriptName = "build.cmd"; + private static readonly string CallScriptName = + (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) ? ScriptName : "./" + ScriptName; + public static readonly CommandLineParser Instance = new(); public string[]? Parse(string[]? args) @@ -53,63 +58,32 @@ public class CommandLineParser { var arg = argsToProcess.Dequeue(); - var matched = false; - foreach (var option in options) - { - if (Is(arg, option.ShortName, option.FullName)) - { - matched = true; - cakeArgs.Add(option.CakeOption); - if (option.Arg != "") - { - if (!argsToProcess.Any()) - { - PrintError(option.FullName + " is not specified"); - return null; - } - - cakeArgs.Add(argsToProcess.Dequeue()); - } - } - } - if (arg.StartsWith("/p:")) { - matched = true; cakeArgs.Add("--msbuild"); cakeArgs.Add(arg[3..]); + continue; } - if (!matched) + if (arg.StartsWith('-')) { - PrintError("Unknown option: " + arg); - return null; + cakeArgs.Add(arg); + if (argsToProcess.Any() && !argsToProcess.Peek().StartsWith('-')) + cakeArgs.Add(argsToProcess.Dequeue()); + continue; } + + PrintError("Unknown option: " + arg); + return null; } return cakeArgs.ToArray(); } - private record Option(string ShortName, string FullName, string Arg, string Description, string CakeOption); - - private readonly Option[] options = + private readonly IOption[] baseOptions = { - new("-v", - "--verbosity", - "", - "Specifies the amount of information to be displayed\n(Quiet, Minimal, Normal, Verbose, Diagnostic)", - "--verbosity"), - new("-e", - "--exclusive", - "", - "Executes the target task without any dependencies", - "--exclusive"), - new("-h", - "--help", - "", - "Prints help information for the target task", - "") + KnownOptions.Verbosity, KnownOptions.Exclusive, KnownOptions.Help }; private void PrintHelp() @@ -127,7 +101,7 @@ private void PrintHelp() WriteHeader("Usage:"); WritePrefix(); - Write(ScriptName + " "); + Write(CallScriptName + " "); WriteTask(" "); WriteOption("[OPTIONS]"); WriteLine(); @@ -137,12 +111,12 @@ private void PrintHelp() WriteHeader("Examples:"); WritePrefix(); - Write(ScriptName + " "); + Write(CallScriptName + " "); WriteTask("restore"); WriteLine(); WritePrefix(); - Write(ScriptName + " "); + Write(CallScriptName + " "); WriteTask("build "); WriteOption("/p:"); WriteArg("Configuration"); @@ -151,7 +125,7 @@ private void PrintHelp() WriteLine(); WritePrefix(); - Write(ScriptName + " "); + Write(CallScriptName + " "); WriteTask("pack "); WriteOption("/p:"); WriteArg("VersionPrefix"); @@ -164,27 +138,29 @@ private void PrintHelp() WriteLine(); WritePrefix(); - Write(ScriptName + " "); + Write(CallScriptName + " "); WriteTask("unittests "); WriteOption("--exclusive --verbosity "); WriteArg("Diagnostic"); WriteLine(); WritePrefix(); - Write(ScriptName + " "); + Write(CallScriptName + " "); WriteTask("docs-update "); - WriteOption("/p:"); - WriteArg("Depth"); - WriteOption("="); + WriteOption("--depth "); WriteArg("3"); WriteLine(); + WritePrefix(); + Write(CallScriptName + " "); + WriteTask("docs-build "); + WriteOption("--preview "); WriteLine(); - PrintCommonOptions(); - WriteLine(); + PrintOptions(baseOptions); + WriteHeader("Tasks:"); var taskWidth = GetTaskNames().Max(name => name.Length) + 3; foreach (var (taskName, taskDescription) in GetTasks()) @@ -207,29 +183,47 @@ private void PrintHelp() } } - private void PrintCommonOptions() + private void PrintOptions(IOption[] options) { + const string valuePlaceholder = ""; + WriteLine("Options:", ConsoleColor.DarkCyan); - var shortNameWidth = options.Max(it => it.ShortName.Length); - var targetWidth = options.Max(it => it.FullName.Length + it.Arg.Length); + int GetWidth(IOption option) + { + int width = option.CommandLineName.Length; + foreach (var alias in option.Aliases) + width += 1 + alias.Length; + if (option is StringOption) + width += 1 + valuePlaceholder.Length; + return width; + } - foreach (var (shortName, fullName, arg, description, _) in options) + const int descriptionGap = 3; + var maxWidth = options.Max(GetWidth) + descriptionGap; + + foreach (var option in options) { + var allNames = option.Aliases.Append(option.CommandLineName).OrderBy(name => name.Length); + var joinName = string.Join(',', allNames); + WritePrefix(); - WriteOption(shortName.PadRight(shortNameWidth)); - WriteOption(shortName != "" ? "," : " "); - WriteOption(fullName); - Write(" "); - WriteArg(arg); - Write(new string(' ', targetWidth - fullName.Length - arg.Length + 3)); - var descriptionLines = description.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); + WriteOption(joinName); + if (option is StringOption) + { + Write(" "); + WriteArg(valuePlaceholder); + } + + Write(new string(' ', + maxWidth - joinName.Length - (option is StringOption ? valuePlaceholder.Length + 1 : 0))); + var descriptionLines = option.Description.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); Write(descriptionLines.FirstOrDefault() ?? ""); for (int i = 1; i < descriptionLines.Length; i++) { WriteLine(); WritePrefix(); - Write(new string(' ', shortNameWidth + 2 + targetWidth + 3)); + Write(new string(' ', maxWidth)); Write(descriptionLines[i]); } @@ -240,10 +234,12 @@ private void PrintCommonOptions() WriteOption("/p:"); WriteArg(""); WriteOption("="); - WriteArg(""); - Write(new string(' ', targetWidth + shortNameWidth - 11)); + WriteArg(valuePlaceholder); + Write(new string(' ', maxWidth - "/p:=".Length - valuePlaceholder.Length)); Write("Passes custom properties to MSBuild"); WriteLine(); + + WriteLine(); } private void PrintTaskHelp(string taskName) @@ -267,18 +263,19 @@ private void PrintTaskHelp(string taskName) WriteLine(taskDescription); } - foreach (var line in helpInfo.Description) - { - WritePrefix(); - WriteLine(line); - } + if (string.IsNullOrWhiteSpace(helpInfo.Description)) + foreach (var line in helpInfo.Description.Split('\n', StringSplitOptions.RemoveEmptyEntries)) + { + WritePrefix(); + WriteLine(line.Trim()); + } WriteLine(); WriteHeader("Usage:"); WritePrefix(); - Write(ScriptName + " "); + Write(CallScriptName + " "); WriteTask(taskName + " "); WriteOption("[OPTIONS]"); WriteLine(); @@ -309,7 +306,19 @@ private void PrintTaskHelp(string taskName) WriteLine(); - PrintCommonOptions(); + PrintOptions(helpInfo.Options.Concat(baseOptions).ToArray()); + + if (helpInfo.EnvironmentVariables.Any()) + { + WriteHeader("Environment variables:"); + foreach (var variable in helpInfo.EnvironmentVariables) + { + WritePrefix(); + WriteOption(variable); + } + + WriteLine(); + } } private static HashSet GetTaskNames() diff --git a/build/BenchmarkDotNet.Build/HelpInfo.cs b/build/BenchmarkDotNet.Build/HelpInfo.cs index 8f93af63f9..868299677b 100644 --- a/build/BenchmarkDotNet.Build/HelpInfo.cs +++ b/build/BenchmarkDotNet.Build/HelpInfo.cs @@ -1,8 +1,11 @@ using System; +using BenchmarkDotNet.Build.Options; namespace BenchmarkDotNet.Build; public class HelpInfo { - public string[] Description { get; init; } = Array.Empty(); + public string Description { get; init; } = ""; + public IOption[] Options { get; init; } = Array.Empty(); + public string[] EnvironmentVariables { get; init; } = Array.Empty(); } \ No newline at end of file diff --git a/build/BenchmarkDotNet.Build/Options/BoolOption.cs b/build/BenchmarkDotNet.Build/Options/BoolOption.cs new file mode 100644 index 0000000000..5a437d8095 --- /dev/null +++ b/build/BenchmarkDotNet.Build/Options/BoolOption.cs @@ -0,0 +1,20 @@ +using System; + +namespace BenchmarkDotNet.Build.Options; + +public class BoolOption : Option +{ + public BoolOption(string commandLineName) : base(commandLineName) + { + } + + public override bool Resolve(BuildContext context) + { + if (!HasArgument(context)) + return false; + var value = GetArgument(context); + if (value == null) + return true; + return !value.Equals(false.ToString(), StringComparison.OrdinalIgnoreCase); + } +} \ No newline at end of file diff --git a/build/BenchmarkDotNet.Build/Options/IOption.cs b/build/BenchmarkDotNet.Build/Options/IOption.cs new file mode 100644 index 0000000000..0a2046816e --- /dev/null +++ b/build/BenchmarkDotNet.Build/Options/IOption.cs @@ -0,0 +1,8 @@ +namespace BenchmarkDotNet.Build.Options; + +public interface IOption +{ + string CommandLineName { get; } + string Description { get; } + string[] Aliases { get; } +} \ No newline at end of file diff --git a/build/BenchmarkDotNet.Build/Options/KnownOptions.cs b/build/BenchmarkDotNet.Build/Options/KnownOptions.cs new file mode 100644 index 0000000000..19467c09c3 --- /dev/null +++ b/build/BenchmarkDotNet.Build/Options/KnownOptions.cs @@ -0,0 +1,37 @@ +namespace BenchmarkDotNet.Build.Options; + +public static class KnownOptions +{ + public static readonly StringOption Verbosity = new("--verbosity" + ) + { + Description = "Specifies the amount of information to be displayed\n" + + "(Quiet, Minimal, Normal, Verbose, Diagnostic)", + Aliases = new[] { "-v" } + }; + + public static readonly BoolOption Exclusive = new("--exclusive") + { + Description = "Executes the target task without any dependencies", + Aliases = new[] { "-e" } + }; + + public static readonly BoolOption DocsPreview = new("--preview") + { + Description = "When specified, documentation changelog includes the upcoming version", + Aliases = new[] { "-p" } + }; + + public static readonly StringOption DocsDepth = new("--depth") + { + Description = "The number of last stable versions that requires changelog regenerations\n" + + "Use 'all' for all values. The default is zero.", + Aliases = new[] { "-d" } + }; + + public static readonly BoolOption Help = new("--help") + { + Description = "Prints help information", + Aliases = new[] { "-h" } + }; +} \ No newline at end of file diff --git a/build/BenchmarkDotNet.Build/Options/Option.cs b/build/BenchmarkDotNet.Build/Options/Option.cs new file mode 100644 index 0000000000..4840af7ad2 --- /dev/null +++ b/build/BenchmarkDotNet.Build/Options/Option.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Cake.Common; +using Cake.Core; + +namespace BenchmarkDotNet.Build.Options; + +public abstract class Option : IOption +{ + public string CommandLineName { get; } + public string Description { get; init; } = ""; + public string[] Aliases { get; init; } = Array.Empty(); + + private IEnumerable AllNames + { + get + { + yield return CommandLineName; + foreach (var alias in Aliases) + yield return alias; + } + } + + private IEnumerable AllStrippedNames => AllNames.Select(name => name.TrimStart('-')); + + protected Option(string commandLineName) + { + CommandLineName = commandLineName; + } + + public abstract T Resolve(BuildContext context); + + protected bool HasArgument(BuildContext context) => AllStrippedNames.Any(context.HasArgument); + + protected string? GetArgument(BuildContext context) => AllStrippedNames + .Where(context.HasArgument) + .Select(name => context.Arguments.GetArgument(name)) + .FirstOrDefault(); +} \ No newline at end of file diff --git a/build/BenchmarkDotNet.Build/Options/StringOption.cs b/build/BenchmarkDotNet.Build/Options/StringOption.cs new file mode 100644 index 0000000000..66a3bc375b --- /dev/null +++ b/build/BenchmarkDotNet.Build/Options/StringOption.cs @@ -0,0 +1,19 @@ +namespace BenchmarkDotNet.Build.Options; + +public class StringOption : Option +{ + public StringOption(string commandLineName) : base(commandLineName) + { + } + + + public override string Resolve(BuildContext context) + { + if (!HasArgument(context)) + return ""; + var value = GetArgument(context); + if (value == null || string.IsNullOrWhiteSpace(value)) + return ""; + return value.Trim(); + } +} \ No newline at end of file diff --git a/build/BenchmarkDotNet.Build/Program.cs b/build/BenchmarkDotNet.Build/Program.cs index 42cc824d1a..2717e9b20a 100644 --- a/build/BenchmarkDotNet.Build/Program.cs +++ b/build/BenchmarkDotNet.Build/Program.cs @@ -1,4 +1,5 @@ using BenchmarkDotNet.Build.Meta; +using BenchmarkDotNet.Build.Options; using Cake.Common; using Cake.Frosting; @@ -92,19 +93,25 @@ public HelpInfo GetHelp() { return new HelpInfo { - Description = new[] - { - $"Requires environment variable '{GitHubCredentials.TokenVariableName}'" - } + Options = new IOption[] { KnownOptions.DocsPreview, KnownOptions.DocsDepth }, + EnvironmentVariables = new[] { GitHubCredentials.TokenVariableName } }; } } [TaskName("DocsPrepare")] [TaskDescription("Prepare auxiliary documentation files")] -public class DocsPrepareTask : FrostingTask +public class DocsPrepareTask : FrostingTask, IHelpProvider { public override void Run(BuildContext context) => context.DocumentationRunner.Prepare(); + + public HelpInfo GetHelp() + { + return new HelpInfo + { + Options = new IOption[] { KnownOptions.DocsPreview } + }; + } } // In order to work around xref issues in DocFx, BenchmarkDotNet and BenchmarkDotNet.Annotations must be build @@ -114,9 +121,14 @@ public class DocsPrepareTask : FrostingTask [TaskName("DocsBuild")] [TaskDescription("Build final documentation")] [IsDependentOn(typeof(DocsPrepareTask))] -public class DocsBuildTask : FrostingTask +public class DocsBuildTask : FrostingTask, IHelpProvider { public override void Run(BuildContext context) => context.DocumentationRunner.Build(); + + public HelpInfo GetHelp() => new() + { + Options = new IOption[] { KnownOptions.DocsPreview } + }; } [TaskName("Release")] diff --git a/build/BenchmarkDotNet.Build/Runners/DocumentationRunner.cs b/build/BenchmarkDotNet.Build/Runners/DocumentationRunner.cs index a7cf31b1bd..7b59d223fc 100644 --- a/build/BenchmarkDotNet.Build/Runners/DocumentationRunner.cs +++ b/build/BenchmarkDotNet.Build/Runners/DocumentationRunner.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using BenchmarkDotNet.Build.Meta; +using BenchmarkDotNet.Build.Options; using Cake.Common.Diagnostics; using Cake.Common.IO; using Cake.Core.IO; @@ -14,6 +15,8 @@ namespace BenchmarkDotNet.Build.Runners; public class DocumentationRunner { private readonly BuildContext context; + private readonly bool preview; + private readonly string depth; public DirectoryPath ChangelogDirectory { get; } public DirectoryPath ChangelogSrcDirectory { get; } @@ -32,6 +35,8 @@ public class DocumentationRunner public DocumentationRunner(BuildContext context) { this.context = context; + preview = KnownOptions.DocsPreview.Resolve(context); + depth = KnownOptions.DocsDepth.Resolve(context); var docsDirectory = context.RootDirectory.Combine("docs"); ChangelogDirectory = docsDirectory.Combine("changelog"); @@ -61,39 +66,43 @@ public void Update() throw new Exception($"Environment variable '{GitHubCredentials.TokenVariableName}' is not specified!"); var history = context.VersionHistory; - var depth = context.Depth; var stableVersionCount = history.StableVersions.Length; - if (depth == 0) + if (depth.Equals("all", StringComparison.OrdinalIgnoreCase)) { DocfxChangelogDownload( history.StableVersions.First(), history.FirstCommit); - for (int i = 1; i < stableVersionCount; i++) + for (var i = 1; i < stableVersionCount; i++) DocfxChangelogDownload( history.StableVersions[i], history.StableVersions[i - 1]); } - else if (depth > 0) + else if (depth != "") { - for (int i = Math.Max(stableVersionCount - depth, 1); i < stableVersionCount; i++) + if (!int.TryParse(depth, CultureInfo.InvariantCulture, out var depthValue)) + throw new InvalidDataException($"Failed to parse the depth value: '{depth}'"); + + for (var i = Math.Max(stableVersionCount - depthValue, 1); i < stableVersionCount; i++) DocfxChangelogDownload( history.StableVersions[i], history.StableVersions[i - 1]); } - DocfxChangelogDownload( - history.CurrentVersion, - history.StableVersions.Last(), - "HEAD"); + if (preview) + DocfxChangelogDownload( + history.CurrentVersion, + history.StableVersions.Last(), + "HEAD"); } public void Prepare() { foreach (var version in context.VersionHistory.StableVersions) DocfxChangelogGenerate(version); - DocfxChangelogGenerate(context.VersionHistory.CurrentVersion); + if (preview) + DocfxChangelogGenerate(context.VersionHistory.CurrentVersion); GenerateIndexMd(); GenerateChangelogIndex(); @@ -133,9 +142,12 @@ private void GenerateChangelogToc() { var content = new StringBuilder(); - content.AppendLine($"- name: v{context.VersionHistory.CurrentVersion}"); - content.AppendLine($" href: v{context.VersionHistory.CurrentVersion}.md"); - + if (preview) + { + content.AppendLine($"- name: v{context.VersionHistory.CurrentVersion}"); + content.AppendLine($" href: v{context.VersionHistory.CurrentVersion}.md"); + } + foreach (var version in context.VersionHistory.StableVersions.Reverse()) { content.AppendLine($"- name: v{version}"); @@ -157,8 +169,9 @@ private void GenerateChangelogFull() content.AppendLine(""); content.AppendLine("# Full ChangeLog"); content.AppendLine(""); - content.AppendLine( - $"[!include[v{context.VersionHistory.CurrentVersion}](v{context.VersionHistory.CurrentVersion}.md)]"); + if (preview) + content.AppendLine( + $"[!include[v{context.VersionHistory.CurrentVersion}](v{context.VersionHistory.CurrentVersion}.md)]"); foreach (var version in context.VersionHistory.StableVersions.Reverse()) content.AppendLine($"[!include[v{version}](v{version}.md)]"); @@ -174,7 +187,8 @@ private void GenerateChangelogIndex() content.AppendLine(""); content.AppendLine("# ChangeLog"); content.AppendLine(""); - content.AppendLine($"* @changelog.v{context.VersionHistory.CurrentVersion}"); + if (preview) + content.AppendLine($"* @changelog.v{context.VersionHistory.CurrentVersion}"); foreach (var version in context.VersionHistory.StableVersions.Reverse()) content.AppendLine($"* @changelog.v{version}"); content.AppendLine("* @changelog.full"); @@ -238,8 +252,8 @@ private void EnsureChangelogDetailsExist(bool forceClean = false) private void DocfxChangelogDownload(string version, string versionPrevious, string lastCommit = "") { EnsureChangelogDetailsExist(); - context.Information("DocfxChangelogDownload: " + version); - ChangeLogBuilder.Run(changelogDetailsDirectory, version, versionPrevious, lastCommit).Wait(); + context.Information($"Downloading changelog details for v{version}"); + ChangeLogBuilder.Run(context, changelogDetailsDirectory, version, versionPrevious, lastCommit); } private void GenerateRedirects() diff --git a/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.CSharp/.template.config/template.json b/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.CSharp/.template.config/template.json index b4051ccbf4..c0c4e6c182 100644 --- a/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.CSharp/.template.config/template.json +++ b/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.CSharp/.template.config/template.json @@ -144,7 +144,7 @@ "type": "parameter", "datatype": "string", "description": "Version of BenchmarkDotNet that will be referenced.", - "defaultValue": "0.13.7", + "defaultValue": "0.1.1729", "replaces": "$(BenchmarkDotNetVersion)" } }, diff --git a/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.FSharp/.template.config/template.json b/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.FSharp/.template.config/template.json index 20d49ec024..4158c6bc0f 100644 --- a/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.FSharp/.template.config/template.json +++ b/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.FSharp/.template.config/template.json @@ -144,7 +144,7 @@ "type": "parameter", "datatype": "string", "description": "Version of BenchmarkDotNet that will be referenced.", - "defaultValue": "0.13.7", + "defaultValue": "0.1.1729", "replaces": "$(BenchmarkDotNetVersion)" } }, diff --git a/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.VB/.template.config/template.json b/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.VB/.template.config/template.json index 1fe705443d..103d38332b 100644 --- a/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.VB/.template.config/template.json +++ b/templates/templates/BenchmarkDotNet.BenchmarkProjectTemplate.VB/.template.config/template.json @@ -144,7 +144,7 @@ "type": "parameter", "datatype": "string", "description": "Version of BenchmarkDotNet that will be referenced.", - "defaultValue": "0.13.7", + "defaultValue": "0.1.1729", "replaces": "$(BenchmarkDotNetVersion)" } },