Пример #1
0
        private static string GetXunitRunner(string nuget, BuildPlan buildPlan)
        {
            var xunitRunnerFolder = Path.Combine(buildPlan.Root, buildPlan.BuildToolsFolder, "xunit.runner.console");

            if (!Directory.Exists(xunitRunnerFolder))
            {
                var argument = $"install xunit.runner.console -ExcludeVersion -o {Path.Combine(buildPlan.Root, buildPlan.BuildToolsFolder)} -nocache -pre -Source https://api.nuget.org/v3/index.json";
                ProcessStartInfo startInfo;
                if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows)
                {
                    startInfo = new ProcessStartInfo(nuget, argument);
                }
                else
                {
                    startInfo = new ProcessStartInfo("mono", $"{nuget} {argument}");
                }

                var process = Process.Start(startInfo);
                if (!process.WaitForExit((int)TimeSpan.FromMinutes(5).TotalMilliseconds))
                {
                    throw new InvalidOperationException($"Downloading NuGet.exe timeout");
                }
            }

            return(Path.Combine(xunitRunnerFolder, "tools"));
        }
Пример #2
0
        private static void RunTestProject(string project,
                                           string[] frameworks,
                                           BuildPlan buildPlan,
                                           DotNetExecutor dotnet,
                                           string xunitTools,
                                           List <string> failures)
        {
            var testFolder = Path.Combine(buildPlan.Root, "tests", project);

            if (dotnet.Build(testFolder) != 0)
            {
                failures.Add($"Test build failed: {project}");
            }

            foreach (var framework in frameworks)
            {
                if (framework == "dnx451")
                {
                    if (!RunTestProjectForFullCLR(testFolder, project, xunitTools))
                    {
                        failures.Add($"Test failed: {project} / {framework}");
                    }
                }
                else
                {
                    if (dotnet.Test(testFolder) != 0)
                    {
                        failures.Add($"Test failed: {project} / {framework}");
                    }
                }
            }
        }
Пример #3
0
        public static bool RunTests(BuildPlan buildPlan)
        {
            var xunitTools = PrepareTools(buildPlan);
            var dotnet     = new DotNetExecutor(buildPlan);
            var failures   = new List <string>();

            dotnet.Restore(Path.Combine(buildPlan.Root, "src"));
            dotnet.Restore(Path.Combine(buildPlan.Root, "tests"));

            foreach (var pair in buildPlan.TestProjects)
            {
                RunTestProject(pair.Key, pair.Value, buildPlan, dotnet, xunitTools, failures);
            }

            if (failures.Any())
            {
                foreach (var f in failures)
                {
                    Console.Error.WriteLine(f);
                }

                return(false);
            }
            else
            {
                return(true);
            }
        }
Пример #4
0
        private static void RunTestProject(string project,
                                           string[] frameworks,
                                           BuildPlan buildPlan,
                                           DotNetExecutor dotnet,
                                           string xunitTools,
                                           List<string> failures)
        {
            var testFolder = Path.Combine(buildPlan.Root, "tests", project);

            if (dotnet.Build(testFolder) != 0)
            {
                failures.Add($"Test build failed: {project}");
            }

            foreach (var framework in frameworks)
            {
                if (framework == "dnx451")
                {
                    if (!RunTestProjectForFullCLR(testFolder, project, xunitTools))
                    {
                        failures.Add($"Test failed: {project} / {framework}");
                    }
                }
                else
                {
                    if (dotnet.Test(testFolder) != 0)
                    {
                        failures.Add($"Test failed: {project} / {framework}");
                    }
                }
            }
        }
Пример #5
0
        public static bool RunTests(BuildPlan buildPlan)
        {
            var xunitTools = PrepareTools(buildPlan);
            var dotnet = new DotNetExecutor(buildPlan);
            var failures = new List<string>();
            
            dotnet.Restore(Path.Combine(buildPlan.Root, "src"));
            dotnet.Restore(Path.Combine(buildPlan.Root, "tests"));

            foreach (var pair in buildPlan.TestProjects)
            {
                RunTestProject(pair.Key, pair.Value, buildPlan, dotnet, xunitTools, failures);
            }

            if (failures.Any())
            {
                foreach (var f in failures)
                {
                    Console.Error.WriteLine(f);
                }
                
                return false;
            }
            else
            {
                return true;
            }
        }
Пример #6
0
        private static string GetNuGet(BuildPlan buildPlan)
        {
            string nugetCache;
            string home;

            switch (PlatformServices.Default.Runtime.OperatingSystemPlatform)
            {
            case Platform.Windows:
                nugetCache = Path.Combine(Environment.GetEnvironmentVariable("LocalAppData"), "NuGet");
                break;

            case Platform.Darwin:
                home       = Environment.GetEnvironmentVariable("HOME");
                nugetCache = Path.Combine(home, "Library", "Caches", "OmniSharpBuild");
                break;

            default:
                home = Environment.GetEnvironmentVariable("XDG_DATA_HOME");
                if (string.IsNullOrEmpty(home))
                {
                    home       = Environment.GetEnvironmentVariable("HOME");
                    nugetCache = Path.Combine(home, ".local", "share");
                }
                else
                {
                    nugetCache = home;
                }
                break;
            }

            if (!Directory.Exists(nugetCache))
            {
                Directory.CreateDirectory(nugetCache);
            }

            nugetCache = Path.Combine(nugetCache, NuGetCacheFileName);

            if (!File.Exists(nugetCache))
            {
                var client   = new HttpClient();
                var response = client.GetAsync("https://dist.nuget.org/win-x86-commandline/latest/nuget.exe").Result;
                using (var fs = File.Create(nugetCache))
                {
                    response.Content.CopyToAsync(fs).Wait();
                }
            }

            var result = Path.Combine(buildPlan.BuildToolsFolder, "nuget.exe");

            File.Copy(nugetCache, result, overwrite: true);

            return(result);
        }
Пример #7
0
        public DotNetExecutor(BuildPlan plan)
        {
            if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows)
            {
                _executableName = "dotnet.exe";
            }
            else
            {
                _executableName = "dotnet";
            }

            if (Directory.Exists(Path.Combine(plan.Root, plan.DotNetFolder)))
            {
                _executablePath = Directory.GetFiles(Path.Combine(plan.Root, plan.DotNetFolder), _executableName, SearchOption.AllDirectories)
                                  .First();
            }
            else
            {
                _executablePath = _executableName;
            }
        }
Пример #8
0
        public DotNetExecutor(BuildPlan plan)
        {
            if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows)
            {
                _executableName = "dotnet.exe";
            }
            else
            {
                _executableName = "dotnet";
            }

            if (Directory.Exists(Path.Combine(plan.Root, plan.DotNetFolder)))
            {
                _executablePath = Directory.GetFiles(Path.Combine(plan.Root, plan.DotNetFolder), _executableName, SearchOption.AllDirectories)
                                           .First();
            }
            else
            {
                _executablePath = _executableName;
            }
        }
Пример #9
0
        private static string PrepareTools(BuildPlan buildPlan)
        {
            var nuget = GetNuGet(buildPlan);

            return(GetXunitRunner(nuget, buildPlan));
        }
Пример #10
0
        public static int Main(string[] args)
        {
            Console.WriteLine("Publish project OmniSharp");
            var root      = FindRoot();
            var buildPlan = BuildPlan.Parse(root);

            var projectPath = Path.Combine(root, "src", buildPlan.MainProject);

            if (!Directory.Exists(projectPath))
            {
                Console.WriteLine($"Can't find project {buildPlan.MainProject}");
                return(1);
            }

            var publishOutput = Path.Combine(root, buildPlan.ArtifactsFolder, "publish");

            if (!Directory.Exists(publishOutput))
            {
                Directory.CreateDirectory(publishOutput);
            }

            var packageOutput = Path.Combine(root, buildPlan.ArtifactsFolder, "package");

            if (!Directory.Exists(packageOutput))
            {
                Directory.CreateDirectory(packageOutput);
            }

            var dotnetExecutable = new DotNetExecutor(buildPlan);

            Console.WriteLine($"       root: {root}");
            Console.WriteLine($"    project: {buildPlan.MainProject}");
            Console.WriteLine($"     dotnet: {dotnetExecutable}");
            Console.WriteLine($"     source: {projectPath}");
            Console.WriteLine($"publish out: {publishOutput}");
            Console.WriteLine($"package out: {packageOutput}");
            Console.WriteLine($" frameworks: {string.Join(", ", buildPlan.Frameworks)}");
            Console.WriteLine($"    runtime: {string.Join(", ", buildPlan.Rids)}");

            if (!TestActions.RunTests(buildPlan))
            {
                return(1);
            }

            if (dotnetExecutable.Restore(Path.Combine(root, "src")) != 0)
            {
                Console.Error.WriteLine("Fail to restore projects for {rid}");
                return(1);
            }

            foreach (var rid in buildPlan.Rids)
            {
                foreach (var framework in buildPlan.Frameworks)
                {
                    var publish = Path.Combine(publishOutput, buildPlan.MainProject, rid, framework);
                    if (dotnetExecutable.Publish(publish, projectPath, rid, framework) != 0)
                    {
                        Console.Error.WriteLine($"Fail to publish {projectPath} on {framework} for {rid}");
                        return(1);
                    }

                    Package(publish, packageOutput, buildPlan.MainProject, rid, framework);
                }
            }

            return(0);
        }
Пример #11
0
        private static string GetNuGet(BuildPlan buildPlan)
        {
            string nugetCache;
            string home;
            switch (PlatformServices.Default.Runtime.OperatingSystemPlatform)
            {
                case Platform.Windows:
                    nugetCache = Path.Combine(Environment.GetEnvironmentVariable("LocalAppData"), "NuGet");
                    break;
                case Platform.Darwin:
                    home = Environment.GetEnvironmentVariable("HOME");
                    nugetCache = Path.Combine(home, "Library", "Caches", "OmniSharpBuild");
                    break;
                default:
                    home = Environment.GetEnvironmentVariable("XDG_DATA_HOME");
                    if (string.IsNullOrEmpty(home))
                    {
                        home = Environment.GetEnvironmentVariable("HOME");
                        nugetCache = Path.Combine(home, ".local", "share");
                    }
                    else
                    {
                        nugetCache = home;
                    }
                    break;
            }

            if (!Directory.Exists(nugetCache))
            {
                Directory.CreateDirectory(nugetCache);
            }

            nugetCache = Path.Combine(nugetCache, NuGetCacheFileName);

            if (!File.Exists(nugetCache))
            {
                var client = new HttpClient();
                var response = client.GetAsync("https://dist.nuget.org/win-x86-commandline/latest/nuget.exe").Result;
                using (var fs = File.Create(nugetCache))
                {
                    response.Content.CopyToAsync(fs).Wait();
                }
            }

            var result = Path.Combine(buildPlan.BuildToolsFolder, "nuget.exe");
            File.Copy(nugetCache, result, overwrite: true);

            return result;
        }
Пример #12
0
        private static string GetXunitRunner(string nuget, BuildPlan buildPlan)
        {
            var xunitRunnerFolder = Path.Combine(buildPlan.Root, buildPlan.BuildToolsFolder, "xunit.runner.console");
            if (!Directory.Exists(xunitRunnerFolder))
            {
                var argument = $"install xunit.runner.console -ExcludeVersion -o {Path.Combine(buildPlan.Root, buildPlan.BuildToolsFolder)} -nocache -pre -Source https://api.nuget.org/v3/index.json";
                ProcessStartInfo startInfo;
                if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Windows)
                {
                    startInfo = new ProcessStartInfo(nuget, argument);
                }
                else
                {
                    startInfo = new ProcessStartInfo("mono", $"{nuget} {argument}");
                }

                var process = Process.Start(startInfo);
                if (!process.WaitForExit((int)TimeSpan.FromMinutes(5).TotalMilliseconds))
                {
                    throw new InvalidOperationException($"Downloading NuGet.exe timeout");
                }
            }

            return Path.Combine(xunitRunnerFolder, "tools");
        }
Пример #13
0
 private static string PrepareTools(BuildPlan buildPlan)
 {
     var nuget = GetNuGet(buildPlan);
     return GetXunitRunner(nuget, buildPlan);
 }