Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 6 additions & 14 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
root = true

[*]
[*.{fs,fsi,fsx}]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.{fs,fsx,fsi}]
max_line_length = 100
fsharp_alternative_long_member_definitions = true
fsharp_multi_line_lambda_closing_newline = true
fsharp_multiline_bracket_style = aligned
fsharp_keep_max_number_of_blank_lines = 1
fsharp_align_function_signature_to_indentation = true
fsharp_max_if_then_else_short_width = 0
fsharp_experimental_keep_indent_in_branch = true
fsharp_bar_before_discriminated_union_declaration = true

fsharp_experimental_elmish = true
fsharp_record_multiline_formatter = number_of_items
fsharp_array_or_list_multiline_formatter = number_of_items
fsharp_max_record_number_of_items = 0
fsharp_max_array_or_list_number_of_items = 0
# Expecto looks a bit nicer with stroustrup
[tests/**/*.fs]
fsharp_multiline_bracket_style = stroustrup
7 changes: 7 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Automatically normalize line endings
* text=auto

# Always use lf for F# files
*.fs text eol=lf
*.fsx text eol=lf
*.fsi text eol=lf
4 changes: 4 additions & 0 deletions .github/workflows/buildAndTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ jobs:
- uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
- name: Tool restore
run: dotnet tool restore
- name: Format Check
run: dotnet fantomas . --check || { if [ $? -eq 99 ]; then echo "The code was not formatted, run 'dotnet fantomas .' to format all code."; exit 1; fi; }
- name: Restore
run: dotnet restore
- name: Run Build
Expand Down
7 changes: 7 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<RestoreLockedMode Condition="'$(ContinuousIntegrationBuild)' == 'true'">true</RestoreLockedMode>
</PropertyGroup>
<PropertyGroup>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoWarn>$(NoWarn);3186,0042</NoWarn><!-- circumvent an error with the fake dependencymanager for paket: https://github.com/dotnet/fsharp/issues/8678 -->
<NoWarn>$(NoWarn);NU1902</NoWarn><!-- NU1902 - package vulnerability detected -->
<WarnOn>$(WarnOn);1182</WarnOn> <!-- Unused variables,https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/compiler-options#opt-in-warnings -->
<WarnOn>$(WarnOn);3390</WarnOn><!-- Malformed XML doc comments -->
</PropertyGroup>
<ItemGroup>
<!-- Automatically set RepositoryUrl, DebugType embedded, ContinuousIntegrationBuild -->
<PackageReference Include="DotNet.ReproducibleBuilds" PrivateAssets="All"/>
Expand Down
22 changes: 14 additions & 8 deletions src/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ type ChangelogExtensions =
(string section.Type,
section.ItemCollection
|> Seq.map _.MarkdownText
|> String.concat Environment.NewLine))
|> String.concat Environment.NewLine)
)

[<Extension>]
static member ToTaskItem(unreleased: ChangelogSectionUnreleased) =
Expand All @@ -51,9 +52,12 @@ type ChangelogExtensions =
| false, _ -> None
| true, version ->
Some
{| version = version
date = section.ToDateTime()
collection = section.SubSectionCollection |})
{|
version = version
date = section.ToDateTime()
collection = section.SubSectionCollection
|}
)

[<Extension>]
static member ToMarkdown(subsections: ChangelogSubSectionCollection) =
Expand All @@ -62,12 +66,13 @@ type ChangelogExtensions =
subsections
|> Seq.fold
(fun (builder: StringBuilder) subsection ->
let state = builder.AppendLine $"### {subsection.Type}"
|> (fun x -> x.AppendLine "")
let state =
builder.AppendLine $"### {subsection.Type}" |> (fun x -> x.AppendLine "")

subsection.ItemCollection
|> Seq.fold (fun (builder: StringBuilder) line -> builder.AppendLine $"- {line.MarkdownText}") state
|> (fun x -> x.AppendLine ""))
|> (fun x -> x.AppendLine "")
)
builder
|> _.ToString()
|> _.Trim()
Expand Down Expand Up @@ -146,7 +151,8 @@ type ParseChangeLogs() =
for (key, value) in x.collection.ToTaskItemMetadata() do
taskItem.SetMetadata(key, value)

taskItem :> ITaskItem)
taskItem :> ITaskItem
)

this.CurrentReleaseChangelog <- mapped[0]
this.AllReleasedChangelogs <- mapped
Expand Down
11 changes: 2 additions & 9 deletions src/Log.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,13 @@ let changelogFileNotFound (filePath: string) =
ErrorCode = "IKC0001"
HelpKeyword = "Missing Changelog file"
Message = "The Changelog file {0} was not found."
MessageArgs =
[|
box filePath
|]
MessageArgs = [| box filePath |]
}

let invalidChangelog (filePath: string) (error: string) =
{
ErrorCode = "IKC0002"
HelpKeyword = "Invalid Changelog file"
Message = "The Changelog file {0} is invalid. The error was: {1}"
MessageArgs =
[|
box filePath
box error
|]
MessageArgs = [| box filePath; box error |]
}
11 changes: 6 additions & 5 deletions tests/IntegrationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ open Faqt
open SimpleExec
open Workspace


module Utils =
let packAndGetPackageProperties projectName =
let packageCache = VirtualWorkspace.``test-package-cache``.``.``

if Directory.Exists packageCache then
Directory.Delete(packageCache, true)

Directory.CreateDirectory packageCache |> ignore

Command.Run(
"dotnet",
CmdLine.empty
Expand All @@ -24,6 +26,7 @@ module Utils =
|> CmdLine.toString,
workingDirectory = Workspace.fixtures.``.``
)

Command.ReadAsync(
"dotnet",
CmdLine.empty
Expand All @@ -39,8 +42,8 @@ module Utils =

type StringHelper =
[<Extension>]
static member ReplaceEscapedNewLines (s: string) =
s.ReplaceLineEndings().Replace("\\r\\n","\\n")
static member ReplaceEscapedNewLines(s: string) =
s.ReplaceLineEndings().Replace("\\r\\n", "\\n")

[<TestClass>]
type IntegrationTests() =
Expand All @@ -52,7 +55,6 @@ type IntegrationTests() =

this.testPackageVersion <- $"0.0.1-test-{suffix}"


// Create a package to be used in the tests
// I didn't find a way to test the MSBuild tasks execution using MSBuild only
// So each fsproj, will use a package reference to the package created here
Expand All @@ -78,7 +80,6 @@ type IntegrationTests() =
workingDirectory = Workspace.fixtures.``.``
)


[<TestMethod>]
member this.``works for absolute path with keep a changelog``() : Task =
task {
Expand Down
67 changes: 41 additions & 26 deletions tests/UnitTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,33 @@ open Faqt.Operators
open Microsoft.VisualStudio.TestTools.UnitTesting
open Workspace

type TestContext =
{
BuildEngine: Mock<IBuildEngine>
Errors: ResizeArray<BuildErrorEventArgs>
}
type TestContext = {
BuildEngine: Mock<IBuildEngine>
Errors: ResizeArray<BuildErrorEventArgs>
} with

member this.PrintErrors() =
this.Errors |> Seq.iter (fun error -> printfn "Error: %s" error.Message)

[<TestClass>]
type UnitTests() =

member val context = Unchecked.defaultof<TestContext> with get, set

[<TestInitialize>]
member this.Initialize() =
this.context <-
{
BuildEngine = Mock<IBuildEngine>()
Errors = ResizeArray<BuildErrorEventArgs>()
}
this.context <- {
BuildEngine = Mock<IBuildEngine>()
Errors = ResizeArray<BuildErrorEventArgs>()
}

this.context.BuildEngine
.Setup(fun engine -> engine.LogErrorEvent(It.IsAny<BuildErrorEventArgs>()))
.Callback(fun (args: BuildErrorEventArgs) -> this.context.Errors.Add(args))
|> ignore

[<TestMethod>]
member this.``task fails when changelog file does not exist`` () =
member this.``task fails when changelog file does not exist``() =

let myTask = ParseChangeLogs(ChangelogFile = "ThisFileDoesNotExist.md")
myTask.BuildEngine <- this.context.BuildEngine.Object
Expand All @@ -46,7 +46,7 @@ type UnitTests() =
%this.context.Errors.[0].Code.Should().Be("IKC0001")

[<TestMethod>]
member this.``task succeeds when changelog file exists (relative path)`` () =
member this.``task succeeds when changelog file exists (relative path)``() =
// When running tests, the working directory is where the dll is located
let myTask = ParseChangeLogs(ChangelogFile = "../../../changelogs/CHANGELOG.md")

Expand All @@ -60,7 +60,7 @@ type UnitTests() =
%this.context.Errors.Count.Should().Be(0)

[<TestMethod>]
member this.``task succeeds when changelog file exists (absolute path)`` () =
member this.``task succeeds when changelog file exists (absolute path)``() =
let myTask = ParseChangeLogs(ChangelogFile = Workspace.changelogs.``CHANGELOG.md``)
myTask.BuildEngine <- this.context.BuildEngine.Object

Expand All @@ -70,7 +70,7 @@ type UnitTests() =
%this.context.Errors.Count.Should().Be(0)

[<TestMethod>]
member this.``task fails when changelog file is invalid`` () =
member this.``task fails when changelog file is invalid``() =
let myTask =
ParseChangeLogs(ChangelogFile = Workspace.changelogs.``CHANGELOG_invalid.md``)

Expand All @@ -82,9 +82,8 @@ type UnitTests() =
%this.context.Errors.Count.Should().Be(1)
%this.context.Errors.[0].Code.Should().Be("IKC0002")


[<TestMethod>]
member this.``task correctly parses details from changelog file`` () =
member this.``task correctly parses details from changelog file``() =
let myTask =
ParseChangeLogs(ChangelogFile = Workspace.changelogs.``CHANGELOG_detailed.md``)

Expand All @@ -93,26 +92,42 @@ type UnitTests() =
let success = myTask.Execute()
%success.Should().BeTrue "Should have successfully parsed the changelog data"
%myTask.AllReleasedChangelogs.Length.Should().Be(9, "Should have 9 versions")
%myTask.CurrentReleaseChangelog.ItemSpec.Should().Be("0.1.8", "Should have the most recent version")
%myTask.CurrentReleaseChangelog.GetMetadata("Date").Should().Be("2022-03-31", "Should have the most recent version's date")
%(myTask.CurrentReleaseChangelog.MetadataNames |> Seq.cast |> _.Should().Contain("Changed", "Should have changed metadata"))
%(myTask.CurrentReleaseChangelog.MetadataNames |> Seq.cast |> _.Should().Contain("Date", "Should have date metadata"))

%myTask.CurrentReleaseChangelog.ItemSpec
.Should()
.Be("0.1.8", "Should have the most recent version")

%myTask.CurrentReleaseChangelog
.GetMetadata("Date")
.Should()
.Be("2022-03-31", "Should have the most recent version's date")

%(myTask.CurrentReleaseChangelog.MetadataNames
|> Seq.cast
|> _.Should().Contain("Changed", "Should have changed metadata"))

%(myTask.CurrentReleaseChangelog.MetadataNames
|> Seq.cast
|> _.Should().Contain("Date", "Should have date metadata"))

[<TestMethod>]
member this.``task produces expected markdown`` () =
let myTask =
ParseChangeLogs(ChangelogFile = Workspace.changelogs.``CHANGELOG.md``)
member this.``task produces expected markdown``() =
let myTask = ParseChangeLogs(ChangelogFile = Workspace.changelogs.``CHANGELOG.md``)

myTask.BuildEngine <- this.context.BuildEngine.Object

let success = myTask.Execute()
%success.Should().BeTrue "Should have successfully parsed the changelog data"
%myTask.LatestReleaseNotes.Should().Be("""### Added

%myTask.LatestReleaseNotes
.Should()
.Be(
"""### Added

- Created the package

### Changed

- Changed something in the package
- Updated the target framework""")

- Updated the target framework"""
)