-
Notifications
You must be signed in to change notification settings - Fork 576
[devops] Vendor Maestro changelog tool #26461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
80539f9
Vendor Maestro changelog tool
rolfbjarne c7fdf54
Use bundled framework for changelog tool
rolfbjarne ae2a79a
Auto-format source code
17f2b13
Address changelog review comments
rolfbjarne 80c6b5c
Fix dependency diff parsing and vendored tool references
rolfbjarne 234aebf
Use global.json for dotnet SDK selection in changelog workflow
rolfbjarne c06b5d2
Address suppressed changelog review comments
rolfbjarne ab7e6a6
Address remaining changelog review suggestions
rolfbjarne 631aea4
Fix changelog compare diff URL
rolfbjarne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.IO; | ||
| using System.Net.Http; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace changelog { | ||
|
|
||
| class Program { | ||
| static readonly List<string> list = new (); | ||
| static readonly List<string> filters = new (); | ||
|
|
||
| // current repo (1) points to dotnet/installer (2) | ||
| // getting into other repos (pointed by dotnet/installer) can show different results | ||
| static int level = 2; | ||
|
|
||
| static async Task Main (string [] args) | ||
| { | ||
| if (args.Length < 2) { | ||
| Console.Error.WriteLine ("Usage: changelog <pull-request-url-or-diff-file> <output-file> [repo-filter ...]"); | ||
| Environment.ExitCode = 1; | ||
| return; | ||
| } | ||
|
|
||
| var pr = args [0]; | ||
| var outputFile = args [1]; | ||
| for (int i = 2; i < args.Length; i++) | ||
| filters.Add (args [i]); | ||
|
|
||
| using (var writer = new StreamWriter (outputFile)) { | ||
| writer.WriteLine ($"# .NET Changelog for {pr}"); | ||
| if (TryGetGitHubPullRequestDiffUrl (pr, out var diffUrl)) | ||
| pr = diffUrl; | ||
| list.Add (pr); | ||
| await Process (writer); | ||
| writer.WriteLine ("Generated using scripts/changelog"); | ||
| } | ||
| } | ||
|
|
||
| static bool TryGetGitHubPullRequestDiffUrl (string url, out string diffUrl) | ||
| { | ||
| diffUrl = url; | ||
| if (!Uri.TryCreate (url, UriKind.Absolute, out var uri)) | ||
| return false; | ||
| if (uri.Host != "github.com") | ||
| return false; | ||
| if (url.EndsWith (".diff", StringComparison.Ordinal)) | ||
| return false; | ||
|
|
||
| var parts = uri.AbsolutePath.Split ('/', StringSplitOptions.RemoveEmptyEntries); | ||
| if (parts.Length != 4 || parts [2] != "pull") | ||
| return false; | ||
|
|
||
| diffUrl = $"https://patch-diff.githubusercontent.com/raw/{string.Join ('/', parts)}.diff"; | ||
| return true; | ||
| } | ||
|
|
||
| static async Task Process (TextWriter writer) | ||
| { | ||
| using var client = new HttpClient (); | ||
| for (int i = 0; i < Math.Min (list.Count, level); i++) { | ||
| writer.WriteLine ($"## Level {i + 1}"); | ||
| var url = list [i]; | ||
| if (url.StartsWith ("https://", StringComparison.Ordinal)) { | ||
| using var result = await client.GetAsync (list [i]); | ||
| result.EnsureSuccessStatusCode (); | ||
| using var stream = await result.Content.ReadAsStreamAsync (); | ||
| ProcessDiff (stream, writer); | ||
| } else { | ||
| using var stream = new FileStream (url, FileMode.Open, FileAccess.Read); | ||
| ProcessDiff (stream, writer); | ||
| } | ||
| writer.WriteLine (); | ||
| } | ||
| } | ||
|
|
||
| static bool Include (string uri) | ||
| { | ||
| if (filters.Count == 0) | ||
| return true; | ||
|
|
||
| foreach (var filter in filters) { | ||
| if (uri.EndsWith (filter, StringComparison.Ordinal)) | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| static void ProcessDiff (Stream s, TextWriter writer) | ||
| { | ||
| bool processing = false; | ||
| var uri = ""; | ||
| var old_sha = ""; | ||
| var new_sha = ""; | ||
| using (var sr = new StreamReader (s)) { | ||
| while (!sr.EndOfStream) { | ||
| var line = sr.ReadLine (); | ||
| if (line is null) | ||
| break; | ||
| if (line == "diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml") { | ||
| processing = true; | ||
| continue; | ||
| } | ||
| if (processing) { | ||
| if (line.StartsWith ("diff --git ", StringComparison.Ordinal)) | ||
| return; | ||
| if (line.Length < 1) | ||
| continue; | ||
| bool removal = (line [0] == '-'); | ||
| bool addition = (line [0] == '+'); | ||
| var tl = (removal || addition) ? line [1..] : line; | ||
| tl = tl.Trim (); | ||
| if (tl.StartsWith ("<Uri>", StringComparison.Ordinal)) { | ||
| uri = tl [5..^6]; | ||
| old_sha = ""; | ||
| new_sha = ""; | ||
| } else if (removal && tl.StartsWith ("<Sha>", StringComparison.Ordinal)) { | ||
| old_sha = tl [5..^6]; | ||
| } else if (addition && tl.StartsWith ("<Sha>", StringComparison.Ordinal)) { | ||
| new_sha = tl [5..^6]; | ||
| if (!Include (uri)) | ||
| continue; | ||
| if (string.IsNullOrEmpty (old_sha)) { | ||
| writer.WriteLine ($"* {uri} [{new_sha [0..7]}]({uri}/commits/{new_sha}) (new dependency)"); | ||
| } else { | ||
| var diff_url = $"{uri}/compare/{old_sha}...{new_sha}.diff"; | ||
| writer.WriteLine ($"* {uri} [{old_sha [0..7]}...{new_sha [0..7]}]({uri}/compare/{old_sha}...{new_sha})"); | ||
| // skip duplicates (if same revisions are used) | ||
| if (!list.Contains (diff_url)) | ||
| list.Add (diff_url); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <!-- | ||
| Copyright (c) Microsoft Corporation. | ||
| Licensed under the MIT License. | ||
| --> | ||
| # Changelog | ||
|
|
||
| This tool reads dependency changes from a pull request and formats them as a | ||
| Markdown changelog. | ||
|
|
||
| ## Usage | ||
|
|
||
| ```sh | ||
| dotnet run --project scripts/changelog/changelog.csproj -- https://github.com/dotnet/macios/pull/11175 /tmp/changelog.txt | ||
| ``` | ||
|
|
||
| Additional arguments filter the dependency repositories included in the output. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <!-- | ||
| Copyright (c) Microsoft Corporation. | ||
| Licensed under the MIT License. | ||
| --> | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFramework>net$(BundledNETCoreAppTargetFrameworkVersion)</TargetFramework> | ||
| </PropertyGroup> | ||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
| include $(TOP)/scripts/template.mk | ||
| $(eval $(call TemplateScript,CHANGELOG,changelog)) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.