Skip to content

Commit 3b361e3

Browse files
Add Release build task
1 parent bf020e9 commit 3b361e3

File tree

9 files changed

+367
-47
lines changed

9 files changed

+367
-47
lines changed

build/BenchmarkDotNet.Build/BuildContext.cs

+20-29
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public class BuildContext : FrostingContext
2626
public DotNetVerbosity BuildVerbosity { get; set; } = DotNetVerbosity.Minimal;
2727
public int Depth { get; set; }
2828
public bool VersionStable { get; }
29+
public string NextVersion { get; }
30+
public bool PushMode { get; }
2931

3032
public DirectoryPath RootDirectory { get; }
3133
public DirectoryPath BuildDirectory { get; }
@@ -34,6 +36,8 @@ public class BuildContext : FrostingContext
3436
public FilePath SolutionFile { get; }
3537
public FilePath TemplatesTestsProjectFile { get; }
3638
public FilePathCollection AllPackableSrcProjects { get; }
39+
public FilePath VersionsFile { get; }
40+
public FilePath CommonPropsFile { get; }
3741

3842
public DotNetMSBuildSettings MsBuildSettingsRestore { get; }
3943
public DotNetMSBuildSettings MsBuildSettingsBuild { get; }
@@ -45,9 +49,11 @@ public class BuildContext : FrostingContext
4549

4650
public VersionHistory VersionHistory { get; }
4751

52+
public GitRunner GitRunner { get; }
4853
public UnitTestRunner UnitTestRunner { get; }
4954
public DocumentationRunner DocumentationRunner { get; }
5055
public BuildRunner BuildRunner { get; }
56+
public ReleaseRunner ReleaseRunner { get; }
5157

5258
public BuildContext(ICakeContext context)
5359
: base(context)
@@ -64,6 +70,9 @@ public BuildContext(ICakeContext context)
6470
AllPackableSrcProjects = new FilePathCollection(context.GetFiles(RootDirectory.FullPath + "/src/**/*.csproj")
6571
.Where(p => !p.FullPath.Contains("Disassembler")));
6672

73+
VersionsFile = BuildDirectory.CombineWithFilePath("versions.txt");
74+
CommonPropsFile = BuildDirectory.CombineWithFilePath("common.props");
75+
6776
MsBuildSettingsRestore = new DotNetMSBuildSettings();
6877
MsBuildSettingsBuild = new DotNetMSBuildSettings();
6978
MsBuildSettingsPack = new DotNetMSBuildSettings();
@@ -78,6 +87,8 @@ public BuildContext(ICakeContext context)
7887

7988
Depth = -1;
8089
VersionStable = false;
90+
NextVersion = "";
91+
PushMode = false;
8192
if (context.Arguments.HasArgument("msbuild"))
8293
{
8394
var msBuildParameters = context.Arguments.GetArguments().First(it => it.Key == "msbuild").Value;
@@ -107,6 +118,12 @@ public BuildContext(ICakeContext context)
107118

108119
if (name.Equals("VersionStable", StringComparison.OrdinalIgnoreCase) && value != "")
109120
VersionStable = true;
121+
122+
if (name.Equals("NextVersion", StringComparison.OrdinalIgnoreCase) && value != "")
123+
NextVersion = value;
124+
125+
if (name.Equals("PushMode", StringComparison.OrdinalIgnoreCase) && value != "")
126+
PushMode = true;
110127
}
111128
}
112129
}
@@ -129,11 +146,13 @@ public BuildContext(ICakeContext context)
129146
nuGetPackageNames.Sort();
130147
NuGetPackageNames = nuGetPackageNames;
131148

132-
VersionHistory = new VersionHistory(this, BuildDirectory.CombineWithFilePath("versions.txt"));
149+
VersionHistory = new VersionHistory(this, VersionsFile);
133150

151+
GitRunner = new GitRunner(this);
134152
UnitTestRunner = new UnitTestRunner(this);
135153
DocumentationRunner = new DocumentationRunner(this);
136154
BuildRunner = new BuildRunner(this);
155+
ReleaseRunner = new ReleaseRunner(this);
137156
}
138157

139158
public void GenerateFile(FilePath filePath, StringBuilder content)
@@ -160,32 +179,4 @@ public void GenerateFile(FilePath filePath, string content)
160179
}
161180
}
162181

163-
public void Clone(DirectoryPath path, string repoUrl, string branchName)
164-
{
165-
this.Information($"[GitClone]");
166-
this.Information($" Repo: {repoUrl}");
167-
this.Information($" Branch: {branchName}");
168-
this.Information($" Path: {path}");
169-
var settings = new GitCloneSettings { Checkout = true, BranchName = branchName };
170-
try
171-
{
172-
this.GitClone(repoUrl, path, settings);
173-
this.Information(" Success");
174-
}
175-
catch (Exception e)
176-
{
177-
this.Error($" Failed to clone via API (Exception: {e.GetType().Name})'");
178-
try
179-
{
180-
var gitArgs = $"clone -b {branchName} {repoUrl} {path}";
181-
this.Information($" Trying to clone manually using 'git {gitArgs}'");
182-
this.StartProcess("git", gitArgs);
183-
this.Information(" Success");
184-
}
185-
catch (Exception e2)
186-
{
187-
throw new Exception($"Failed to clone {repoUrl} to {path} (branch: '{branchName})'", e2);
188-
}
189-
}
190-
}
191182
}

build/BenchmarkDotNet.Build/ChangeLogBuilder.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ private async Task<string> Build()
6060
if (string.IsNullOrEmpty(lastCommit))
6161
lastCommit = $"v{currentVersion}";
6262

63-
var client = new GitHubClient(new ProductHeaderValue(GitHubCredentials.ProductHeader));
64-
var tokenAuth = new Credentials(GitHubCredentials.Token);
65-
client.Credentials = tokenAuth;
63+
var client = GitHubCredentials.CreateClient();
6664

6765
if (currentVersion == "_")
6866
{

build/BenchmarkDotNet.Build/Meta/GitHubCredentials.cs

+9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using Octokit;
23

34
namespace BenchmarkDotNet.Build.Meta;
45

@@ -8,4 +9,12 @@ public static class GitHubCredentials
89

910
public const string ProductHeader = "BenchmarkDotNet";
1011
public static string? Token => Environment.GetEnvironmentVariable(TokenVariableName);
12+
13+
public static GitHubClient CreateClient()
14+
{
15+
var client = new GitHubClient(new ProductHeaderValue(ProductHeader));
16+
var tokenAuth = new Credentials(Token);
17+
client.Credentials = tokenAuth;
18+
return client;
19+
}
1120
}

build/BenchmarkDotNet.Build/Meta/Repo.cs

+3
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@ public static class Repo
66
public const string Name = "BenchmarkDotNet";
77
public const string HttpsUrlBase = $"https://github.com/{Owner}/{Name}";
88
public const string HttpsGitUrl = $"{HttpsUrlBase}.git";
9+
910
public const string ChangelogDetailsBranch = "docs-changelog-details";
11+
public const string DocsStableBranch = "docs-stable";
12+
public const string MasterBranch = "master";
1013
}

build/BenchmarkDotNet.Build/Program.cs

+11
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,17 @@ public class DocsBuildTask : FrostingTask<BuildContext>
119119
public override void Run(BuildContext context) => context.DocumentationRunner.Build();
120120
}
121121

122+
[TaskName("Release")]
123+
[TaskDescription("Release new version")]
124+
[IsDependentOn(typeof(BuildTask))]
125+
[IsDependentOn(typeof(PackTask))]
126+
[IsDependentOn(typeof(DocsUpdateTask))]
127+
[IsDependentOn(typeof(DocsBuildTask))]
128+
public class ReleaseTask : FrostingTask<BuildContext>
129+
{
130+
public override void Run(BuildContext context) => context.ReleaseRunner.Run();
131+
}
132+
122133
[TaskName("FastTests")]
123134
[TaskDescription("OBSOLETE: use 'UnitTests'")]
124135
[IsDependentOn(typeof(UnitTestsTask))]

build/BenchmarkDotNet.Build/Runners/BuildRunner.cs

+13
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Cake.Common.Tools.DotNet.Pack;
77
using Cake.Common.Tools.DotNet.Restore;
88
using Cake.Core;
9+
using Cake.Core.IO;
910

1011
namespace BenchmarkDotNet.Build.Runners;
1112

@@ -40,6 +41,18 @@ public void Build()
4041
});
4142
}
4243

44+
public void BuildProjectSilent(FilePath projectFile)
45+
{
46+
context.DotNetBuild(projectFile.FullPath, new DotNetBuildSettings
47+
{
48+
NoRestore = false,
49+
DiagnosticOutput = false,
50+
MSBuildSettings = context.MsBuildSettingsBuild,
51+
Configuration = context.BuildConfiguration,
52+
Verbosity = DotNetVerbosity.Quiet
53+
});
54+
}
55+
4356
public void Pack()
4457
{
4558
context.CleanDirectory(context.ArtifactsDirectory);

build/BenchmarkDotNet.Build/Runners/DocumentationRunner.cs

+22-15
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public class DocumentationRunner
1515
{
1616
private readonly BuildContext context;
1717

18-
private readonly DirectoryPath changelogDirectory;
19-
private readonly DirectoryPath changelogSrcDirectory;
18+
public DirectoryPath ChangelogDirectory { get; }
19+
public DirectoryPath ChangelogSrcDirectory { get; }
2020
private readonly DirectoryPath changelogDetailsDirectory;
2121
private readonly DirectoryPath docsGeneratedDirectory;
2222

@@ -34,19 +34,19 @@ public DocumentationRunner(BuildContext context)
3434
this.context = context;
3535

3636
var docsDirectory = context.RootDirectory.Combine("docs");
37-
changelogDirectory = docsDirectory.Combine("changelog");
38-
changelogSrcDirectory = docsDirectory.Combine("_changelog");
39-
changelogDetailsDirectory = changelogSrcDirectory.Combine("details");
37+
ChangelogDirectory = docsDirectory.Combine("changelog");
38+
ChangelogSrcDirectory = docsDirectory.Combine("_changelog");
39+
changelogDetailsDirectory = ChangelogSrcDirectory.Combine("details");
4040
docsGeneratedDirectory = docsDirectory.Combine("_site");
4141

4242
redirectFile = docsDirectory.Combine("_redirects").CombineWithFilePath("_redirects");
4343
docfxJsonFile = docsDirectory.CombineWithFilePath("docfx.json");
4444
readmeFile = context.RootDirectory.CombineWithFilePath("README.md");
4545
rootIndexFile = docsDirectory.CombineWithFilePath("index.md");
46-
changelogIndexFile = changelogDirectory.CombineWithFilePath("index.md");
47-
changelogFullFile = changelogDirectory.CombineWithFilePath("full.md");
48-
changelogTocFile = changelogDirectory.CombineWithFilePath("toc.yml");
49-
lastFooterFile = changelogSrcDirectory.Combine("footer")
46+
changelogIndexFile = ChangelogDirectory.CombineWithFilePath("index.md");
47+
changelogFullFile = ChangelogDirectory.CombineWithFilePath("full.md");
48+
changelogTocFile = ChangelogDirectory.CombineWithFilePath("toc.yml");
49+
lastFooterFile = ChangelogSrcDirectory.Combine("footer")
5050
.CombineWithFilePath("v" + context.VersionHistory.CurrentVersion + ".md");
5151
}
5252

@@ -132,6 +132,10 @@ private void GenerateIndexMd()
132132
private void GenerateChangelogToc()
133133
{
134134
var content = new StringBuilder();
135+
136+
content.AppendLine($"- name: {context.VersionHistory.CurrentVersion}");
137+
content.AppendLine($" href: {context.VersionHistory.CurrentVersion}.md");
138+
135139
foreach (var version in context.VersionHistory.StableVersions.Reverse())
136140
{
137141
content.AppendLine($"- name: {version}");
@@ -153,6 +157,8 @@ private void GenerateChangelogFull()
153157
content.AppendLine("");
154158
content.AppendLine("# Full ChangeLog");
155159
content.AppendLine("");
160+
content.AppendLine(
161+
$"[!include[{context.VersionHistory.CurrentVersion}]({context.VersionHistory.CurrentVersion}.md)]");
156162
foreach (var version in context.VersionHistory.StableVersions.Reverse())
157163
content.AppendLine($"[!include[{version}]({version}.md)]");
158164

@@ -168,6 +174,7 @@ private void GenerateChangelogIndex()
168174
content.AppendLine("");
169175
content.AppendLine("# ChangeLog");
170176
content.AppendLine("");
177+
content.AppendLine($"* @changelog.{context.VersionHistory.CurrentVersion}");
171178
foreach (var version in context.VersionHistory.StableVersions.Reverse())
172179
content.AppendLine($"* @changelog.{version}");
173180
content.AppendLine("* @changelog.full");
@@ -178,10 +185,10 @@ private void GenerateChangelogIndex()
178185
private void DocfxChangelogGenerate(string version)
179186
{
180187
EnsureChangelogDetailsExist();
181-
var header = changelogSrcDirectory.Combine("header").CombineWithFilePath(version + ".md");
182-
var footer = changelogSrcDirectory.Combine("footer").CombineWithFilePath(version + ".md");
183-
var details = changelogSrcDirectory.Combine("details").CombineWithFilePath(version + ".md");
184-
var release = changelogDirectory.CombineWithFilePath(version + ".md");
188+
var header = ChangelogSrcDirectory.Combine("header").CombineWithFilePath(version + ".md");
189+
var footer = ChangelogSrcDirectory.Combine("footer").CombineWithFilePath(version + ".md");
190+
var details = ChangelogSrcDirectory.Combine("details").CombineWithFilePath(version + ".md");
191+
var release = ChangelogDirectory.CombineWithFilePath(version + ".md");
185192

186193
var content = new StringBuilder();
187194
content.AppendLine("---");
@@ -224,7 +231,7 @@ private void EnsureChangelogDetailsExist(bool forceClean = false)
224231
new DeleteDirectorySettings { Force = true, Recursive = true });
225232

226233
if (!context.DirectoryExists(changelogDetailsDirectory))
227-
context.Clone(changelogDetailsDirectory, Repo.HttpsGitUrl, Repo.ChangelogDetailsBranch);
234+
context.GitRunner.Clone(changelogDetailsDirectory, Repo.HttpsGitUrl, Repo.ChangelogDetailsBranch);
228235
}
229236

230237
private void DocfxChangelogDownload(string version, string versionPrevious, string lastCommit = "")
@@ -273,7 +280,7 @@ private void UpdateLastFooter()
273280
var version = context.VersionHistory.CurrentVersion;
274281
var previousVersion = context.VersionHistory.StableVersions.Last();
275282
var date = context.VersionStable
276-
? DateTime.Now.ToString("MMMM dd, yyyy", CultureInfo.InvariantCulture)
283+
? DateTime.Now.ToString("MMMM dd, yyyy", CultureInfo.InvariantCulture)
277284
: "TBA";
278285

279286
var content = new StringBuilder();

0 commit comments

Comments
 (0)