Skip to content

Commit 40a8cfd

Browse files
authored
Update release workflow for analyzers. (#2882)
1 parent 8291376 commit 40a8cfd

File tree

5 files changed

+99
-0
lines changed

5 files changed

+99
-0
lines changed

.github/workflows/release.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,27 @@ jobs:
112112
- name: Publish to NuGet
113113
run: dotnet nuget push ./artifacts/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
114114

115+
# --- Analyzer Rules ---
116+
117+
- name: Move analyzer rules
118+
run: ./build.cmd move-analyzer-rules --version v${{ steps.version.outputs.VERSION }}
119+
120+
- name: Commit analyzer rules changes
121+
uses: EndBug/add-and-commit@v9
122+
with:
123+
message: "Update released analyzer rules"
124+
author_name: GitHub Actions
125+
author_email: [email protected]
126+
committer_name: GitHub Actions
127+
committer_email: [email protected]
128+
129+
- name: Push git changes
130+
uses: ad-m/github-push-action@v1
131+
with:
132+
github_token: ${{ secrets.GITHUB_TOKEN }}
133+
branch: master
134+
tags: false
135+
115136
# --- Documentation ---
116137

117138
- name: Fetch changelog

build/BenchmarkDotNet.Build/Options/KnownOptions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ public static class KnownOptions
4747
Aliases = new[] { "-s" }
4848
};
4949

50+
public static readonly StringOption CurrentVersion = new("--current-version")
51+
{
52+
Description = "Specifies current version number"
53+
};
54+
5055
public static readonly StringOption NextVersion = new("--next-version")
5156
{
5257
Description = "Specifies next version number",

build/BenchmarkDotNet.Build/Program.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,27 @@ public HelpInfo GetHelp()
175175
}
176176
}
177177

178+
[TaskName(Name)]
179+
[TaskDescription("Move updated analyzer rules from unshipped to shipped file")]
180+
public class MoveAnalyzerRulesTask : FrostingTask<BuildContext>, IHelpProvider
181+
{
182+
private const string Name = "move-analyzer-rules";
183+
public override void Run(BuildContext context) => context.DocumentationRunner.MoveAnalyzerRules();
184+
185+
public HelpInfo GetHelp()
186+
{
187+
return new HelpInfo
188+
{
189+
Options = [KnownOptions.CurrentVersion],
190+
Examples =
191+
[
192+
new Example(Name)
193+
.WithArgument(KnownOptions.CurrentVersion, "v0.15.8")
194+
]
195+
};
196+
}
197+
}
198+
178199
[TaskName(Name)]
179200
[TaskDescription("Pack Nupkg packages")]
180201
[IsDependentOn(typeof(BuildTask))]

build/BenchmarkDotNet.Build/Runners/DocumentationRunner.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Text;
44
using BenchmarkDotNet.Build.Helpers;
55
using BenchmarkDotNet.Build.Meta;
6+
using BenchmarkDotNet.Build.Options;
67
using BenchmarkDotNet.Build.Runners.Changelog;
78
using Cake.Common.Diagnostics;
89
using Cake.Common.IO;
@@ -21,6 +22,9 @@ public class DocumentationRunner
2122
private readonly FilePath redirectFile;
2223
private readonly FilePath readmeFile;
2324
private readonly FilePath rootIndexFile;
25+
private readonly FilePath analyzersShippedFile;
26+
private readonly FilePath analyzersUnshippedFile;
27+
private readonly FilePath analyzersPageFile;
2428

2529
public DirectoryPath ChangelogSrcDirectory => changelogBuilder.SrcDirectory;
2630

@@ -35,6 +39,33 @@ public DocumentationRunner(BuildContext context)
3539
docfxJsonFile = docsDirectory.CombineWithFilePath("docfx.json");
3640
readmeFile = context.RootDirectory.CombineWithFilePath("README.md");
3741
rootIndexFile = docsDirectory.CombineWithFilePath("index.md");
42+
43+
var analyzersDirectory = context.RootDirectory.Combine("src").Combine("BenchmarkDotNet.Analyzers");
44+
analyzersShippedFile = analyzersDirectory.CombineWithFilePath("AnalyzerReleases.Shipped.md");
45+
analyzersUnshippedFile = analyzersDirectory.CombineWithFilePath("AnalyzerReleases.Unshipped.md");
46+
analyzersPageFile = docsGeneratedDirectory.Combine("articles").CombineWithFilePath("analyzers.md");
47+
}
48+
49+
public void MoveAnalyzerRules()
50+
{
51+
if (new FileInfo(analyzersUnshippedFile.FullPath).Length == 0)
52+
{
53+
return;
54+
}
55+
56+
string tempFile = System.IO.Path.GetTempFileName();
57+
using (var writer = new StreamWriter(tempFile))
58+
{
59+
writer.WriteLine($"## {KnownOptions.CurrentVersion.Resolve(context)}");
60+
CopyLines(writer, analyzersUnshippedFile);
61+
writer.WriteLine();
62+
writer.WriteLine();
63+
CopyLines(writer, analyzersShippedFile);
64+
}
65+
66+
File.Delete(analyzersShippedFile.FullPath);
67+
File.Move(tempFile, analyzersShippedFile.FullPath);
68+
File.WriteAllText(analyzersUnshippedFile.FullPath, string.Empty);
3869
}
3970

4071
public void Fetch()
@@ -49,6 +80,7 @@ public void Generate()
4980

5081
UpdateReadme();
5182
GenerateIndexMd();
83+
GenerateAnalyzersPage();
5284
}
5385

5486
public void Build()
@@ -91,6 +123,24 @@ private void GenerateIndexMd()
91123
context.GenerateFile(rootIndexFile, content);
92124
}
93125

126+
private void GenerateAnalyzersPage()
127+
{
128+
using var writer = new StreamWriter(analyzersPageFile.FullPath);
129+
writer.WriteLine($"# Roslyn Analyzers for C#");
130+
writer.WriteLine();
131+
CopyLines(writer, analyzersShippedFile);
132+
}
133+
134+
private static void CopyLines(StreamWriter writer, FilePath filePath)
135+
{
136+
using var reader = new StreamReader(filePath.FullPath);
137+
while (reader.ReadLine() is { } line)
138+
{
139+
writer.WriteLine();
140+
writer.Write(line);
141+
}
142+
}
143+
94144
private void GenerateRedirects()
95145
{
96146
if (!context.FileExists(redirectFile))

docs/articles/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@
1616
href: team.md
1717
- name: License
1818
href: license.md
19+
- name: Analyzers
20+
href: analyzers.md

0 commit comments

Comments
 (0)