From 83385cfaa56dae6c6190b6dee1ca4da08fd6e7f8 Mon Sep 17 00:00:00 2001 From: Sandro Figo Date: Sat, 7 Jan 2023 12:30:33 +0100 Subject: [PATCH 1/7] Make GetReleaseSections() and ReleaseSection internal for testing --- source/Nuke.Common/ChangeLog/ChangeLogTasks.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/Nuke.Common/ChangeLog/ChangeLogTasks.cs b/source/Nuke.Common/ChangeLog/ChangeLogTasks.cs index 9addf9473..4fe912dce 100644 --- a/source/Nuke.Common/ChangeLog/ChangeLogTasks.cs +++ b/source/Nuke.Common/ChangeLog/ChangeLogTasks.cs @@ -173,7 +173,7 @@ public static IEnumerable ExtractChangelogSectionNotes(AbsolutePath chan .Take(section.EndIndex - section.StartIndex); } - private static IEnumerable GetReleaseSections(List content) + internal static IEnumerable GetReleaseSections(List content) { static bool IsReleaseHead(string str) => str.StartsWith("## "); @@ -242,7 +242,7 @@ private static void UpdateVersionSummary(string tag, List content, [CanB } [DebuggerDisplay("{" + nameof(Caption) + "} [{" + nameof(StartIndex) + "}-{" + nameof(EndIndex) + "}]")] - private class ReleaseSection + internal class ReleaseSection { public string Caption; public int StartIndex; From d3d45726b5987fc575eaabf48e4e3890dac9fdea Mon Sep 17 00:00:00 2001 From: Sandro Figo Date: Fri, 6 Jan 2023 22:58:57 +0100 Subject: [PATCH 2/7] Add unit tests for changelog tasks --- .../changelog_reference_1.0.0_variant_1.md | 49 +++++++ ...log_reference_1.0.0_variant_1.verified.txt | 84 +++++++++++ .../changelog_reference_1.0.0_variant_2.md | 19 +++ ...log_reference_1.0.0_variant_2.verified.txt | 32 +++++ .../changelog_reference_1.0.0_variant_3.md | 53 +++++++ ...log_reference_1.0.0_variant_3.verified.txt | 88 ++++++++++++ .../changelog_reference_1.0.0_variant_4.md | 7 + ...log_reference_1.0.0_variant_4.verified.txt | 14 ++ .../changelog_reference_1.0.0_variant_5.md | 10 ++ ...log_reference_1.0.0_variant_5.verified.txt | 25 ++++ ...1.0.0_variant_5_section_0.2.3.verified.txt | 4 + .../changelog_reference_invalid_variant_1.md | 2 + .../changelog_reference_invalid_variant_2.md | 13 ++ .../Nuke.Common.Tests/ChangelogTasksTest.cs | 130 ++++++++++++++++++ 14 files changed, 530 insertions(+) create mode 100644 source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_1.md create mode 100644 source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_1.verified.txt create mode 100644 source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_2.md create mode 100644 source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_2.verified.txt create mode 100644 source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_3.md create mode 100644 source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_3.verified.txt create mode 100644 source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_4.md create mode 100644 source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_4.verified.txt create mode 100644 source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_5.md create mode 100644 source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_5.verified.txt create mode 100644 source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_5_section_0.2.3.verified.txt create mode 100644 source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_invalid_variant_1.md create mode 100644 source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_invalid_variant_2.md create mode 100644 source/Nuke.Common.Tests/ChangelogTasksTest.cs diff --git a/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_1.md b/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_1.md new file mode 100644 index 000000000..cd4d0eea9 --- /dev/null +++ b/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_1.md @@ -0,0 +1,49 @@ +Some text at the top of the changelog file. + +# Changelog + +This format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). + +## [Unreleased] + +### Added + +- Added something + +### Fixed + +- Fixed something + +## [1.4.0] - 2023-01-05 + +### Added + +- First item +- Second item + +### Changed + +- Fixed something +- Fixed something else + +## [1.0.0] - 2023-01-03 + +### Removed + +- Removed something + +## [0.2.0] - 2023-01-02 + +### Added + +- Some text that spans + multiple lines +- A text on a single line + +## [0.1.0] - 2023-01-01 + +### Added + +- Added something + +Some text at the end of the changelog file. \ No newline at end of file diff --git a/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_1.verified.txt b/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_1.verified.txt new file mode 100644 index 000000000..cf718eaeb --- /dev/null +++ b/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_1.verified.txt @@ -0,0 +1,84 @@ +[ + { + IsEmpty: false, + Unreleased: true, + Notes: [ + , + ### Added, + , + - Added something, + , + ### Fixed, + , + - Fixed something, + + ], + StartIndex: 6, + EndIndex: 15 + }, + { + IsEmpty: false, + Unreleased: false, + Version: 1.4.0, + Notes: [ + , + ### Added, + , + - First item, + - Second item, + , + ### Changed, + , + - Fixed something, + - Fixed something else, + + ], + StartIndex: 16, + EndIndex: 27 + }, + { + IsEmpty: false, + Unreleased: false, + Version: 1.0.0, + Notes: [ + , + ### Removed, + , + - Removed something, + + ], + StartIndex: 28, + EndIndex: 33 + }, + { + IsEmpty: false, + Unreleased: false, + Version: 0.2.0, + Notes: [ + , + ### Added, + , + - Some text that spans, + multiple lines, + - A text on a single line, + + ], + StartIndex: 34, + EndIndex: 41 + }, + { + IsEmpty: false, + Unreleased: false, + Version: 0.1.0, + Notes: [ + , + ### Added, + , + - Added something, + , + Some text at the end of the changelog file. + ], + StartIndex: 42, + EndIndex: 48 + } +] \ No newline at end of file diff --git a/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_2.md b/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_2.md new file mode 100644 index 000000000..078876296 --- /dev/null +++ b/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_2.md @@ -0,0 +1,19 @@ +# Changelog + +This format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). + +## [Unreleased] + +### Added + +- Some text that spans + multiple lines + +- A text on a single line + + +## [1.0.0] - 2023-01-01 + +### Fixed + +- Fixed something \ No newline at end of file diff --git a/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_2.verified.txt b/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_2.verified.txt new file mode 100644 index 000000000..e827ea1f6 --- /dev/null +++ b/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_2.verified.txt @@ -0,0 +1,32 @@ +[ + { + IsEmpty: false, + Unreleased: true, + Notes: [ + , + ### Added, + , + - Some text that spans, + multiple lines, + , + - A text on a single line, + , + + ], + StartIndex: 4, + EndIndex: 13 + }, + { + IsEmpty: false, + Unreleased: false, + Version: 1.0.0, + Notes: [ + , + ### Fixed, + , + - Fixed something + ], + StartIndex: 14, + EndIndex: 18 + } +] \ No newline at end of file diff --git a/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_3.md b/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_3.md new file mode 100644 index 000000000..496c7d5c4 --- /dev/null +++ b/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_3.md @@ -0,0 +1,53 @@ +Some text at the top of the changelog file. + +# Changelog + +This format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). + +## [Unreleased] + +### Added + +- Added something + + ### Fixed + +- Fixed something + +## [1.4.0] - 2023-01-05 + +### Added + + + + +- First item + +- Second item + +### Changed + +- Fixed something +- Fixed something else + +## [1.0.0] - 2023-01-03 + +### Removed + + - Removed something + +## [0.2.0] - 2023-01-02 + +### Added + +- Some text that spans + multiple lines +- A text on a single line + +## [0.1.0] - 2023-01-01 + +### Added + +- Added something + + Some text at the end of the changelog file. \ No newline at end of file diff --git a/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_3.verified.txt b/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_3.verified.txt new file mode 100644 index 000000000..4201b05c2 --- /dev/null +++ b/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_3.verified.txt @@ -0,0 +1,88 @@ +[ + { + IsEmpty: false, + Unreleased: true, + Notes: [ + , + ### Added, + , + - Added something, + , + ### Fixed, + , + - Fixed something, + + ], + StartIndex: 6, + EndIndex: 15 + }, + { + IsEmpty: false, + Unreleased: false, + Version: 1.4.0, + Notes: [ + , + ### Added , + , + , + , + , + - First item, + , + - Second item, + , + ### Changed, + , + - Fixed something, + - Fixed something else, + + ], + StartIndex: 16, + EndIndex: 31 + }, + { + IsEmpty: false, + Unreleased: false, + Version: 1.0.0, + Notes: [ + , + ### Removed, + , + - Removed something, + + ], + StartIndex: 32, + EndIndex: 37 + }, + { + IsEmpty: false, + Unreleased: false, + Version: 0.2.0, + Notes: [ + , + ### Added, + , + - Some text that spans, + multiple lines, + - A text on a single line, + + ], + StartIndex: 38, + EndIndex: 45 + }, + { + IsEmpty: false, + Unreleased: false, + Version: 0.1.0, + Notes: [ + , + ### Added, + , + - Added something, + , + Some text at the end of the changelog file. + ], + StartIndex: 46, + EndIndex: 52 + } +] \ No newline at end of file diff --git a/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_4.md b/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_4.md new file mode 100644 index 000000000..ea8781327 --- /dev/null +++ b/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_4.md @@ -0,0 +1,7 @@ +# Changelog +This format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## [Unreleased] +### Added +- Some text that spans + multiple lines +- A text on a single line \ No newline at end of file diff --git a/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_4.verified.txt b/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_4.verified.txt new file mode 100644 index 000000000..1dc9874b9 --- /dev/null +++ b/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_4.verified.txt @@ -0,0 +1,14 @@ +[ + { + IsEmpty: false, + Unreleased: true, + Notes: [ + ### Added, + - Some text that spans, + multiple lines, + - A text on a single line + ], + StartIndex: 2, + EndIndex: 6 + } +] \ No newline at end of file diff --git a/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_5.md b/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_5.md new file mode 100644 index 000000000..501bce708 --- /dev/null +++ b/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_5.md @@ -0,0 +1,10 @@ +# Changelog +This format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## [Unreleased] +### Added +- Some text that spans + multiple lines +- A text on a single line +## [0.2.3] - 2023-01-02 +### Fixed +- Fixed something \ No newline at end of file diff --git a/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_5.verified.txt b/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_5.verified.txt new file mode 100644 index 000000000..33aad9652 --- /dev/null +++ b/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_5.verified.txt @@ -0,0 +1,25 @@ +[ + { + IsEmpty: false, + Unreleased: true, + Notes: [ + ### Added, + - Some text that spans, + multiple lines, + - A text on a single line + ], + StartIndex: 2, + EndIndex: 6 + }, + { + IsEmpty: false, + Unreleased: false, + Version: 0.2.3, + Notes: [ + ### Fixed, + - Fixed something + ], + StartIndex: 7, + EndIndex: 9 + } +] \ No newline at end of file diff --git a/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_5_section_0.2.3.verified.txt b/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_5_section_0.2.3.verified.txt new file mode 100644 index 000000000..565c36793 --- /dev/null +++ b/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_1.0.0_variant_5_section_0.2.3.verified.txt @@ -0,0 +1,4 @@ +[ + ### Fixed, + - Fixed something +] \ No newline at end of file diff --git a/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_invalid_variant_1.md b/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_invalid_variant_1.md new file mode 100644 index 000000000..2fcff6fc2 --- /dev/null +++ b/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_invalid_variant_1.md @@ -0,0 +1,2 @@ +# Changelog +A change log that does not comply with the format from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). \ No newline at end of file diff --git a/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_invalid_variant_2.md b/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_invalid_variant_2.md new file mode 100644 index 000000000..a4b321c62 --- /dev/null +++ b/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_invalid_variant_2.md @@ -0,0 +1,13 @@ +# Changelog +A change log that does not comply with the format from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## [Unreleased] +### Added +- Some text that spans + multiple lines +- A text on a single line +## [Unreleased] +### Added +- Second unreleased section +## [0.2.3] - 2023-01-02 +### Fixed +- Fixed something \ No newline at end of file diff --git a/source/Nuke.Common.Tests/ChangelogTasksTest.cs b/source/Nuke.Common.Tests/ChangelogTasksTest.cs new file mode 100644 index 000000000..6c4d7cfc2 --- /dev/null +++ b/source/Nuke.Common.Tests/ChangelogTasksTest.cs @@ -0,0 +1,130 @@ +// Copyright 2023 Maintainers of NUKE. +// Distributed under the MIT License. +// https://github.com/nuke-build/nuke/blob/master/LICENSE + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using FluentAssertions; +using JetBrains.Annotations; +using Nuke.Common.ChangeLog; +using Nuke.Common.IO; +using VerifyXunit; +using Xunit; + +namespace Nuke.Common.Tests +{ + [UsesVerify] + public class ChangelogTasksTest + { + private static AbsolutePath RootDirectory => Constants.TryGetRootDirectoryFrom(EnvironmentInfo.WorkingDirectory).NotNull(); + + private static AbsolutePath PathToChangelogReferenceFiles => RootDirectory / "source" / "Nuke.Common.Tests" / "ChangelogReferenceFiles"; + + [Theory] + [MemberData(nameof(AllChangelogReference_1_0_0_Files))] + public void ReadReleaseNotes_ChangelogReferenceFile_ThrowsNoExceptions(AbsolutePath file) + { + Action act = () => ChangelogTasks.ReadReleaseNotes(file); + + act.Should().NotThrow(); + } + + [Theory] + [MemberData(nameof(AllChangelogReference_1_0_0_Files))] + public void ReadReleaseNotes_ChangelogReferenceFile_ReturnsAnyReleaseNotes(AbsolutePath file) + { + var releaseNotes = ChangelogTasks.ReadReleaseNotes(file); + + releaseNotes.Should().NotBeEmpty(); + } + + [Theory] + [MemberData(nameof(AllChangelogReference_1_0_0_Files))] + public void ReadChangelog_ChangelogReferenceFile_ThrowsNoExceptions(AbsolutePath file) + { + Action act = () => ChangelogTasks.ReadChangelog(file); + + act.Should().NotThrow(); + } + + [Theory] + [MemberData(nameof(AllChangelogReference_1_0_0_Files))] + public void ExtractChangelogSectionNotes_ChangelogReferenceFile_ThrowsNoExceptions(AbsolutePath file) + { + Action act = () => ChangelogTasks.ExtractChangelogSectionNotes(file); + + act.Should().NotThrow(); + } + + [Theory] + [MemberData(nameof(AllChangelogReference_1_0_0_Files))] + public Task ReadReleaseNotes_ChangelogReferenceFile_HasParsedCorrectly(AbsolutePath file) + { + var releaseNotes = ChangelogTasks.ReadReleaseNotes(file); + + return Verifier.Verify(releaseNotes).UseDirectory(PathToChangelogReferenceFiles).UseFileName(file.NameWithoutExtension); + } + + [Fact] + public void GetReleaseSections_ChangelogReferenceFileWithoutReleaseHead_ReturnsEmpty() + { + var changeLogFilePath = PathToChangelogReferenceFiles / "changelog_reference_invalid_variant_1.md"; + var lines = changeLogFilePath.ReadAllLines().ToList(); + + ChangelogTasks.GetReleaseSections(lines).Should().BeEmpty(); + } + + [Theory] + [InlineData("changelog_reference_1.0.0_variant_5.md", "0.2.3")] + public Task ExtractChangelogSectionNotes_WithTag_ReturnsSectionThatMatchesProvidedTag(string fileName, string tag) + { + var changeLogFilePath = PathToChangelogReferenceFiles / fileName; + var sectionNotes = ChangelogTasks.ExtractChangelogSectionNotes(changeLogFilePath, tag); + + return Verifier.Verify(sectionNotes).UseDirectory(PathToChangelogReferenceFiles) + .UseFileName($"{changeLogFilePath.NameWithoutExtension}_section_{tag}"); + } + + [Theory] + [InlineData("changelog_reference_1.0.0_variant_5.md", "0.0.0")] + [InlineData("changelog_reference_1.0.0_variant_5.md", "9.9.9")] + public void ExtractChangelogSection_WithNonExistingTag_ThrowsInformativeException(string fileName, string tag) + { + var changeLogFilePath = PathToChangelogReferenceFiles / fileName; + + Action act = () => ChangelogTasks.ExtractChangelogSectionNotes(changeLogFilePath, tag); + + act.Should().Throw().Where(ex => ex.Message == $"Could not find release section for '{tag}'."); + } + + [Theory] + [InlineData("changelog_reference_invalid_variant_2.md")] + public void ReadChangelog_ChangelogFileThatHasMultipleUnreleasedSection_ThrowsInformativeException(string fileName) + { + var changeLogFilePath = PathToChangelogReferenceFiles / fileName; + + Action act = () => ChangelogTasks.ReadChangelog(changeLogFilePath); + + act.Should().Throw().Where(ex => ex.Message == "Changelog should have only one draft section"); + } + + [Theory] + [InlineData("changelog_reference_invalid_variant_1.md")] + public void ReadChangelog_EmptyChangelogFile_ThrowsInformativeException(string fileName) + { + var changeLogFilePath = PathToChangelogReferenceFiles / fileName; + + Action act = () => ChangelogTasks.ReadChangelog(changeLogFilePath); + + act.Should().Throw().Where(ex => ex.Message == "Changelog should have at least one release note section"); + } + + [UsedImplicitly] + public static IEnumerable AllChangelogReference_1_0_0_Files + { + get => PathToChangelogReferenceFiles.GlobFiles("changelog_reference_1.0.0*.md").Select(file => new object[] { file }); + } + } +} From fc63d206c3d52b86347215a3178fe1f76768dbe7 Mon Sep 17 00:00:00 2001 From: Sandro Figo Date: Wed, 25 Jan 2023 11:28:59 +0100 Subject: [PATCH 3/7] Fix ExtractChangelogSectionNotes not throwing the intended exception --- source/Nuke.Common/ChangeLog/ChangeLogTasks.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/Nuke.Common/ChangeLog/ChangeLogTasks.cs b/source/Nuke.Common/ChangeLog/ChangeLogTasks.cs index 4fe912dce..0374003c2 100644 --- a/source/Nuke.Common/ChangeLog/ChangeLogTasks.cs +++ b/source/Nuke.Common/ChangeLog/ChangeLogTasks.cs @@ -166,7 +166,7 @@ public static IEnumerable ExtractChangelogSectionNotes(AbsolutePath chan var sections = GetReleaseSections(content); var section = tag == null ? sections.First(x => x.StartIndex < x.EndIndex) - : sections.First(x => x.Caption.EqualsOrdinalIgnoreCase(tag)).NotNull($"Could not find release section for '{tag}'."); + : sections.FirstOrDefault(x => x.Caption.EqualsOrdinalIgnoreCase(tag)).NotNull($"Could not find release section for '{tag}'."); return content .Skip(section.StartIndex + 1) From 1c86000ef6e963b6ea9f702fe7899299a25300d6 Mon Sep 17 00:00:00 2001 From: Sandro Figo Date: Wed, 25 Jan 2023 15:13:17 +0100 Subject: [PATCH 4/7] Fix ReleaseSection end index when changelog contains empty lines --- source/Nuke.Common/ChangeLog/ChangeLogTasks.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/Nuke.Common/ChangeLog/ChangeLogTasks.cs b/source/Nuke.Common/ChangeLog/ChangeLogTasks.cs index 0374003c2..b820fa273 100644 --- a/source/Nuke.Common/ChangeLog/ChangeLogTasks.cs +++ b/source/Nuke.Common/ChangeLog/ChangeLogTasks.cs @@ -204,15 +204,15 @@ static string GetCaption(string str) } var caption = GetCaption(line); - var nextNonReleaseContentIndex = content.FindIndex(index + 1, x => IsReleaseHead(x) || !IsReleaseContent(x)); + var nextReleaseHeadIndex = content.FindIndex(index + 1, IsReleaseHead); var releaseData = new ReleaseSection { Caption = caption, StartIndex = index, - EndIndex = nextNonReleaseContentIndex != -1 - ? nextNonReleaseContentIndex - 1 + EndIndex = nextReleaseHeadIndex >= 0 + ? nextReleaseHeadIndex - 1 : content.Count - 1 }; From 01efb5fe55a6446d0e21126a7f1cae059918f38f Mon Sep 17 00:00:00 2001 From: Sandro Figo Date: Thu, 16 Feb 2023 10:57:59 +0100 Subject: [PATCH 5/7] Add changelog reference files with NUKE flavor --- .../changelog_reference_NUKE_variant_1.md | 22 +++++++ ...elog_reference_NUKE_variant_1.verified.txt | 57 +++++++++++++++++++ .../changelog_reference_NUKE_variant_2.md | 23 ++++++++ ...elog_reference_NUKE_variant_2.verified.txt | 42 ++++++++++++++ .../Nuke.Common.Tests/ChangelogTasksTest.cs | 11 ++++ 5 files changed, 155 insertions(+) create mode 100644 source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_NUKE_variant_1.md create mode 100644 source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_NUKE_variant_1.verified.txt create mode 100644 source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_NUKE_variant_2.md create mode 100644 source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_NUKE_variant_2.verified.txt diff --git a/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_NUKE_variant_1.md b/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_NUKE_variant_1.md new file mode 100644 index 000000000..d119cc9d4 --- /dev/null +++ b/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_NUKE_variant_1.md @@ -0,0 +1,22 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) +and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). + +## [vNext] + +## [1.2.3] / 2022-01-02 +- Added something +- Fixed something + +## [1.2.2] / 2022-01-01 +- Fixed something + +## [0.2.0] / 2020-03-17 +- Added something + +## [0.1.0] / 2019-03-23 +- Added something + +Some text at the end of the changelog \ No newline at end of file diff --git a/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_NUKE_variant_1.verified.txt b/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_NUKE_variant_1.verified.txt new file mode 100644 index 000000000..c2b49667d --- /dev/null +++ b/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_NUKE_variant_1.verified.txt @@ -0,0 +1,57 @@ +[ + { + IsEmpty: true, + Unreleased: true, + Notes: [ + + ], + StartIndex: 6, + EndIndex: 7 + }, + { + IsEmpty: false, + Unreleased: false, + Version: 1.2.3, + Notes: [ + - Added something, + - Fixed something, + + ], + StartIndex: 8, + EndIndex: 11 + }, + { + IsEmpty: false, + Unreleased: false, + Version: 1.2.2, + Notes: [ + - Fixed something, + + ], + StartIndex: 12, + EndIndex: 14 + }, + { + IsEmpty: false, + Unreleased: false, + Version: 0.2.0, + Notes: [ + - Added something, + + ], + StartIndex: 15, + EndIndex: 17 + }, + { + IsEmpty: false, + Unreleased: false, + Version: 0.1.0, + Notes: [ + - Added something, + , + Some text at the end of the changelog + ], + StartIndex: 18, + EndIndex: 21 + } +] \ No newline at end of file diff --git a/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_NUKE_variant_2.md b/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_NUKE_variant_2.md new file mode 100644 index 000000000..b9ee3f660 --- /dev/null +++ b/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_NUKE_variant_2.md @@ -0,0 +1,23 @@ +# Changelog +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) +and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). + +## [vNext] +- Changed something + +## [1.0.0] / 2022-01-02 +- Some text that spans + multiple lines +- A text on a single line + +- Added something +- Fixed something + +## [0.1.0] / 2019-03-23 +- Added something + +- Fixed something + +Some text at the end of the changelog \ No newline at end of file diff --git a/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_NUKE_variant_2.verified.txt b/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_NUKE_variant_2.verified.txt new file mode 100644 index 000000000..8e7ed6050 --- /dev/null +++ b/source/Nuke.Common.Tests/ChangelogReferenceFiles/changelog_reference_NUKE_variant_2.verified.txt @@ -0,0 +1,42 @@ +[ + { + IsEmpty: false, + Unreleased: true, + Notes: [ + - Changed something, + + ], + StartIndex: 6, + EndIndex: 8 + }, + { + IsEmpty: false, + Unreleased: false, + Version: 1.0.0, + Notes: [ + - Some text that spans, + multiple lines, + - A text on a single line, + , + - Added something, + - Fixed something, + + ], + StartIndex: 9, + EndIndex: 16 + }, + { + IsEmpty: false, + Unreleased: false, + Version: 0.1.0, + Notes: [ + - Added something, + , + - Fixed something, + , + Some text at the end of the changelog + ], + StartIndex: 17, + EndIndex: 22 + } +] \ No newline at end of file diff --git a/source/Nuke.Common.Tests/ChangelogTasksTest.cs b/source/Nuke.Common.Tests/ChangelogTasksTest.cs index 6c4d7cfc2..8aafbb7af 100644 --- a/source/Nuke.Common.Tests/ChangelogTasksTest.cs +++ b/source/Nuke.Common.Tests/ChangelogTasksTest.cs @@ -24,6 +24,7 @@ public class ChangelogTasksTest [Theory] [MemberData(nameof(AllChangelogReference_1_0_0_Files))] + [MemberData(nameof(AllChangelogReference_NUKE_Files))] public void ReadReleaseNotes_ChangelogReferenceFile_ThrowsNoExceptions(AbsolutePath file) { Action act = () => ChangelogTasks.ReadReleaseNotes(file); @@ -33,6 +34,7 @@ public void ReadReleaseNotes_ChangelogReferenceFile_ThrowsNoExceptions(AbsoluteP [Theory] [MemberData(nameof(AllChangelogReference_1_0_0_Files))] + [MemberData(nameof(AllChangelogReference_NUKE_Files))] public void ReadReleaseNotes_ChangelogReferenceFile_ReturnsAnyReleaseNotes(AbsolutePath file) { var releaseNotes = ChangelogTasks.ReadReleaseNotes(file); @@ -42,6 +44,7 @@ public void ReadReleaseNotes_ChangelogReferenceFile_ReturnsAnyReleaseNotes(Absol [Theory] [MemberData(nameof(AllChangelogReference_1_0_0_Files))] + [MemberData(nameof(AllChangelogReference_NUKE_Files))] public void ReadChangelog_ChangelogReferenceFile_ThrowsNoExceptions(AbsolutePath file) { Action act = () => ChangelogTasks.ReadChangelog(file); @@ -51,6 +54,7 @@ public void ReadChangelog_ChangelogReferenceFile_ThrowsNoExceptions(AbsolutePath [Theory] [MemberData(nameof(AllChangelogReference_1_0_0_Files))] + [MemberData(nameof(AllChangelogReference_NUKE_Files))] public void ExtractChangelogSectionNotes_ChangelogReferenceFile_ThrowsNoExceptions(AbsolutePath file) { Action act = () => ChangelogTasks.ExtractChangelogSectionNotes(file); @@ -60,6 +64,7 @@ public void ExtractChangelogSectionNotes_ChangelogReferenceFile_ThrowsNoExceptio [Theory] [MemberData(nameof(AllChangelogReference_1_0_0_Files))] + [MemberData(nameof(AllChangelogReference_NUKE_Files))] public Task ReadReleaseNotes_ChangelogReferenceFile_HasParsedCorrectly(AbsolutePath file) { var releaseNotes = ChangelogTasks.ReadReleaseNotes(file); @@ -126,5 +131,11 @@ public static IEnumerable AllChangelogReference_1_0_0_Files { get => PathToChangelogReferenceFiles.GlobFiles("changelog_reference_1.0.0*.md").Select(file => new object[] { file }); } + + [UsedImplicitly] + public static IEnumerable AllChangelogReference_NUKE_Files + { + get => PathToChangelogReferenceFiles.GlobFiles("changelog_reference_NUKE*.md").Select(file => new object[] { file }); + } } } From db00d4509949680fac70ae63b435fc81bce3760d Mon Sep 17 00:00:00 2001 From: Sandro Figo Date: Thu, 16 Feb 2023 10:59:07 +0100 Subject: [PATCH 6/7] Fix IsEmpty property for release notes that have empty lines --- source/Nuke.Common/ChangeLog/ReleaseNotes.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/Nuke.Common/ChangeLog/ReleaseNotes.cs b/source/Nuke.Common/ChangeLog/ReleaseNotes.cs index 45eca78b3..1b840f9ec 100644 --- a/source/Nuke.Common/ChangeLog/ReleaseNotes.cs +++ b/source/Nuke.Common/ChangeLog/ReleaseNotes.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; +using System.Linq; using JetBrains.Annotations; using NuGet.Versioning; @@ -15,7 +16,7 @@ public class ReleaseNotes /// /// Gets a value indicating whether this release notes section contains notes. /// - public bool IsEmpty => Notes.Count == 0; + public bool IsEmpty => Notes.All(string.IsNullOrWhiteSpace); /// /// Gets a value indicating whether this release notes section is unreleased (vNext). From 31493213cf2d2a8cfa84a7df45100a1d36742da9 Mon Sep 17 00:00:00 2001 From: Matthias Koch Date: Mon, 15 May 2023 23:20:29 +0200 Subject: [PATCH 7/7] Fixes --- .../Nuke.Common.Tests/ChangelogTasksTest.cs | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/source/Nuke.Common.Tests/ChangelogTasksTest.cs b/source/Nuke.Common.Tests/ChangelogTasksTest.cs index 8aafbb7af..3f7f265d9 100644 --- a/source/Nuke.Common.Tests/ChangelogTasksTest.cs +++ b/source/Nuke.Common.Tests/ChangelogTasksTest.cs @@ -75,8 +75,8 @@ public Task ReadReleaseNotes_ChangelogReferenceFile_HasParsedCorrectly(AbsoluteP [Fact] public void GetReleaseSections_ChangelogReferenceFileWithoutReleaseHead_ReturnsEmpty() { - var changeLogFilePath = PathToChangelogReferenceFiles / "changelog_reference_invalid_variant_1.md"; - var lines = changeLogFilePath.ReadAllLines().ToList(); + var file = PathToChangelogReferenceFiles / "changelog_reference_invalid_variant_1.md"; + var lines = file.ReadAllLines().ToList(); ChangelogTasks.GetReleaseSections(lines).Should().BeEmpty(); } @@ -97,45 +97,43 @@ public Task ExtractChangelogSectionNotes_WithTag_ReturnsSectionThatMatchesProvid [InlineData("changelog_reference_1.0.0_variant_5.md", "9.9.9")] public void ExtractChangelogSection_WithNonExistingTag_ThrowsInformativeException(string fileName, string tag) { - var changeLogFilePath = PathToChangelogReferenceFiles / fileName; + var file = PathToChangelogReferenceFiles / fileName; - Action act = () => ChangelogTasks.ExtractChangelogSectionNotes(changeLogFilePath, tag); + Action act = () => ChangelogTasks.ExtractChangelogSectionNotes(file, tag); - act.Should().Throw().Where(ex => ex.Message == $"Could not find release section for '{tag}'."); + act.Should().Throw().WithMessage($"Could not find release section for '{tag}'."); } [Theory] [InlineData("changelog_reference_invalid_variant_2.md")] public void ReadChangelog_ChangelogFileThatHasMultipleUnreleasedSection_ThrowsInformativeException(string fileName) { - var changeLogFilePath = PathToChangelogReferenceFiles / fileName; + var file = PathToChangelogReferenceFiles / fileName; - Action act = () => ChangelogTasks.ReadChangelog(changeLogFilePath); + Action act = () => ChangelogTasks.ReadChangelog(file); - act.Should().Throw().Where(ex => ex.Message == "Changelog should have only one draft section"); + act.Should().Throw().WithMessage("Changelog should have only one draft section"); } [Theory] [InlineData("changelog_reference_invalid_variant_1.md")] public void ReadChangelog_EmptyChangelogFile_ThrowsInformativeException(string fileName) { - var changeLogFilePath = PathToChangelogReferenceFiles / fileName; + var file = PathToChangelogReferenceFiles / fileName; - Action act = () => ChangelogTasks.ReadChangelog(changeLogFilePath); + Action act = () => ChangelogTasks.ReadChangelog(file); - act.Should().Throw().Where(ex => ex.Message == "Changelog should have at least one release note section"); + act.Should().Throw().WithMessage("Changelog should have at least one release note section"); } [UsedImplicitly] public static IEnumerable AllChangelogReference_1_0_0_Files { - get => PathToChangelogReferenceFiles.GlobFiles("changelog_reference_1.0.0*.md").Select(file => new object[] { file }); + get => PathToChangelogReferenceFiles.GlobFiles("changelog_reference_1.0.0*.md").Select(x => new object[] { x }); } - + [UsedImplicitly] public static IEnumerable AllChangelogReference_NUKE_Files - { - get => PathToChangelogReferenceFiles.GlobFiles("changelog_reference_NUKE*.md").Select(file => new object[] { file }); - } + => PathToChangelogReferenceFiles.GlobFiles("changelog_reference_NUKE*.md").Select(x => new object[] { x }); } }