<commit_before>#load "./build/parameters.cake";
#load "./build/cmd.cake";
#load "./build/cmd.cake";

#addin "nuget:https://www.nuget.org/api/v2?package=Cake.Git&version=0.19.0"
#addin "nuget:https://www.nuget.org/api/v2?package=Cake.SemVer&version=3.0.0"
#addin "nuget:https://www.nuget.org/api/v2?package=semver&version=2.0.4"

#tool "nuget:https://www.nuget.org/api/v2?package=GitVersion.CommandLine&version=3.6.4"
#tool "nuget:?package=WiX"

BuildParameters parameters = BuildParameters.GetParameters(Context);

Setup(context =>
{
    parameters.Initialize(context);

    Information("================================================================================================");
    Information("Building version {1} of {0} ({2}, {3}) using version {4} of Cake. (IsApp: {5})",
        parameters.Project,
        parameters.Version.SemVersion,
        parameters.Configuration,
        parameters.Target,
        parameters.Version.CakeVersion,
        parameters.IsApp,
        parameters.IsTagged);

    Information("------------------------------------------------------------------------------------------------");
    Information("   GitVersion version:\t{0}", parameters.Version.SemVersion);
    Information(" ReleaseNotes version:\t{0}", parameters.ReleaseNotes.SemanticVersion);
    Information("Last released version:\t{0}", parameters.RepositoryPaths.Directories.LastReleasedVersion);
    Information("================================================================================================");
});

var target = Argument("target", "Default");

Task("Clean").Does(() => CleanDirectories(parameters.Paths.Directories.ToClean));

Task("Restore-NuGet-Packages")
    .IsDependentOn("Clean")
    .Does(() =>
    {
        var projects = GetFiles("./src/**/*.csproj");
        foreach(var project in projects)
        {
            DotNetCoreRestore(project.FullPath, new DotNetCoreRestoreSettings());
        }
    });

Task("Build")
    .IsDependentOn("Restore-NuGet-Packages")
    .WithCriteria(() => parameters.IsNetFull == false)
    .Does(() =>
    {
        var path = MakeAbsolute(parameters.RepositoryPaths.Directories.CsProjFile);
        DotNetCoreBuild(path.FullPath, new DotNetCoreBuildSettings()
        {
            Configuration = parameters.Configuration,
            OutputDirectory = parameters.Paths.Directories.ArtifactsBinNetCoreApp,
            ArgumentCustomization = args => args
                .Append("/p:Version={0}", parameters.Version.SemVersion)
                .Append("/p:AssemblyVersion={0}", parameters.Version.Version)
                .Append("/p:FileVersion={0}", parameters.Version.Version)
                .Append("/p:SourceLinkCreate=true")
        });
    });

Task("Publish-As-Msi")
    .IsDependentOn("Build")
    .WithCriteria(() => parameters.IsMsi)
    .Does(() =>
    {
        var path = MakeAbsolute(parameters.RepositoryPaths.Directories.CsProjFile);
        DotNetCorePublish(path.FullPath, new DotNetCorePublishSettings()
        {
            Configuration = parameters.Configuration,
            OutputDirectory = parameters.Paths.Directories.ArtifactsBinNetCoreAppPublishTemp,
            ArgumentCustomization = args => args
                .Append("/p:Version={0}", parameters.Version.SemVersion)
                .Append("/p:AssemblyVersion={0}", parameters.Version.Version)
                .Append("/p:FileVersion={0}", parameters.Version.Version)
                .Append("/p:SourceLinkCreate=true")
        });


        Information("================================================================================================");
        Information("Published bits path: {0}", parameters.Paths.Directories.ArtifactsBinNetCoreAppPublishTemp.FullPath);
        var filePath = File("App.wxs");
        WiXHeat(parameters.Paths.Directories.ArtifactsBinNetCoreAppPublishTemp.FullPath, filePath, WiXHarvestType.Dir, new HeatSettings {
            ArgumentCustomization = args => args.Append("-var var.Source"),
            ComponentGroupName = "References",
            Verbose = true,
            NoLogo = true,
            SuppressRootDirectory = true,
            GenerateGuid = true,
            GenerateGuidWithoutBraces = true,
            SuppressCom = true,
            SuppressRegistry = true,
            Transform = parameters.RepositoryPaths.Directories.WixHeatTransformXslt.FullPath
        });

        WiXCandle("App.wxs", new CandleSettings {
            ArgumentCustomization = args => args
                .Append("-dSource=" + parameters.Paths.Directories.ArtifactsBinNetCoreAppPublishTemp.FullPath)
                .Append("-ext WixUtilExtension"),
            Architecture = Architecture.X64,
            Verbose = true
        });

        WiXLight("App.wixobj", new LightSettings {
            ArgumentCustomization = args => args
                .Append("-dSource=" + parameters.Paths.Directories.ArtifactsBinNetCoreAppPublishTemp.FullPath)
                .Append("-ext WixUIExtension")
                .Append("-ext WixUtilExtension"),
            RawArguments = "-pedantic -v",
            OutputFile = parameters.Paths.Directories.ArtifactsBinNetCoreAppPublish + "/" + parameters.Project + ".msi"
        });

        DeleteDirectory(parameters.Paths.Directories.ArtifactsBinNetCoreAppPublishTemp.FullPath, recursive:true);
    });

Task("Publish-As-App")
    .IsDependentOn("Build")
    .WithCriteria(() => parameters.IsApp)
    .Does(() =>
    {
        var path = MakeAbsolute(parameters.RepositoryPaths.Directories.CsProjFile);
        DotNetCorePublish(path.FullPath, new DotNetCorePublishSettings()
        {
            Configuration = parameters.Configuration,
            OutputDirectory = parameters.Paths.Directories.ArtifactsBinNetCoreAppPublish,
            ArgumentCustomization = args => args
                .Append("/p:Version={0}", parameters.Version.SemVersion)
                .Append("/p:AssemblyVersion={0}", parameters.Version.Version)
                .Append("/p:FileVersion={0}", parameters.Version.Version)
                .Append("/p:SourceLinkCreate=true")
        });
    });

Task("Publish")
    .IsDependentOn("Publish-As-App")
    .IsDependentOn("Publish-As-Msi")
    .Does(() =>
    {
        Information("Publishing...");
    });

Task("Create-Lib-NuGet-Packages")
    .WithCriteria(() => parameters.IsLib)
    .IsDependentOn("Build")
    .Does(() =>
    {
        DotNetCorePack(parameters.RepositoryPaths.Directories.CsProjFile.ToString(), new DotNetCorePackSettings {
            Configuration = parameters.Configuration,
            OutputDirectory = parameters.Paths.Directories.NugetRoot,
            NoBuild = false,
            ArgumentCustomization = args => args
                .Append("/p:Version={0}", parameters.Version.SemVersion)
                .Append("/p:AssemblyVersion={0}", parameters.Version.Version)
                .Append("/p:FileVersion={0}", parameters.Version.Version)
                .Append("/p:SourceLinkCreate=true")
        });
    });

Task("Create-App-NuGet-Packages")
    .IsDependentOn("Publish")
    .WithCriteria(() => parameters.IsApp || parameters.IsMsi)
    .Does(() =>
    {
        var deployment = MakeAbsolute(parameters.RepositoryPaths.Directories.DeploymentPath).FullPath;
        var files = new DirectoryInfo(deployment).GetFiles().Select(f=> new NuSpecContent {Source = f.FullName, Target = "tools"}).ToList();
        files.Add(new NuSpecContent {Source = "**", Target = "content"});

        NuGetPack(new NuGetPackSettings {
                                     Id                      = parameters.NugetPackageName,
                                     Version                 = parameters.Version.SemVersion.ToString(),
                                     Title                   = parameters.NugetPackageName,
                                     Description             = "The description of the package",
                                     Authors                 = new[] {"<NAME>"},
                                     RequireLicenseAcceptance= false,
                                     Symbols                 = false,
                                     NoPackageAnalysis       = true,
                                     Files                   = files.ToArray(),
                                     BasePath                = parameters.Paths.Directories.ArtifactsBinNetCoreAppPublish,
                                     OutputDirectory         = parameters.Paths.Directories.NugetRoot
                                 });
    });

Task("Pack")
    .IsDependentOn("Create-Lib-NuGet-Packages")
    .IsDependentOn("Create-App-NuGet-Packages")
    .Does(() =>
    {
        Information("Packing...");
    });

Task("Release")
    .IsDependentOn("Pack")
    .WithCriteria(context => parameters.CanRelease)
    .WithCriteria(context => parameters.CanPublishNuGet)
    .Does(context =>
    {
        var apiKey = EnvironmentVariable("RELEASE_NUGETKEY");
        if(string.IsNullOrEmpty(apiKey)) throw new InvalidOperationException("Could not resolve NuGet API key from EnvVar=RELEASE_NUGETKEY.");

        var apiUrl = EnvironmentVariable("nugetserver");
        if(string.IsNullOrEmpty(apiUrl))
            apiUrl = "https://www.nuget.org/api/v2/package";

        var pkg = parameters.Packages.All.First();
        NuGetPush(pkg.PackagePath, new NuGetPushSettings {
            ApiKey = apiKey,
            Source = apiUrl
        });

        string tag = parameters.NugetPackageName + "@" + parameters.Version.SemVersion;
        GitTag("../.", tag);
        Cmd.ExecuteCommand(context, "git push --tags");
    });

Task("Default").IsDependentOn("Release");

RunTarget(target);
<commit_msg>Downgrades gitversion even more<commit_after>#load "./build/parameters.cake";
#load "./build/cmd.cake";
#load "./build/cmd.cake";

#addin "nuget:https://www.nuget.org/api/v2?package=Cake.Git&version=0.19.0"
#addin "nuget:https://www.nuget.org/api/v2?package=Cake.SemVer&version=3.0.0"
#addin "nuget:https://www.nuget.org/api/v2?package=semver&version=2.0.4"

#tool "nuget:https://www.nuget.org/api/v2?package=GitVersion.CommandLine&version=3.6.1"
#tool "nuget:?package=WiX"

BuildParameters parameters = BuildParameters.GetParameters(Context);

Setup(context =>
{
    parameters.Initialize(context);

    Information("================================================================================================");
    Information("Building version {1} of {0} ({2}, {3}) using version {4} of Cake. (IsApp: {5})",
        parameters.Project,
        parameters.Version.SemVersion,
        parameters.Configuration,
        parameters.Target,
        parameters.Version.CakeVersion,
        parameters.IsApp,
        parameters.IsTagged);

    Information("------------------------------------------------------------------------------------------------");
    Information("   GitVersion version:\t{0}", parameters.Version.SemVersion);
    Information(" ReleaseNotes version:\t{0}", parameters.ReleaseNotes.SemanticVersion);
    Information("Last released version:\t{0}", parameters.RepositoryPaths.Directories.LastReleasedVersion);
    Information("================================================================================================");
});

var target = Argument("target", "Default");

Task("Clean").Does(() => CleanDirectories(parameters.Paths.Directories.ToClean));

Task("Restore-NuGet-Packages")
    .IsDependentOn("Clean")
    .Does(() =>
    {
        var projects = GetFiles("./src/**/*.csproj");
        foreach(var project in projects)
        {
            DotNetCoreRestore(project.FullPath, new DotNetCoreRestoreSettings());
        }
    });

Task("Build")
    .IsDependentOn("Restore-NuGet-Packages")
    .WithCriteria(() => parameters.IsNetFull == false)
    .Does(() =>
    {
        var path = MakeAbsolute(parameters.RepositoryPaths.Directories.CsProjFile);
        DotNetCoreBuild(path.FullPath, new DotNetCoreBuildSettings()
        {
            Configuration = parameters.Configuration,
            OutputDirectory = parameters.Paths.Directories.ArtifactsBinNetCoreApp,
            ArgumentCustomization = args => args
                .Append("/p:Version={0}", parameters.Version.SemVersion)
                .Append("/p:AssemblyVersion={0}", parameters.Version.Version)
                .Append("/p:FileVersion={0}", parameters.Version.Version)
                .Append("/p:SourceLinkCreate=true")
        });
    });

Task("Publish-As-Msi")
    .IsDependentOn("Build")
    .WithCriteria(() => parameters.IsMsi)
    .Does(() =>
    {
        var path = MakeAbsolute(parameters.RepositoryPaths.Directories.CsProjFile);
        DotNetCorePublish(path.FullPath, new DotNetCorePublishSettings()
        {
            Configuration = parameters.Configuration,
            OutputDirectory = parameters.Paths.Directories.ArtifactsBinNetCoreAppPublishTemp,
            ArgumentCustomization = args => args
                .Append("/p:Version={0}", parameters.Version.SemVersion)
                .Append("/p:AssemblyVersion={0}", parameters.Version.Version)
                .Append("/p:FileVersion={0}", parameters.Version.Version)
                .Append("/p:SourceLinkCreate=true")
        });


        Information("================================================================================================");
        Information("Published bits path: {0}", parameters.Paths.Directories.ArtifactsBinNetCoreAppPublishTemp.FullPath);
        var filePath = File("App.wxs");
        WiXHeat(parameters.Paths.Directories.ArtifactsBinNetCoreAppPublishTemp.FullPath, filePath, WiXHarvestType.Dir, new HeatSettings {
            ArgumentCustomization = args => args.Append("-var var.Source"),
            ComponentGroupName = "References",
            Verbose = true,
            NoLogo = true,
            SuppressRootDirectory = true,
            GenerateGuid = true,
            GenerateGuidWithoutBraces = true,
            SuppressCom = true,
            SuppressRegistry = true,
            Transform = parameters.RepositoryPaths.Directories.WixHeatTransformXslt.FullPath
        });

        WiXCandle("App.wxs", new CandleSettings {
            ArgumentCustomization = args => args
                .Append("-dSource=" + parameters.Paths.Directories.ArtifactsBinNetCoreAppPublishTemp.FullPath)
                .Append("-ext WixUtilExtension"),
            Architecture = Architecture.X64,
            Verbose = true
        });

        WiXLight("App.wixobj", new LightSettings {
            ArgumentCustomization = args => args
                .Append("-dSource=" + parameters.Paths.Directories.ArtifactsBinNetCoreAppPublishTemp.FullPath)
                .Append("-ext WixUIExtension")
                .Append("-ext WixUtilExtension"),
            RawArguments = "-pedantic -v",
            OutputFile = parameters.Paths.Directories.ArtifactsBinNetCoreAppPublish + "/" + parameters.Project + ".msi"
        });

        DeleteDirectory(parameters.Paths.Directories.ArtifactsBinNetCoreAppPublishTemp.FullPath, recursive:true);
    });

Task("Publish-As-App")
    .IsDependentOn("Build")
    .WithCriteria(() => parameters.IsApp)
    .Does(() =>
    {
        var path = MakeAbsolute(parameters.RepositoryPaths.Directories.CsProjFile);
        DotNetCorePublish(path.FullPath, new DotNetCorePublishSettings()
        {
            Configuration = parameters.Configuration,
            OutputDirectory = parameters.Paths.Directories.ArtifactsBinNetCoreAppPublish,
            ArgumentCustomization = args => args
                .Append("/p:Version={0}", parameters.Version.SemVersion)
                .Append("/p:AssemblyVersion={0}", parameters.Version.Version)
                .Append("/p:FileVersion={0}", parameters.Version.Version)
                .Append("/p:SourceLinkCreate=true")
        });
    });

Task("Publish")
    .IsDependentOn("Publish-As-App")
    .IsDependentOn("Publish-As-Msi")
    .Does(() =>
    {
        Information("Publishing...");
    });

Task("Create-Lib-NuGet-Packages")
    .WithCriteria(() => parameters.IsLib)
    .IsDependentOn("Build")
    .Does(() =>
    {
        DotNetCorePack(parameters.RepositoryPaths.Directories.CsProjFile.ToString(), new DotNetCorePackSettings {
            Configuration = parameters.Configuration,
            OutputDirectory = parameters.Paths.Directories.NugetRoot,
            NoBuild = false,
            ArgumentCustomization = args => args
                .Append("/p:Version={0}", parameters.Version.SemVersion)
                .Append("/p:AssemblyVersion={0}", parameters.Version.Version)
                .Append("/p:FileVersion={0}", parameters.Version.Version)
                .Append("/p:SourceLinkCreate=true")
        });
    });

Task("Create-App-NuGet-Packages")
    .IsDependentOn("Publish")
    .WithCriteria(() => parameters.IsApp || parameters.IsMsi)
    .Does(() =>
    {
        var deployment = MakeAbsolute(parameters.RepositoryPaths.Directories.DeploymentPath).FullPath;
        var files = new DirectoryInfo(deployment).GetFiles().Select(f=> new NuSpecContent {Source = f.FullName, Target = "tools"}).ToList();
        files.Add(new NuSpecContent {Source = "**", Target = "content"});

        NuGetPack(new NuGetPackSettings {
                                     Id                      = parameters.NugetPackageName,
                                     Version                 = parameters.Version.SemVersion.ToString(),
                                     Title                   = parameters.NugetPackageName,
                                     Description             = "The description of the package",
                                     Authors                 = new[] {"<NAME>"},
                                     RequireLicenseAcceptance= false,
                                     Symbols                 = false,
                                     NoPackageAnalysis       = true,
                                     Files                   = files.ToArray(),
                                     BasePath                = parameters.Paths.Directories.ArtifactsBinNetCoreAppPublish,
                                     OutputDirectory         = parameters.Paths.Directories.NugetRoot
                                 });
    });

Task("Pack")
    .IsDependentOn("Create-Lib-NuGet-Packages")
    .IsDependentOn("Create-App-NuGet-Packages")
    .Does(() =>
    {
        Information("Packing...");
    });

Task("Release")
    .IsDependentOn("Pack")
    .WithCriteria(context => parameters.CanRelease)
    .WithCriteria(context => parameters.CanPublishNuGet)
    .Does(context =>
    {
        var apiKey = EnvironmentVariable("RELEASE_NUGETKEY");
        if(string.IsNullOrEmpty(apiKey)) throw new InvalidOperationException("Could not resolve NuGet API key from EnvVar=RELEASE_NUGETKEY.");

        var apiUrl = EnvironmentVariable("nugetserver");
        if(string.IsNullOrEmpty(apiUrl))
            apiUrl = "https://www.nuget.org/api/v2/package";

        var pkg = parameters.Packages.All.First();
        NuGetPush(pkg.PackagePath, new NuGetPushSettings {
            ApiKey = apiKey,
            Source = apiUrl
        });

        string tag = parameters.NugetPackageName + "@" + parameters.Version.SemVersion;
        GitTag("../.", tag);
        Cmd.ExecuteCommand(context, "git push --tags");
    });

Task("Default").IsDependentOn("Release");

RunTarget(target);

{'fraction_non_alphanumeric': 0.16347539633518632, 'fraction_numerical': 0.004323656578134651, 'mean_word_length': 2.362582208376601, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 57, 'https://': 10, 'lorem ipsum': 0, 'www.': 10, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '177648', 'n_tokens_mistral': 5116, 'n_tokens_neox': 4913, 'n_words': 721}