<commit_before>#region Build

Task("Clean")
    .Does<BuildParameters>((parameters) =>
{
    Information("Cleaning directories..");

    CleanDirectories("./src/**/bin/" + parameters.Configuration);
    CleanDirectories("./src/**/obj");
    CleanDirectories("./src/GitVersionVsixTask/scripts/**");

    DeleteFiles("src/GitVersionVsixTask/*.vsix");
    DeleteFiles("src/GitVersionRubyGem/*.gem");

    CleanDirectories(parameters.Paths.Directories.ToClean);
});

Task("Build")
    .IsDependentOn("Clean")
    .Does<BuildParameters>((parameters) =>
{
    // build .Net code
    Build(parameters.Configuration);

    var workDir = "./src/GitVersionVsixTask";
    // build typescript code
    NpmSet(new NpmSetSettings             { WorkingDirectory = workDir, LogLevel = NpmLogLevel.Silent, Key = "progress", Value = "false" });
    NpmInstall(new NpmInstallSettings     { WorkingDirectory = workDir, LogLevel = NpmLogLevel.Silent });
    NpmRunScript(new NpmRunScriptSettings { WorkingDirectory = workDir, LogLevel = NpmLogLevel.Silent, ScriptName = "build" });
});

#endregion

#region Tests

Task("Test")
    .WithCriteria<BuildParameters>((context, parameters) => parameters.EnabledUnitTests, "Unit tests were disabled.")
    .IsDependentOn("Build")
    .Does<BuildParameters>((parameters) =>
{
    var frameworks = new[] { parameters.CoreFxVersion, parameters.FullFxVersion };
    var testResultsPath = parameters.Paths.Directories.TestResultsOutput;

    foreach(var framework in frameworks)
    {
        // run using dotnet test
        var actions = new List<Action>();
        var projects = GetFiles("./src/**/*.Tests.csproj");
        foreach(var project in projects)
        {
            actions.Add(() =>
            {
                var projectName = $"{project.GetFilenameWithoutExtension()}.{framework}";
                var settings = new DotNetCoreTestSettings {
                    Framework = framework,
                    NoBuild = true,
                    NoRestore = true,
                    Configuration = parameters.Configuration,
                };

                if (!parameters.IsRunningOnMacOS) {
                    settings.TestAdapterPath = new DirectoryPath(".");
                    var resultsPath = MakeAbsolute(new FilePath($"{testResultsPath}/{projectName}.results.xml"));
                    settings.Logger = $"nunit;LogFilePath={resultsPath}";
                }

                var coverletSettings = new CoverletSettings {
                    CollectCoverage = true,
                    CoverletOutputFormat = CoverletOutputFormat.opencover,
                    CoverletOutputDirectory = testResultsPath,
                    CoverletOutputName = $"{projectName}.coverage.xml"
                };

                if (IsRunningOnUnix() && string.Equals(framework, parameters.FullFxVersion))
                {
                    settings.Filter = "TestCategory!=NoMono";
                }

                DotNetCoreTest(project.FullPath, settings, coverletSettings);
            });
        }

        var options = new ParallelOptions
        {
            MaxDegreeOfParallelism = -1,
            CancellationToken = default
        };

        Parallel.Invoke(options, actions.ToArray());
    }

    var workDir = "./src/GitVersionVsixTask";
    var npmSettings = new NpmRunScriptSettings { WorkingDirectory = workDir, LogLevel = NpmLogLevel.Silent, ScriptName = "test" };
    var vsixResultsPath = MakeAbsolute(new FilePath($"{testResultsPath}/vsix.results.xml"));
    npmSettings.Arguments.Add($"--reporter-options mochaFile={vsixResultsPath}");
    NpmRunScript(npmSettings);
})
.ReportError(exception =>
{
    var error = (exception as AggregateException).InnerExceptions[0];
    Error(error.Dump());
})
.Finally(() =>
{
    var parameters = Context.Data.Get<BuildParameters>();
    var testResultsFiles = GetFiles(parameters.Paths.Directories.TestResultsOutput + "/*.results.xml");
    if (parameters.IsRunningOnAzurePipeline)
    {
        if (testResultsFiles.Any()) {
            var data = new TFBuildPublishTestResultsData {
                TestResultsFiles = testResultsFiles.ToArray(),
                TestRunner = TFTestRunnerType.NUnit
            };
            TFBuild.Commands.PublishTestResults(data);
        }<commit_msg>(vsix) add unit tests support for Vsix, code review changes<commit_after>#region Build

Task("Clean")
    .Does<BuildParameters>((parameters) =>
{
    Information("Cleaning directories..");

    CleanDirectories("./src/**/bin/" + parameters.Configuration);
    CleanDirectories("./src/**/obj");
    CleanDirectories("./src/GitVersionVsixTask/scripts/**");

    DeleteFiles("src/GitVersionVsixTask/*.vsix");
    DeleteFiles("src/GitVersionRubyGem/*.gem");

    CleanDirectories(parameters.Paths.Directories.ToClean);
});

Task("Build")
    .IsDependentOn("Clean")
    .Does<BuildParameters>((parameters) =>
{
    // build .Net code
    Build(parameters.Configuration);

    var workDir = "./src/GitVersionVsixTask";
    // build typescript code
    NpmSet(new NpmSetSettings             { WorkingDirectory = workDir, LogLevel = NpmLogLevel.Silent, Key = "progress", Value = "false" });
    NpmInstall(new NpmInstallSettings     { WorkingDirectory = workDir, LogLevel = NpmLogLevel.Silent });
    NpmRunScript(new NpmRunScriptSettings { WorkingDirectory = workDir, LogLevel = NpmLogLevel.Silent, ScriptName = "build" });
});

#endregion

#region Tests

Task("Test")
    .WithCriteria<BuildParameters>((context, parameters) => parameters.EnabledUnitTests, "Unit tests were disabled.")
    .IsDependentOn("Build")
    .Does<BuildParameters>((parameters) =>
{
    var frameworks = new[] { parameters.CoreFxVersion, parameters.FullFxVersion };
    var testResultsPath = parameters.Paths.Directories.TestResultsOutput;

    foreach(var framework in frameworks)
    {
        // run using dotnet test
        var actions = new List<Action>();
        var projects = GetFiles("./src/**/*.Tests.csproj");
        foreach(var project in projects)
        {
            actions.Add(() =>
            {
                var projectName = $"{project.GetFilenameWithoutExtension()}.{framework}";
                var settings = new DotNetCoreTestSettings {
                    Framework = framework,
                    NoBuild = true,
                    NoRestore = true,
                    Configuration = parameters.Configuration,
                };

                if (!parameters.IsRunningOnMacOS) {
                    settings.TestAdapterPath = new DirectoryPath(".");
                    var resultsPath = MakeAbsolute(testResultsPath.CombineWithFilePath($"{projectName}.results.xml"));
                    settings.Logger = $"nunit;LogFilePath={resultsPath}";
                }

                var coverletSettings = new CoverletSettings {
                    CollectCoverage = true,
                    CoverletOutputFormat = CoverletOutputFormat.opencover,
                    CoverletOutputDirectory = testResultsPath,
                    CoverletOutputName = $"{projectName}.coverage.xml"
                };

                if (IsRunningOnUnix() && string.Equals(framework, parameters.FullFxVersion))
                {
                    settings.Filter = "TestCategory!=NoMono";
                }

                DotNetCoreTest(project.FullPath, settings, coverletSettings);
            });
        }

        var options = new ParallelOptions
        {
            MaxDegreeOfParallelism = -1,
            CancellationToken = default
        };

        Parallel.Invoke(options, actions.ToArray());
    }

    var workDir = "./src/GitVersionVsixTask";
    var npmSettings = new NpmRunScriptSettings { WorkingDirectory = workDir, LogLevel = NpmLogLevel.Silent, ScriptName = "test" };
    var vsixResultsPath = MakeAbsolute(testResultsPath.CombineWithFilePath("vsix.results.xml"));
    npmSettings.Arguments.Add($"--reporter-options mochaFile={vsixResultsPath}");
    NpmRunScript(npmSettings);
})
.ReportError(exception =>
{
    var error = (exception as AggregateException).InnerExceptions[0];
    Error(error.Dump());
})
.Finally(() =>
{
    var parameters = Context.Data.Get<BuildParameters>();
    var testResultsFiles = GetFiles(parameters.Paths.Directories.TestResultsOutput + "/*.results.xml");
    if (parameters.IsRunningOnAzurePipeline)
    {
        if (testResultsFiles.Any()) {
            var data = new TFBuildPublishTestResultsData {
                TestResultsFiles = testResultsFiles.ToArray(),
                TestRunner = TFTestRunnerType.NUnit
            };
            TFBuild.Commands.PublishTestResults(data);
        }
{'fraction_non_alphanumeric': 0.11757898391389886, 'fraction_numerical': 0.0004629093854877908, 'mean_word_length': 2.533115290269828, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, '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': '2172287', 'n_tokens_mistral': 2343, 'n_tokens_neox': 2233, 'n_words': 399}