From f64a864592b419899cc4e39c7a65058f4f127f1a Mon Sep 17 00:00:00 2001 From: Mark Ridgwell Date: Thu, 19 Nov 2020 14:34:23 +0000 Subject: [PATCH 01/13] Updating readme --- README.md | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6598824e..bb40f286 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,20 @@ -# cs-template -C# Template +# Changelog manager .net tool + +## Installation + +```shell +dotnet tool install Credfeto.ChangeLog.Cmd +``` + +## Usage + +Extract the release notes for a pre-release build +```shell +dotnet changelog -changelog CHANGELOG.md -extract RELEASE_NOTES.md -version 1.0.1.27-master +``` + +Extract the release notes for a release build +```shell +dotnet changelog -changelog CHANGELOG.md -extract RELEASE_NOTES.md -version 1.0.2.77 +``` + From 45645e16b5080406c3cae13271a56ba5f9713bae Mon Sep 17 00:00:00 2001 From: Mark Ridgwell Date: Thu, 19 Nov 2020 15:41:55 +0000 Subject: [PATCH 02/13] updated .net version to 5.0.100 --- src/global.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/global.json b/src/global.json index 31a570e6..b611b490 100644 --- a/src/global.json +++ b/src/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "3.1.403", + "version": "5.0.100", "allowPrerelease": false, "rollForward": "disable" } From 874a11f850730f965f758ae5ab8c165ca83a213f Mon Sep 17 00:00:00 2001 From: Mark Ridgwell Date: Thu, 19 Nov 2020 15:58:31 +0000 Subject: [PATCH 03/13] Updated changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a52ca7df..123c20fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Please ADD ALL Changes to the UNRELEASED SECTION and not a specific release ## [Unreleased] ### Added +- Added support for checking where changelog entries were entered ### Fixed ### Changed ### Removed From 24428cb2d8ae746d3638fb6e660d89d44d82db56 Mon Sep 17 00:00:00 2001 From: Mark Ridgwell Date: Thu, 19 Nov 2020 17:05:06 +0000 Subject: [PATCH 04/13] Added changelog entry that should be reported as out of the range --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 123c20fe..080e0a41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,4 +23,5 @@ Releases that have at least been deployed to staging, BUT NOT necessarily releas - Support for extracting the changelog for a specific release - Support for extracting the changelog for a unreleased content -## [0.0.0] - Project created \ No newline at end of file +## [0.0.0] - Project created +- This should be an error \ No newline at end of file From 4cfeca1a4718f47ffb2ff9170cfe5d58b35db94e Mon Sep 17 00:00:00 2001 From: Mark Ridgwell Date: Thu, 19 Nov 2020 17:57:53 +0000 Subject: [PATCH 05/13] Checking diff between hard coded master and latest checked in version --- .../Credfeto.ChangeLog.Cmd.csproj | 2 +- src/Credfeto.ChangeLog.Cmd/Program.cs | 104 ++++++++++++++++++ 2 files changed, 105 insertions(+), 1 deletion(-) diff --git a/src/Credfeto.ChangeLog.Cmd/Credfeto.ChangeLog.Cmd.csproj b/src/Credfeto.ChangeLog.Cmd/Credfeto.ChangeLog.Cmd.csproj index 85657243..6b7de1b6 100644 --- a/src/Credfeto.ChangeLog.Cmd/Credfeto.ChangeLog.Cmd.csproj +++ b/src/Credfeto.ChangeLog.Cmd/Credfeto.ChangeLog.Cmd.csproj @@ -26,7 +26,7 @@ - + diff --git a/src/Credfeto.ChangeLog.Cmd/Program.cs b/src/Credfeto.ChangeLog.Cmd/Program.cs index 54420af6..353c5e89 100644 --- a/src/Credfeto.ChangeLog.Cmd/Program.cs +++ b/src/Credfeto.ChangeLog.Cmd/Program.cs @@ -1,9 +1,12 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; using Credfeto.ChangeLog.Management; +using LibGit2Sharp; using Microsoft.Extensions.Configuration; namespace Credfeto.ChangeLog.Cmd @@ -19,6 +22,100 @@ private static async Task Main(string[] args) try { + string workDir = Environment.CurrentDirectory; + + using (Repository repo = OpenRepository(workDir)) + { + string? sha = repo.Head.Tip.Sha; + Console.WriteLine($"Head SHA: {sha}"); + + const string originBranchName = "master"; + + Branch? originBranch = repo.Branches.FirstOrDefault(b => b.FriendlyName == originBranchName); + + if (originBranch == null) + { + // Can't find origin branch - error + } + else + { + if (originBranch.Tip.Sha == sha) + { + // same branch + } + else + { + // Blob oldblob = repo.Lookup(originBranch.Tip.Sha); + // Blob newblob = repo.Lookup(repo.Head.Tip.Sha); + + Regex versionMatchRegex = new(pattern: @"^##\s\[(\d+)", options: RegexOptions.Compiled); + + string[] changelog = await File.ReadAllLinesAsync(@"D:\Work\changelog-manager\CHANGELOG.md"); + + int firstReleaseVersionIndex = -1; + + for (int lineIndex = 0; lineIndex < changelog.Length; ++lineIndex) + { + string line = changelog[lineIndex]; + + if (versionMatchRegex.IsMatch(line)) + { + firstReleaseVersionIndex = lineIndex; + + break; + } + } + + if (firstReleaseVersionIndex != -1) + { + Console.WriteLine(); + Console.WriteLine(); + Console.WriteLine($"First release version: {firstReleaseVersionIndex}"); + + Patch changes = repo.Diff.Compare(oldTree: originBranch.Tip.Tree, + newTree: repo.Head.Tip.Tree, + new CompareOptions {ContextLines = 0, InterhunkLines = 0, IncludeUnmodified = false}); + + Regex regex = new(pattern: @"^@@\s*\-(?\d*)(,(?\d*))?\s*\+(?\d*)(,(?\d*))?\s*@@", + RegexOptions.Compiled | RegexOptions.Multiline); + + foreach (var change in changes) + { + if (change.Path == "CHANGELOG.md") + { + string patchDetails = change.Patch; + Console.WriteLine(patchDetails); + + MatchCollection matches = regex.Matches(patchDetails); + + foreach (Match match in matches) + { + int changeStart = Convert.ToInt32(match.Groups["CurrentFileStart"] + .Value); + + if (!int.TryParse(s: match.Groups["CurrentFileChangeLength"] + .Value, + out int changeLength)) + { + changeLength = 1; + } + + int changeEnd = changeStart + changeLength; + Console.WriteLine($"Hunk Start: {changeStart}"); + Console.WriteLine($"Hunk End: {changeEnd}"); + + if (changeEnd >= firstReleaseVersionIndex) + { + Console.WriteLine("---- Error - Content modified after First release"); + } + } + } + } + } + } + } + } + IConfigurationRoot configuration = LoadConfiguration(args); string changeLog = configuration.GetValue(key: @"changelog"); @@ -84,5 +181,12 @@ private static IConfigurationRoot LoadConfiguration(string[] args) }) .Build(); } + + private static Repository OpenRepository(string workDir) + { + string found = Repository.Discover(workDir); + + return new Repository(found); + } } } \ No newline at end of file From 268cb0b85d91da7446468c365ed0eb49d65bdb6f Mon Sep 17 00:00:00 2001 From: Mark Ridgwell Date: Thu, 19 Nov 2020 18:44:17 +0000 Subject: [PATCH 06/13] Moved the changelog check into the lib --- .../Credfeto.ChangeLog.Cmd.csproj | 1 - src/Credfeto.ChangeLog.Cmd/Program.cs | 127 +++--------------- .../BranchMissingException.cs | 22 +++ src/Credfeto.ChangeLog/ChangeLogChecker.cs | 102 ++++++++++++++ src/Credfeto.ChangeLog/ChangeLogReader.cs | 30 ++++- src/Credfeto.ChangeLog/ChangeLogUpdater.cs | 2 +- .../Credfeto.ChangeLog.csproj | 4 + 7 files changed, 174 insertions(+), 114 deletions(-) create mode 100644 src/Credfeto.ChangeLog/BranchMissingException.cs create mode 100644 src/Credfeto.ChangeLog/ChangeLogChecker.cs diff --git a/src/Credfeto.ChangeLog.Cmd/Credfeto.ChangeLog.Cmd.csproj b/src/Credfeto.ChangeLog.Cmd/Credfeto.ChangeLog.Cmd.csproj index 6b7de1b6..5e696bbd 100644 --- a/src/Credfeto.ChangeLog.Cmd/Credfeto.ChangeLog.Cmd.csproj +++ b/src/Credfeto.ChangeLog.Cmd/Credfeto.ChangeLog.Cmd.csproj @@ -26,7 +26,6 @@ - diff --git a/src/Credfeto.ChangeLog.Cmd/Program.cs b/src/Credfeto.ChangeLog.Cmd/Program.cs index 353c5e89..6677e9bf 100644 --- a/src/Credfeto.ChangeLog.Cmd/Program.cs +++ b/src/Credfeto.ChangeLog.Cmd/Program.cs @@ -1,12 +1,9 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using System.Text; -using System.Text.RegularExpressions; using System.Threading.Tasks; using Credfeto.ChangeLog.Management; -using LibGit2Sharp; using Microsoft.Extensions.Configuration; namespace Credfeto.ChangeLog.Cmd @@ -22,100 +19,6 @@ private static async Task Main(string[] args) try { - string workDir = Environment.CurrentDirectory; - - using (Repository repo = OpenRepository(workDir)) - { - string? sha = repo.Head.Tip.Sha; - Console.WriteLine($"Head SHA: {sha}"); - - const string originBranchName = "master"; - - Branch? originBranch = repo.Branches.FirstOrDefault(b => b.FriendlyName == originBranchName); - - if (originBranch == null) - { - // Can't find origin branch - error - } - else - { - if (originBranch.Tip.Sha == sha) - { - // same branch - } - else - { - // Blob oldblob = repo.Lookup(originBranch.Tip.Sha); - // Blob newblob = repo.Lookup(repo.Head.Tip.Sha); - - Regex versionMatchRegex = new(pattern: @"^##\s\[(\d+)", options: RegexOptions.Compiled); - - string[] changelog = await File.ReadAllLinesAsync(@"D:\Work\changelog-manager\CHANGELOG.md"); - - int firstReleaseVersionIndex = -1; - - for (int lineIndex = 0; lineIndex < changelog.Length; ++lineIndex) - { - string line = changelog[lineIndex]; - - if (versionMatchRegex.IsMatch(line)) - { - firstReleaseVersionIndex = lineIndex; - - break; - } - } - - if (firstReleaseVersionIndex != -1) - { - Console.WriteLine(); - Console.WriteLine(); - Console.WriteLine($"First release version: {firstReleaseVersionIndex}"); - - Patch changes = repo.Diff.Compare(oldTree: originBranch.Tip.Tree, - newTree: repo.Head.Tip.Tree, - new CompareOptions {ContextLines = 0, InterhunkLines = 0, IncludeUnmodified = false}); - - Regex regex = new(pattern: @"^@@\s*\-(?\d*)(,(?\d*))?\s*\+(?\d*)(,(?\d*))?\s*@@", - RegexOptions.Compiled | RegexOptions.Multiline); - - foreach (var change in changes) - { - if (change.Path == "CHANGELOG.md") - { - string patchDetails = change.Patch; - Console.WriteLine(patchDetails); - - MatchCollection matches = regex.Matches(patchDetails); - - foreach (Match match in matches) - { - int changeStart = Convert.ToInt32(match.Groups["CurrentFileStart"] - .Value); - - if (!int.TryParse(s: match.Groups["CurrentFileChangeLength"] - .Value, - out int changeLength)) - { - changeLength = 1; - } - - int changeEnd = changeStart + changeLength; - Console.WriteLine($"Hunk Start: {changeStart}"); - Console.WriteLine($"Hunk End: {changeEnd}"); - - if (changeEnd >= firstReleaseVersionIndex) - { - Console.WriteLine("---- Error - Content modified after First release"); - } - } - } - } - } - } - } - } - IConfigurationRoot configuration = LoadConfiguration(args); string changeLog = configuration.GetValue(key: @"changelog"); @@ -133,7 +36,7 @@ private static async Task Main(string[] args) { string version = configuration.GetValue("version"); - string text = await ChangeLogReader.ExtractReleasNodesFromFileAsync(changeLogFileName: changeLog, version: version); + string text = await ChangeLogReader.ExtractReleaseNodesFromFileAsync(changeLogFileName: changeLog, version: version); await File.WriteAllTextAsync(path: extractFileName, contents: text, encoding: Encoding.UTF8); @@ -158,6 +61,24 @@ private static async Task Main(string[] args) return SUCCESS; } + string? branchName = configuration.GetValue("check-insert"); + + if (!string.IsNullOrWhiteSpace(branchName)) + { + bool valid = await ChangeLogChecker.ChangeLogModifiedInReleaseSectionAsync(changeLogFileName: changeLog, originBranchName: branchName); + + if (valid) + { + Console.WriteLine("Changelog is valid"); + + return SUCCESS; + } + + await Console.Error.WriteLineAsync("ERROR: Changelog modified in released section"); + + return ERROR; + } + return ERROR; } catch (Exception exception) @@ -177,16 +98,10 @@ private static IConfigurationRoot LoadConfiguration(string[] args) {@"-version", @"version"}, {@"-extract", @"extract"}, {@"-add", @"add"}, - {@"-message", @"message"} + {@"-message", @"message"}, + {@"-check-insert", @"check-insert"} }) .Build(); } - - private static Repository OpenRepository(string workDir) - { - string found = Repository.Discover(workDir); - - return new Repository(found); - } } } \ No newline at end of file diff --git a/src/Credfeto.ChangeLog/BranchMissingException.cs b/src/Credfeto.ChangeLog/BranchMissingException.cs new file mode 100644 index 00000000..4c9ae05d --- /dev/null +++ b/src/Credfeto.ChangeLog/BranchMissingException.cs @@ -0,0 +1,22 @@ +using System; + +namespace Credfeto.ChangeLog.Management +{ + public sealed class BranchMissingException : Exception + { + public BranchMissingException() + : this("Could not find branch") + { + } + + public BranchMissingException(string message) + : base(message) + { + } + + public BranchMissingException(string message, Exception innerException) + : base(message: message, innerException: innerException) + { + } + } +} \ No newline at end of file diff --git a/src/Credfeto.ChangeLog/ChangeLogChecker.cs b/src/Credfeto.ChangeLog/ChangeLogChecker.cs new file mode 100644 index 00000000..6cf41923 --- /dev/null +++ b/src/Credfeto.ChangeLog/ChangeLogChecker.cs @@ -0,0 +1,102 @@ +using System; +using System.IO; +using System.Linq; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using LibGit2Sharp; + +namespace Credfeto.ChangeLog.Management +{ + public static class ChangeLogChecker + { + private static readonly Regex HunkPositionRegex = + new(pattern: @"^@@\s*\-(?\d*)(,(?\d*))?\s*\+(?\d*)(,(?\d*))?\s*@@", + RegexOptions.Compiled | RegexOptions.Multiline); + + public static async Task ChangeLogModifiedInReleaseSectionAsync(string changeLogFileName, string originBranchName) + { + int? position = await ChangeLogReader.FindFirstReleaseVersionPositionAsync(changeLogFileName); + + if (position == null) + { + return false; + } + + string changelogDir = Path.GetDirectoryName(changeLogFileName)!; + + using (Repository repo = OpenRepository(changelogDir)) + { + string? sha = repo.Head.Tip.Sha; + + Branch? originBranch = repo.Branches.FirstOrDefault(b => b.FriendlyName == originBranchName); + + if (originBranch == null) + { + throw new BranchMissingException($"Could not find branch {originBranchName}"); + } + + if (originBranch.Tip.Sha == sha) + { + // same branch/commit + return false; + } + + string changeLogInRepoPath = FindChangeLogPositionInRepo(repo: repo, changeLogFileName: changeLogFileName); + + int firstReleaseVersionIndex = position.Value; + + Patch changes = repo.Diff.Compare(oldTree: originBranch.Tip.Tree, + newTree: repo.Head.Tip.Tree, + new CompareOptions {ContextLines = 0, InterhunkLines = 0, IncludeUnmodified = false}); + + foreach (var change in changes) + { + if (change.Path == changeLogInRepoPath) + { + string patchDetails = change.Patch; + Console.WriteLine(patchDetails); + + MatchCollection matches = HunkPositionRegex.Matches(patchDetails); + + foreach (Match match in matches) + { + int changeStart = Convert.ToInt32(match.Groups["CurrentFileStart"] + .Value); + + if (!int.TryParse(s: match.Groups["CurrentFileChangeLength"] + .Value, + out int changeLength)) + { + changeLength = 1; + } + + int changeEnd = changeStart + changeLength; + + if (changeEnd >= firstReleaseVersionIndex) + { + return false; + } + } + + return true; + } + } + } + + return true; + } + + private static string FindChangeLogPositionInRepo(Repository repo, string changeLogFileName) + { + return changeLogFileName.Substring(repo.Info.WorkingDirectory.Length) + .Replace(oldValue: "\\", newValue: "/"); + } + + private static Repository OpenRepository(string workDir) + { + string found = Repository.Discover(workDir); + + return new Repository(found); + } + } +} \ No newline at end of file diff --git a/src/Credfeto.ChangeLog/ChangeLogReader.cs b/src/Credfeto.ChangeLog/ChangeLogReader.cs index 3b104ca9..7c922cee 100644 --- a/src/Credfeto.ChangeLog/ChangeLogReader.cs +++ b/src/Credfeto.ChangeLog/ChangeLogReader.cs @@ -7,11 +7,12 @@ namespace Credfeto.ChangeLog.Management { - public sealed class ChangeLogReader + public static class ChangeLogReader { - private static readonly Regex RemoveComments = new Regex(pattern: "", RegexOptions.Compiled | RegexOptions.Multiline); + private static readonly Regex RemoveComments = new(pattern: "", RegexOptions.Compiled | RegexOptions.Multiline); + private static readonly Regex VersionHeaderMatch = new(pattern: @"^##\s\[(\d+)", options: RegexOptions.Compiled); - public static async Task ExtractReleasNodesFromFileAsync(string changeLogFileName, string version) + public static async Task ExtractReleaseNodesFromFileAsync(string changeLogFileName, string version) { string textBlock = await File.ReadAllTextAsync(path: changeLogFileName, encoding: Encoding.UTF8); @@ -28,8 +29,6 @@ public static string ExtractReleaseNotes(string changeLog, string version) FindSectionForBuild(text: text, version: releaseVersion, out int foundStart, out int foundEnd); - StringBuilder releaseNotes = new StringBuilder(); - if (foundStart == -1) { return string.Empty; @@ -40,7 +39,9 @@ public static string ExtractReleaseNotes(string changeLog, string version) foundEnd = text.Length; } - string previousLine = ""; + string previousLine = string.Empty; + + StringBuilder releaseNotes = new(); for (int i = foundStart; i < foundEnd; i++) { @@ -78,6 +79,23 @@ public static string ExtractReleaseNotes(string changeLog, string version) .Trim(); } + public static async Task FindFirstReleaseVersionPositionAsync(string changeLogFileName) + { + IReadOnlyList changelog = await File.ReadAllLinesAsync(path: changeLogFileName, encoding: Encoding.UTF8); + + for (int lineIndex = 0; lineIndex < changelog.Count; ++lineIndex) + { + string line = changelog[lineIndex]; + + if (VersionHeaderMatch.IsMatch(line)) + { + return lineIndex; + } + } + + return null; + } + private static void FindSectionForBuild(string[] text, Version? version, out int foundStart, out int foundEnd) { foundStart = -1; diff --git a/src/Credfeto.ChangeLog/ChangeLogUpdater.cs b/src/Credfeto.ChangeLog/ChangeLogUpdater.cs index e0242396..4d329d8c 100644 --- a/src/Credfeto.ChangeLog/ChangeLogUpdater.cs +++ b/src/Credfeto.ChangeLog/ChangeLogUpdater.cs @@ -7,7 +7,7 @@ namespace Credfeto.ChangeLog.Management { - public sealed class ChangeLogUpdater + public static class ChangeLogUpdater { public static async Task AddEntryAsync(string changeLogFileName, string type, string message) { diff --git a/src/Credfeto.ChangeLog/Credfeto.ChangeLog.csproj b/src/Credfeto.ChangeLog/Credfeto.ChangeLog.csproj index c33c340d..b1646943 100644 --- a/src/Credfeto.ChangeLog/Credfeto.ChangeLog.csproj +++ b/src/Credfeto.ChangeLog/Credfeto.ChangeLog.csproj @@ -25,6 +25,10 @@ en-GB + + + + From ce67e64fe5e183073306b48453e57409899da077 Mon Sep 17 00:00:00 2001 From: Mark Ridgwell Date: Thu, 19 Nov 2020 18:46:39 +0000 Subject: [PATCH 07/13] Removed erroring line --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 080e0a41..123c20fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,5 +23,4 @@ Releases that have at least been deployed to staging, BUT NOT necessarily releas - Support for extracting the changelog for a specific release - Support for extracting the changelog for a unreleased content -## [0.0.0] - Project created -- This should be an error \ No newline at end of file +## [0.0.0] - Project created \ No newline at end of file From 4aa6076e7e2a4d0f987836038371e9e2904d91c3 Mon Sep 17 00:00:00 2001 From: Mark Ridgwell Date: Thu, 19 Nov 2020 18:59:59 +0000 Subject: [PATCH 08/13] Added check on changelog --- .github/workflows/pr-lint.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.github/workflows/pr-lint.yml b/.github/workflows/pr-lint.yml index 59de92ba..5cfbef43 100644 --- a/.github/workflows/pr-lint.yml +++ b/.github/workflows/pr-lint.yml @@ -29,3 +29,22 @@ jobs: noChangelogLabel: Changelog Not Required env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + change-log-entry-is-in-unreleased: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2.3.4 + with: + fetch-depth: 0 + - uses: credfeto/action-dotnet-version-detect@v1.1.1 + - uses: actions/setup-dotnet@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + dotnet-version: ${{ env.DOTNET_VERSION }} + - name: Enable dotnet tools + run: dotnet new tool-manifest + - name: Install Changelog tool + run: dotnet tool install --local Credfeto.ChangeLog.Cmd + - name Check Changelog + run: dotnet changelog -changelog D:\Work\changelog-manager\CHANGELOG.md -check-insert ${{ github.base_ref}} \ No newline at end of file From 995c17450cc5df5dac4d33a5d7f14b932b2a764d Mon Sep 17 00:00:00 2001 From: Mark Ridgwell Date: Thu, 19 Nov 2020 19:06:45 +0000 Subject: [PATCH 09/13] Added check on changelog --- .github/workflows/pr-lint.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/pr-lint.yml b/.github/workflows/pr-lint.yml index 5cfbef43..c6a52cee 100644 --- a/.github/workflows/pr-lint.yml +++ b/.github/workflows/pr-lint.yml @@ -19,21 +19,21 @@ jobs: include-changelog-entry: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2.3.4 - with: - fetch-depth: 0 - - if: ${{ github.actor != 'dependabot-preview[bot]' }} - uses: Zomzog/changelog-checker@v1.1.0 - with: - fileName: CHANGELOG.md - noChangelogLabel: Changelog Not Required - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - uses: actions/checkout@v2.3.4 + with: + fetch-depth: 0 + - if: ${{ github.actor != 'dependabot[bot]' }} + uses: Zomzog/changelog-checker@v1.1.0 + with: + fileName: CHANGELOG.md + noChangelogLabel: Changelog Not Required + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} change-log-entry-is-in-unreleased: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2.3.4 + - uses: actions/checkout@v2.3.4 with: fetch-depth: 0 - uses: credfeto/action-dotnet-version-detect@v1.1.1 From fe3b89118ebdbfb3d305fdd72d155f841fc89b1d Mon Sep 17 00:00:00 2001 From: Mark Ridgwell Date: Thu, 19 Nov 2020 19:12:01 +0000 Subject: [PATCH 10/13] Added check on changelog --- .github/workflows/pr-lint.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-lint.yml b/.github/workflows/pr-lint.yml index c6a52cee..b26c93c7 100644 --- a/.github/workflows/pr-lint.yml +++ b/.github/workflows/pr-lint.yml @@ -34,8 +34,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2.3.4 - with: - fetch-depth: 0 + with: + fetch-depth: 0 - uses: credfeto/action-dotnet-version-detect@v1.1.1 - uses: actions/setup-dotnet@v1 env: From d30052bafb7393dd350721fb597dea02b25ef9d4 Mon Sep 17 00:00:00 2001 From: Mark Ridgwell Date: Thu, 19 Nov 2020 19:14:19 +0000 Subject: [PATCH 11/13] Added check on changelog --- .github/workflows/pr-lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-lint.yml b/.github/workflows/pr-lint.yml index b26c93c7..241a84b6 100644 --- a/.github/workflows/pr-lint.yml +++ b/.github/workflows/pr-lint.yml @@ -46,5 +46,5 @@ jobs: run: dotnet new tool-manifest - name: Install Changelog tool run: dotnet tool install --local Credfeto.ChangeLog.Cmd - - name Check Changelog + - name: Check Changelog run: dotnet changelog -changelog D:\Work\changelog-manager\CHANGELOG.md -check-insert ${{ github.base_ref}} \ No newline at end of file From 9e664faca3777eaf6bbae3ead90936b91288b975 Mon Sep 17 00:00:00 2001 From: Mark Ridgwell Date: Thu, 19 Nov 2020 19:19:24 +0000 Subject: [PATCH 12/13] Backed out .net core 5 as needs all the build utils to be rebuilt first --- .../Credfeto.ChangeLog.Cmd.csproj | 2 +- .../Credfeto.ChangeLog.Tests.csproj | 2 +- src/Credfeto.ChangeLog/ChangeLogChecker.cs | 11 ++++++++--- src/Credfeto.ChangeLog/ChangeLogReader.cs | 6 +++--- src/Credfeto.ChangeLog/Credfeto.ChangeLog.csproj | 2 +- src/global.json | 2 +- 6 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/Credfeto.ChangeLog.Cmd/Credfeto.ChangeLog.Cmd.csproj b/src/Credfeto.ChangeLog.Cmd/Credfeto.ChangeLog.Cmd.csproj index 5e696bbd..316d3cb5 100644 --- a/src/Credfeto.ChangeLog.Cmd/Credfeto.ChangeLog.Cmd.csproj +++ b/src/Credfeto.ChangeLog.Cmd/Credfeto.ChangeLog.Cmd.csproj @@ -1,7 +1,7 @@ Exe - net5.0 + netcoreapp3.1 win10-x64;win81-x64;osx.10.12-x64 true diff --git a/src/Credfeto.ChangeLog.Tests/Credfeto.ChangeLog.Tests.csproj b/src/Credfeto.ChangeLog.Tests/Credfeto.ChangeLog.Tests.csproj index 71ffe4df..1f855dc9 100644 --- a/src/Credfeto.ChangeLog.Tests/Credfeto.ChangeLog.Tests.csproj +++ b/src/Credfeto.ChangeLog.Tests/Credfeto.ChangeLog.Tests.csproj @@ -1,7 +1,7 @@ Library - net5.0 + netcoreapp3.1 true True diff --git a/src/Credfeto.ChangeLog/ChangeLogChecker.cs b/src/Credfeto.ChangeLog/ChangeLogChecker.cs index 6cf41923..8f010a44 100644 --- a/src/Credfeto.ChangeLog/ChangeLogChecker.cs +++ b/src/Credfeto.ChangeLog/ChangeLogChecker.cs @@ -10,8 +10,8 @@ namespace Credfeto.ChangeLog.Management public static class ChangeLogChecker { private static readonly Regex HunkPositionRegex = - new(pattern: @"^@@\s*\-(?\d*)(,(?\d*))?\s*\+(?\d*)(,(?\d*))?\s*@@", - RegexOptions.Compiled | RegexOptions.Multiline); + new Regex(pattern: @"^@@\s*\-(?\d*)(,(?\d*))?\s*\+(?\d*)(,(?\d*))?\s*@@", + RegexOptions.Compiled | RegexOptions.Multiline); public static async Task ChangeLogModifiedInReleaseSectionAsync(string changeLogFileName, string originBranchName) { @@ -58,8 +58,13 @@ public static async Task ChangeLogModifiedInReleaseSectionAsync(string cha MatchCollection matches = HunkPositionRegex.Matches(patchDetails); - foreach (Match match in matches) + foreach (Match? match in matches) { + if (match == null) + { + continue; + } + int changeStart = Convert.ToInt32(match.Groups["CurrentFileStart"] .Value); diff --git a/src/Credfeto.ChangeLog/ChangeLogReader.cs b/src/Credfeto.ChangeLog/ChangeLogReader.cs index 7c922cee..edaaceb9 100644 --- a/src/Credfeto.ChangeLog/ChangeLogReader.cs +++ b/src/Credfeto.ChangeLog/ChangeLogReader.cs @@ -9,8 +9,8 @@ namespace Credfeto.ChangeLog.Management { public static class ChangeLogReader { - private static readonly Regex RemoveComments = new(pattern: "", RegexOptions.Compiled | RegexOptions.Multiline); - private static readonly Regex VersionHeaderMatch = new(pattern: @"^##\s\[(\d+)", options: RegexOptions.Compiled); + private static readonly Regex RemoveComments = new Regex(pattern: "", RegexOptions.Compiled | RegexOptions.Multiline); + private static readonly Regex VersionHeaderMatch = new Regex(pattern: @"^##\s\[(\d+)", options: RegexOptions.Compiled); public static async Task ExtractReleaseNodesFromFileAsync(string changeLogFileName, string version) { @@ -41,7 +41,7 @@ public static string ExtractReleaseNotes(string changeLog, string version) string previousLine = string.Empty; - StringBuilder releaseNotes = new(); + StringBuilder releaseNotes = new StringBuilder(); for (int i = foundStart; i < foundEnd; i++) { diff --git a/src/Credfeto.ChangeLog/Credfeto.ChangeLog.csproj b/src/Credfeto.ChangeLog/Credfeto.ChangeLog.csproj index b1646943..76a46d29 100644 --- a/src/Credfeto.ChangeLog/Credfeto.ChangeLog.csproj +++ b/src/Credfeto.ChangeLog/Credfeto.ChangeLog.csproj @@ -2,7 +2,7 @@ Library - net5.0 + netcoreapp3.1 true True diff --git a/src/global.json b/src/global.json index b611b490..31a570e6 100644 --- a/src/global.json +++ b/src/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "5.0.100", + "version": "3.1.403", "allowPrerelease": false, "rollForward": "disable" } From 099332c1a406e64b8d1cbd054ac9517a7abb7101 Mon Sep 17 00:00:00 2001 From: Mark Ridgwell Date: Thu, 19 Nov 2020 19:22:18 +0000 Subject: [PATCH 13/13] Missing output statment --- src/Credfeto.ChangeLog.Cmd/Program.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Credfeto.ChangeLog.Cmd/Program.cs b/src/Credfeto.ChangeLog.Cmd/Program.cs index 6677e9bf..8614ef9b 100644 --- a/src/Credfeto.ChangeLog.Cmd/Program.cs +++ b/src/Credfeto.ChangeLog.Cmd/Program.cs @@ -79,6 +79,8 @@ private static async Task Main(string[] args) return ERROR; } + Console.WriteLine("ERROR: No known action specified"); + return ERROR; } catch (Exception exception)