<commit_before>﻿namespace Rosalia.Build
{
    using System.Reflection;
    using Rosalia.Build.Helpers;
    using Rosalia.Core.Api;
    using Rosalia.Core.Tasks.Futures;
    using Rosalia.Core.Tasks.Results;
    using Rosalia.TaskLib.AssemblyInfo;
    using Rosalia.TaskLib.Git.Tasks;
    using Rosalia.TaskLib.MsBuild;
    using Rosalia.TaskLib.NuGet.Tasks;

    public class BuildWorkflow : Workflow
    {
        protected override void RegisterTasks()
        {
            /* ======================================================================================== */
            var solutionTreeTask = Task(
                "Initialize context",
                context =>
                {
                    var projectRoot = context.WorkDirectory.Parent.Parent;
                    var src = projectRoot.GetDirectory("Src");

                    return new BuildData
                    {
                        Configuration = "Debug",
                        ProjectRootDirectory = projectRoot,
                        Src = src,
                        SolutionFile = src.GetFile("Rosalia.sln"),
                        Artifacts = projectRoot.GetDirectory("Artifacts")
                    }.AsTaskResult();
                });

            /* ======================================================================================== */
            
            var gitVersionTask = Task(
                "gitVersion",
                new GetVersionTask());

            /* ======================================================================================== */

            var solutionVersionTask = Task(
                "solutionVersion",
                from value in gitVersionTask
                select (value.Tag.Replace("v", string.Empty) + "." + value.CommitsCount).AsTaskResult());

            /* ======================================================================================== */

            ITaskFuture<Nothing> generateAssemblyInfoTask = Task(
                "Generate common assembly info file",
                
                from version in solutionVersionTask
                from data in solutionTreeTask
                select new GenerateAssemblyInfo(data.Src["CommonAssemblyInfo.cs"])
                {
                    Attributes =
                    {
                        _ => new AssemblyProductAttribute("Rosalia"),
                        _ => new AssemblyVersionAttribute(version),
                        _ => new AssemblyFileVersionAttribute(version)
                    }
                }.AsExecutable());

            /* ======================================================================================== */

            var buildSolution = Task(
                "Build solution",
                from data in solutionTreeTask
                select new MsBuildTask
                {
                    ProjectFile = data.SolutionFile,
                    Switches =
                    {
                        MsBuildSwitch.Configuration(data.Configuration)
                    }
                }.AsExecutable(),
                DependsOn(generateAssemblyInfoTask));

            /* ======================================================================================== */
            
            var clearArtifacts = Task(
                "Clear artifacts",
                from data in solutionTreeTask
                select _ =>
                {
                    data.Artifacts.Files.IncludeByExtension("nupkg", "nuspec").DeleteAll();
                });

            /* ======================================================================================== */
            var nuspecCore = Task(
                "nuspecCore",
                
                from data in solutionTreeTask
                from version in solutionVersionTask
                select new GenerateNuGetSpecTask(data.NuSpecRosaliaCore)
                    .Id("Rosalia.Core")
                    .FillCommonProperties(version)
                    .Description("Core libs for Rosalia framework.")
                    .WithFiles(data.GetCoreLibFiles(), "lib")
                    .AsExecutable(),
                    
                DependsOn(buildSolution),
                DependsOn(clearArtifacts));

            /* ======================================================================================== */
            
            var nuspecRosaliaExe = Task(
                "nuspecRosaliaExe",

                from data in solutionTreeTask
                from version in solutionVersionTask
                select new GenerateNuGetSpecTask(data.NuSpecRosalia)
                    .Id("Rosalia")
                    .FillCommonProperties(version)
                    .Description("Automation tool that allows writing build, install or other workflows in C#. This package automatically integrates Rosalia to your Class Library project.")
                    .WithFile(data.RosaliaPackageInstallScript, "tools")
                    .WithFile(data.RosaliaRunnerConsoleExe, "tools")
                    .WithFiles(data.GetRunnerDllFiles(), "tools")
                    .WithFiles(data.BuildAssets.Files.IncludeByExtension(".pp"), "content")
                    .WithDependency("Rosalia.Core", version)
                    .WithDependency("NuGetPowerTools", version: "0.29")
                    .AsExecutable(),
                    
                DependsOn(nuspecCore));

            /* ======================================================================================== */
            ITaskFuture<Nothing> nuspecTaskLibs = Task(
                "nuspecTaskLibs",
                from data in solutionTreeTask
                from version in solutionVersionTask
                select ForEach(data.FindTaskLibDirectories()).Do(tasklibDir =>
                {
                    var libCode = tasklibDir.Name.Replace("Rosalia.TaskLib.", string.Empty);
                    var taskLibNuspec = string.Format("Rosalia.TaskLib.{0}.nuspec", libCode);

                    return new GenerateNuGetSpecTask(data.Artifacts[taskLibNuspec])
                        .FillCommonProperties(version)
                        .FillTaskLibProperties(data, version, libCode);
                }),
                
                DependsOn(nuspecRosaliaExe));

//            /* ======================================================================================== */
//            Register(
//                name: "Generate NuGet packages",
//                task: ForEach(
//                    () => Data.Artifacts.Files.IncludeByExtension(".nuspec"),
//                    file => Register(
//                        name: "Generate nuget package " + file.Name,
//                        task: new GeneratePackageTask
//                        {
//                            SpecFile = file
//                        })));
//
//            /* ======================================================================================== */
//            Register(
//                name: "Genarate docs",
//                task: new BuildDocsTask(),
//                beforeExecute: task => task.SourceDirectory = Data.Src);
//
//            /* ======================================================================================== */
//            Register(
//                name: "Push documentation to GhPages",
//                task: new PrepareDocsForDeploymentTask(),
//                beforeExecute: task =>
//                {
//                    if (!Context.WorkDirectory.GetFile("private_data.yaml").Exists)
//                    {
//                        Result.AddWarning("No private data yaml file. Skip docs deployment.");
//                        Result.Succeed();
//                    }
//                });
        }
    }
}<commit_msg>Changed: build process (generating nuget packages).<commit_after>﻿namespace Rosalia.Build
{
    using System.Reflection;
    using Rosalia.Build.Helpers;
    using Rosalia.Core.Api;
    using Rosalia.Core.Tasks.Futures;
    using Rosalia.Core.Tasks.Results;
    using Rosalia.TaskLib.AssemblyInfo;
    using Rosalia.TaskLib.Git.Tasks;
    using Rosalia.TaskLib.MsBuild;
    using Rosalia.TaskLib.NuGet.Tasks;

    public class BuildWorkflow : Workflow
    {
        protected override void RegisterTasks()
        {
            /* ======================================================================================== */
            var solutionTreeTask = Task(
                "Initialize context",
                context =>
                {
                    var projectRoot = context.WorkDirectory.Parent.Parent;
                    var src = projectRoot.GetDirectory("Src");

                    return new BuildData
                    {
                        Configuration = "Debug",
                        ProjectRootDirectory = projectRoot,
                        Src = src,
                        SolutionFile = src.GetFile("Rosalia.sln"),
                        Artifacts = projectRoot.GetDirectory("Artifacts")
                    }.AsTaskResult();
                });

            /* ======================================================================================== */
            
            var gitVersionTask = Task(
                "gitVersion",
                new GetVersionTask());

            /* ======================================================================================== */

            var solutionVersionTask = Task(
                "solutionVersion",
                from value in gitVersionTask
                select (value.Tag.Replace("v", string.Empty) + "." + value.CommitsCount).AsTaskResult());

            /* ======================================================================================== */

            ITaskFuture<Nothing> generateAssemblyInfoTask = Task(
                "Generate common assembly info file",
                
                from version in solutionVersionTask
                from data in solutionTreeTask
                select new GenerateAssemblyInfo(data.Src["CommonAssemblyInfo.cs"])
                {
                    Attributes =
                    {
                        _ => new AssemblyProductAttribute("Rosalia"),
                        _ => new AssemblyVersionAttribute(version),
                        _ => new AssemblyFileVersionAttribute(version)
                    }
                }.AsExecutable());

            /* ======================================================================================== */

            var buildSolution = Task(
                "Build solution",
                from data in solutionTreeTask
                select new MsBuildTask
                {
                    ProjectFile = data.SolutionFile,
                    Switches =
                    {
                        MsBuildSwitch.Configuration(data.Configuration)
                    }
                }.AsExecutable(),
                DependsOn(generateAssemblyInfoTask));

            /* ======================================================================================== */
            
            var clearArtifacts = Task(
                "Clear artifacts",
                from data in solutionTreeTask
                select _ =>
                {
                    data.Artifacts.Files.IncludeByExtension("nupkg", "nuspec").DeleteAll();
                });

            /* ======================================================================================== */
            var nuspecCore = Task(
                "nuspecCore",
                
                from data in solutionTreeTask
                from version in solutionVersionTask
                select new GenerateNuGetSpecTask(data.NuSpecRosaliaCore)
                    .Id("Rosalia.Core")
                    .FillCommonProperties(version)
                    .Description("Core libs for Rosalia framework.")
                    .WithFiles(data.GetCoreLibFiles(), "lib")
                    .AsExecutable(),
                    
                DependsOn(buildSolution),
                DependsOn(clearArtifacts));

            /* ======================================================================================== */
            
            var nuspecRosaliaExe = Task(
                "nuspecRosaliaExe",

                from data in solutionTreeTask
                from version in solutionVersionTask
                select new GenerateNuGetSpecTask(data.NuSpecRosalia)
                    .Id("Rosalia")
                    .FillCommonProperties(version)
                    .Description("Automation tool that allows writing build, install or other workflows in C#. This package automatically integrates Rosalia to your Class Library project.")
                    .WithFile(data.RosaliaPackageInstallScript, "tools")
                    .WithFile(data.RosaliaRunnerConsoleExe, "tools")
                    .WithFiles(data.GetRunnerDllFiles(), "tools")
                    .WithFiles(data.BuildAssets.Files.IncludeByExtension(".pp"), "content")
                    .WithDependency("Rosalia.Core", version)
                    .WithDependency("NuGetPowerTools", version: "0.29")
                    .AsExecutable(),
                    
                DependsOn(nuspecCore));

            /* ======================================================================================== */
            ITaskFuture<Nothing> nuspecTaskLibs = Task(
                "nuspecTaskLibs",
                from data in solutionTreeTask
                from version in solutionVersionTask
                select ForEach(data.FindTaskLibDirectories()).Do(tasklibDir =>
                {
                    var libCode = tasklibDir.Name.Replace("Rosalia.TaskLib.", string.Empty);
                    var taskLibNuspec = string.Format("Rosalia.TaskLib.{0}.nuspec", libCode);

                    return new GenerateNuGetSpecTask(data.Artifacts[taskLibNuspec])
                        .FillCommonProperties(version)
                        .FillTaskLibProperties(data, version, libCode);
                }),
                
                DependsOn(nuspecRosaliaExe));

            /* ======================================================================================== */

            Task(
                "Generate NuGet packages",
                from data in solutionTreeTask
                select ForEach(data.Artifacts.Files.IncludeByExtension(".nuspec")).Do(file => new GeneratePackageTask(file)),
                
                Default(),

                DependsOn(nuspecCore),
                DependsOn(nuspecRosaliaExe),
                DependsOn(nuspecTaskLibs));

//            /* ======================================================================================== */
//            Register(
//                name: "Genarate docs",
//                task: new BuildDocsTask(),
//                beforeExecute: task => task.SourceDirectory = Data.Src);
//
//            /* ======================================================================================== */
//            Register(
//                name: "Push documentation to GhPages",
//                task: new PrepareDocsForDeploymentTask(),
//                beforeExecute: task =>
//                {
//                    if (!Context.WorkDirectory.GetFile("private_data.yaml").Exists)
//                    {
//                        Result.AddWarning("No private data yaml file. Skip docs deployment.");
//                        Result.Succeed();
//                    }
//                });
        }
    }
}
{'fraction_non_alphanumeric': 0.21253196930946291, 'fraction_numerical': 0.0005115089514066496, 'mean_word_length': 1.5461500895328015, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4312803', 'n_tokens_mistral': 3441, 'n_tokens_neox': 2995, 'n_words': 587}