<commit_before>#r "./tools/FAKE/tools/FakeLib.dll"
#load "NVikaHelper.fsx"
#load "SemanticReleaseNotesParserHelper.fsx"

open Fake
open Fake.Testing.XUnit2
open Fake.NuGet.Install
open OpenCoverHelper
open NVikaHelper
open SemanticReleaseNotesParserHelper

// Properties
let buildDir = "./build/"
let testDir  = "./test/"
let artifactsDir = "./artifacts/"

// version info
let version = if isLocalBuild then "0.0.1" else if buildServer = AppVeyor then environVar "GitVersion_NuGetVersionV2" else buildVersion
let tag = if buildServer = AppVeyor then AppVeyor.AppVeyorEnvironment.RepoTagName else "v0.0.1"

// Targets
Target "Clean" (fun _ ->
    CleanDirs [buildDir; testDir; artifactsDir]
)

Target "RestorePackages" (fun _ ->
    "./src/SemanticReleaseNotesParser.sln"
    |> RestoreMSSolutionPackages (fun p -> { p with OutputPath = "src/packages" })
)

Target "BuildApp" (fun _ ->
    !! "src/SemanticReleaseNotesParser.Core/SemanticReleaseNotesParser.Core.csproj"
      |> MSBuildRelease null "Build"
      |> Log "AppBuild-Output: "

    !! "src/SemanticReleaseNotesParser/SemanticReleaseNotesParser.csproj"
      |> MSBuildRelease buildDir "Build"
      |> Log "AppBuild-Output: "
)

Target "InspectCodeAnalysis" (fun _ ->
    "resharper-clt.portable" |> Choco.Install id
    
    if directExec(fun info ->
        info.FileName <- "inspectcode"
        info.Arguments <- "/o=\"" + artifactsDir + "inspectcodereport_Core.xml\" /project=\"SemanticReleaseNotesParser.Core\" \"src\SemanticReleaseNotesParser.sln\"" )
    then
        if directExec(fun info ->
            info.FileName <- "inspectcode"
            info.Arguments <- "/o=\"" + artifactsDir + "inspectcodereport_Program.xml\" /project=\"SemanticReleaseNotesParser\" \"src\SemanticReleaseNotesParser.sln\"" )
        then
            "nvika" |> Choco.Install id
            [artifactsDir + "inspectcodereport_Core.xml"; artifactsDir + "inspectcodereport_Program.xml"] |> NVika.ParseReports (fun p -> { p with Debug = true; IncludeSource = true })
        else failwith "Execution of inspectcode have failed, NVika can't be executed."
    else failwith "Execution of inspectcode have failed, NVika can't be executed."
)

Target "ILRepack" (fun _ ->
    "ilrepack" |> NugetInstall (fun p -> 
    { p with 
        OutputDirectory = "tools";
        ExcludeVersion = true
    })
    
    if not (directExec(fun info ->
        info.FileName <- "./tools/ilrepack/tools/ilrepack" 
        info.Arguments <- @"/internalize /parallel /wildcards /lib:""C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.0"" /out:" + artifactsDir + "SemanticReleaseNotesParser.exe " + (buildDir @@ "SemanticReleaseNotesParser.exe ") + (buildDir @@ "*.dll") ))
    then
        failwith "Execution of ilrepack have failed."
)

Target "BuildReleaseNotes" (fun _ ->
     SemanticReleaseNotesParser.Convert (fun p -> { p with 
                                                        GroupBy = SemanticReleaseNotesParser.GroupByType.Categories
                                                        Debug = true
                                                        OutputPath = artifactsDir @@ "ReleaseNotes.html"
                                                        PluralizeCategoriesTitle = true
                                                        IncludeStyle = SemanticReleaseNotesParser.IncludeStyleType.Yes
                                                        ToolPath = if Choco.IsAvailable then artifactsDir @@ "SemanticReleaseNotesParser.exe" else buildDir @@ "SemanticReleaseNotesParser.exe"
        } )

     SemanticReleaseNotesParser.Convert (fun p -> { p with 
                                                        GroupBy = SemanticReleaseNotesParser.GroupByType.Categories
                                                        OutputType = SemanticReleaseNotesParser.OutputType.Environment
                                                        OutputFormat = SemanticReleaseNotesParser.OutputFormat.Markdown
                                                        Debug = true
                                                        PluralizeCategoriesTitle = true
                                                        ToolPath = if Choco.IsAvailable then artifactsDir @@ "SemanticReleaseNotesParser.exe" else buildDir @@ "SemanticReleaseNotesParser.exe"
        } )
)

Target "BuildTest" (fun _ ->
    !! "src/*.Tests/*.Tests.csproj"
      |> MSBuildRelease testDir "Build"
      |> Log "AppBuild-Output: "
)

Target "Test" (fun _ ->
    "xunit.runner.console" |> NugetInstall (fun p -> 
    { p with 
        OutputDirectory = "tools";
        ExcludeVersion = true
    })
    
    if isUnix then
        !! (testDir @@ "SemanticReleaseNotesParser.Core.Tests.dll")
        |> xUnit2 (fun p -> { p with 
                                HtmlOutputPath = Some (artifactsDir @@ "xunit.html") 
                                ShadowCopy = false
                            })
    else

        "OpenCover" |> NugetInstall (fun p -> 
        { p with 
            OutputDirectory = "tools";
            ExcludeVersion = true
        })
    
        testDir + "SemanticReleaseNotesParser.Core.Tests.dll -noshadow" |> OpenCover (fun p -> 
        { p with
            ExePath = "./tools/OpenCover/tools/OpenCover.Console.exe"
            TestRunnerExePath = "./tools/xunit.runner.console/tools/xunit.console.exe";
            Output = artifactsDir @@ "coverage.xml";
            Register = RegisterUser;
            Filter = "+[SemanticReleaseNotesParser.Core]*";
            OptionalArguments = "-excludebyattribute:*.ExcludeFromCodeCoverage* -returntargetcode";
        })
    
        testDir + "SemanticReleaseNotesParser.Tests.dll -noshadow" |> OpenCover (fun p -> 
        { p with
            ExePath = "./tools/OpenCover/tools/OpenCover.Console.exe"
            TestRunnerExePath = "./tools/xunit.runner.console/tools/xunit.console.exe";
            Output = artifactsDir @@ "coverage.xml";
            Register = RegisterUser;
            Filter = "+[SemanticReleaseNotesParser]*";
            OptionalArguments = "-excludebyattribute:*.ExcludeFromCodeCoverage* -returntargetcode -mergeoutput";
        })
    
        if isLocalBuild then
            "ReportGenerator" |> NugetInstall (fun p -> 
            { p with 
                OutputDirectory = "tools";
                ExcludeVersion = true
            })
            [artifactsDir @@ "coverage.xml"] |> ReportGeneratorHelper.ReportGenerator (fun p -> 
            { p with 
                TargetDir = artifactsDir @@ "reports" 
                ExePath = @"tools\ReportGenerator\tools\ReportGenerator.exe"
                LogVerbosity = ReportGeneratorHelper.ReportGeneratorLogVerbosity.Error
            })
        else
            "coveralls.io" |> NugetInstall (fun p -> 
            { p with 
                OutputDirectory = "tools";
                ExcludeVersion = true
            })
            if not (directExec(fun info ->
                info.FileName <- @"tools\coveralls.io\tools\coveralls.net.exe"
                info.Arguments <- "--opencover " + artifactsDir + "coverage.xml" ))
            then
                failwith "Execution of coveralls.net have failed."
)

Target "Zip" (fun _ ->
    !! (artifactsDir + "SemanticReleaseNotesParser.exe")
    ++ (artifactsDir + "ReleaseNotes.html")
    |> Zip artifactsDir (artifactsDir + "SemanticReleaseNotesParser." + version + ".zip")
)

Target "PackFakeHelper" (fun _ ->
    "SemanticReleaseNotesParserHelper.fsx" |> FileHelper.CopyFile artifactsDir
    artifactsDir @@ "SemanticReleaseNotesParserHelper.fsx" |> FileHelper.RegexReplaceInFileWithEncoding "./tools/FAKE/tools/FakeLib.dll" "FakeLib.dll" System.Text.Encoding.UTF8
)

Target "ChocoPack" (fun _ ->
    Choco.Pack (fun p -> 
        { p with 
            PackageId = "semanticreleasenotes-parser"
            Version = version
            Title = "Semantic Release Notes Parser"
            Authors = ["laedit"]
            Owners = ["laedit"]
            ProjectUrl = "https://github.com/laedit/SemanticReleaseNotesParser"
            IconUrl = "https://cdn.rawgit.com/laedit/SemanticReleaseNotesParser/master/icon.png"
            LicenseUrl = "https://github.com/laedit/SemanticReleaseNotesParser/blob/master/LICENSE"
            BugTrackerUrl = "https://github.com/laedit/https://github.com/laedit/SemanticReleaseNotesParser/blob/master/LICENSE/issues"<commit_msg>Use codecov instead of coveralls for code coverage<commit_after>#r "./tools/FAKE/tools/FakeLib.dll"
#load "NVikaHelper.fsx"
#load "SemanticReleaseNotesParserHelper.fsx"

open Fake
open Fake.Testing.XUnit2
open Fake.NuGet.Install
open OpenCoverHelper
open NVikaHelper
open SemanticReleaseNotesParserHelper

// Properties
let buildDir = "./build/"
let testDir  = "./test/"
let artifactsDir = "./artifacts/"

// version info
let version = if isLocalBuild then "0.0.1" else if buildServer = AppVeyor then environVar "GitVersion_NuGetVersionV2" else buildVersion
let tag = if buildServer = AppVeyor then AppVeyor.AppVeyorEnvironment.RepoTagName else "v0.0.1"

// Targets
Target "Clean" (fun _ ->
    CleanDirs [buildDir; testDir; artifactsDir]
)

Target "RestorePackages" (fun _ ->
    "./src/SemanticReleaseNotesParser.sln"
    |> RestoreMSSolutionPackages (fun p -> { p with OutputPath = "src/packages" })
)

Target "BuildApp" (fun _ ->
    !! "src/SemanticReleaseNotesParser.Core/SemanticReleaseNotesParser.Core.csproj"
      |> MSBuildRelease null "Build"
      |> Log "AppBuild-Output: "

    !! "src/SemanticReleaseNotesParser/SemanticReleaseNotesParser.csproj"
      |> MSBuildRelease buildDir "Build"
      |> Log "AppBuild-Output: "
)

Target "InspectCodeAnalysis" (fun _ ->
    "resharper-clt.portable" |> Choco.Install id
    
    if directExec(fun info ->
        info.FileName <- "inspectcode"
        info.Arguments <- "/o=\"" + artifactsDir + "inspectcodereport_Core.xml\" /project=\"SemanticReleaseNotesParser.Core\" \"src\SemanticReleaseNotesParser.sln\"" )
    then
        if directExec(fun info ->
            info.FileName <- "inspectcode"
            info.Arguments <- "/o=\"" + artifactsDir + "inspectcodereport_Program.xml\" /project=\"SemanticReleaseNotesParser\" \"src\SemanticReleaseNotesParser.sln\"" )
        then
            "nvika" |> Choco.Install id
            [artifactsDir + "inspectcodereport_Core.xml"; artifactsDir + "inspectcodereport_Program.xml"] |> NVika.ParseReports (fun p -> { p with Debug = true; IncludeSource = true })
        else failwith "Execution of inspectcode have failed, NVika can't be executed."
    else failwith "Execution of inspectcode have failed, NVika can't be executed."
)

Target "ILRepack" (fun _ ->
    "ilrepack" |> NugetInstall (fun p -> 
    { p with 
        OutputDirectory = "tools";
        ExcludeVersion = true
    })
    
    if not (directExec(fun info ->
        info.FileName <- "./tools/ilrepack/tools/ilrepack" 
        info.Arguments <- @"/internalize /parallel /wildcards /lib:""C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.0"" /out:" + artifactsDir + "SemanticReleaseNotesParser.exe " + (buildDir @@ "SemanticReleaseNotesParser.exe ") + (buildDir @@ "*.dll") ))
    then
        failwith "Execution of ilrepack have failed."
)

Target "BuildReleaseNotes" (fun _ ->
     SemanticReleaseNotesParser.Convert (fun p -> { p with 
                                                        GroupBy = SemanticReleaseNotesParser.GroupByType.Categories
                                                        Debug = true
                                                        OutputPath = artifactsDir @@ "ReleaseNotes.html"
                                                        PluralizeCategoriesTitle = true
                                                        IncludeStyle = SemanticReleaseNotesParser.IncludeStyleType.Yes
                                                        ToolPath = if Choco.IsAvailable then artifactsDir @@ "SemanticReleaseNotesParser.exe" else buildDir @@ "SemanticReleaseNotesParser.exe"
        } )

     SemanticReleaseNotesParser.Convert (fun p -> { p with 
                                                        GroupBy = SemanticReleaseNotesParser.GroupByType.Categories
                                                        OutputType = SemanticReleaseNotesParser.OutputType.Environment
                                                        OutputFormat = SemanticReleaseNotesParser.OutputFormat.Markdown
                                                        Debug = true
                                                        PluralizeCategoriesTitle = true
                                                        ToolPath = if Choco.IsAvailable then artifactsDir @@ "SemanticReleaseNotesParser.exe" else buildDir @@ "SemanticReleaseNotesParser.exe"
        } )
)

Target "BuildTest" (fun _ ->
    !! "src/*.Tests/*.Tests.csproj"
      |> MSBuildRelease testDir "Build"
      |> Log "AppBuild-Output: "
)

Target "Test" (fun _ ->
    "xunit.runner.console" |> NugetInstall (fun p -> 
    { p with 
        OutputDirectory = "tools";
        ExcludeVersion = true
    })
    
    if isUnix then
        !! (testDir @@ "SemanticReleaseNotesParser.Core.Tests.dll")
        |> xUnit2 (fun p -> { p with 
                                HtmlOutputPath = Some (artifactsDir @@ "xunit.html") 
                                ShadowCopy = false
                            })
    else

        "OpenCover" |> NugetInstall (fun p -> 
        { p with 
            OutputDirectory = "tools";
            ExcludeVersion = true
        })
    
        testDir + "SemanticReleaseNotesParser.Core.Tests.dll -noshadow" |> OpenCover (fun p -> 
        { p with
            ExePath = "./tools/OpenCover/tools/OpenCover.Console.exe"
            TestRunnerExePath = "./tools/xunit.runner.console/tools/xunit.console.exe";
            Output = artifactsDir @@ "coverage.xml";
            Register = RegisterUser;
            Filter = "+[SemanticReleaseNotesParser.Core]*";
            OptionalArguments = "-excludebyattribute:*.ExcludeFromCodeCoverage* -returntargetcode";
        })
    
        testDir + "SemanticReleaseNotesParser.Tests.dll -noshadow" |> OpenCover (fun p -> 
        { p with
            ExePath = "./tools/OpenCover/tools/OpenCover.Console.exe"
            TestRunnerExePath = "./tools/xunit.runner.console/tools/xunit.console.exe";
            Output = artifactsDir @@ "coverage.xml";
            Register = RegisterUser;
            Filter = "+[SemanticReleaseNotesParser]*";
            OptionalArguments = "-excludebyattribute:*.ExcludeFromCodeCoverage* -returntargetcode -mergeoutput";
        })
    
        if isLocalBuild then
            "ReportGenerator" |> NugetInstall (fun p -> 
            { p with 
                OutputDirectory = "tools";
                ExcludeVersion = true
            })
            [artifactsDir @@ "coverage.xml"] |> ReportGeneratorHelper.ReportGenerator (fun p -> 
            { p with 
                TargetDir = artifactsDir @@ "reports" 
                ExePath = @"tools\ReportGenerator\tools\ReportGenerator.exe"
                LogVerbosity = ReportGeneratorHelper.ReportGeneratorLogVerbosity.Error
            })
        else
            if not (directExec(fun info ->
                info.FileName <- "bash"
                info.Arguments <- "<(curl -s https://codecov.io/bash) -f " + artifactsDir + "coverage.xml" ))
            then
                failwith "Execution of coveralls.net have failed."
)

Target "Zip" (fun _ ->
    !! (artifactsDir + "SemanticReleaseNotesParser.exe")
    ++ (artifactsDir + "ReleaseNotes.html")
    |> Zip artifactsDir (artifactsDir + "SemanticReleaseNotesParser." + version + ".zip")
)

Target "PackFakeHelper" (fun _ ->
    "SemanticReleaseNotesParserHelper.fsx" |> FileHelper.CopyFile artifactsDir
    artifactsDir @@ "SemanticReleaseNotesParserHelper.fsx" |> FileHelper.RegexReplaceInFileWithEncoding "./tools/FAKE/tools/FakeLib.dll" "FakeLib.dll" System.Text.Encoding.UTF8
)

Target "ChocoPack" (fun _ ->
    Choco.Pack (fun p -> 
        { p with 
            PackageId = "semanticreleasenotes-parser"
            Version = version
            Title = "Semantic Release Notes Parser"
            Authors = ["laedit"]
            Owners = ["laedit"]
            ProjectUrl = "https://github.com/laedit/SemanticReleaseNotesParser"
            IconUrl = "https://cdn.rawgit.com/laedit/SemanticReleaseNotesParser/master/icon.png"
            LicenseUrl = "https://github.com/laedit/SemanticReleaseNotesParser/blob/master/LICENSE"
            BugTrackerUrl = "https://github.com/laedit/https://github.com/laedit/SemanticReleaseNotesParser/blob/master/LICENSE/issues"
{'fraction_non_alphanumeric': 0.10591250447013947, 'fraction_numerical': 0.0016688520681845274, 'mean_word_length': 2.042429737080689, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 103, 'https://': 11, 'lorem ipsum': 0, 'www.': 0, 'xml': 16}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 48, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1809152', 'n_tokens_mistral': 4749, 'n_tokens_neox': 4377, 'n_words': 903}