예제 #1
0
        public static string BuildSamplePackage(string name, string version, bool modifyPackage = false)
        {
            var packageDirectory = TestEnvironment.GetTestPath("Fixtures", "Deployment", "Packages", name);

            Assert.That(Directory.Exists(packageDirectory), string.Format("Package {0} is not available (expected at {1}).", name, packageDirectory));

#if NETFX
            var nugetCommandLine = TestEnvironment.GetTestPath("NuGet", "NuGet.exe");
            Assert.That(File.Exists(nugetCommandLine), string.Format("NuGet.exe is not available (expected at {0}).", nugetCommandLine));

            var target = Path.Combine(packageDirectory, name + ".nuspec");
            Assert.That(File.Exists(target), string.Format("Nuspec for {0} is not available (expected at {1}.", name, target));
#else
            var nugetCommandLine = "dotnet";

            var target = packageDirectory;
            Assert.That(Directory.Exists(target), string.Format("Project for {0} is not available (expected at {1}.", name, target));
#endif

            var output = Path.Combine(Path.GetTempPath(), "CalamariTestPackages");
            Directory.CreateDirectory(output);
            var path = Path.Combine(output, name + "." + version + ".nupkg");
            if (File.Exists(path))
            {
                File.Delete(path);
            }


            var runner = new CommandLineRunner(new ConsoleCommandOutput());
#if NETCORE
            var restoreResult = runner.Execute(new CommandLine(nugetCommandLine)
                                               .Action("restore")
                                               .Argument(target)
                                               .Build());
            restoreResult.VerifySuccess();
#endif

            var result = runner.Execute(new CommandLine(nugetCommandLine)
                                        .Action("pack")
                                        .Argument(target)
#if NETFX
                                        .Argument("Version", version)
                                        .Flag("NoPackageAnalysis")
                                        .Argument("OutputDirectory", output)
#else
                                        .Argument("-output", output)
                                        .PositionalArgument("/p:Version=" + version)
#endif
                                        .Build());
            result.VerifySuccess();

            Assert.That(File.Exists(path), string.Format("The generated nupkg was unable to be found (expected at {0}).", path));
            return(path);
        }
예제 #2
0
 protected CalamariResult Invoke(CommandLine command, VariableDictionary variables)
 {
     var capture = new CaptureCommandOutput();
     var runner = new CommandLineRunner(new SplitCommandOutput(new ConsoleCommandOutput(), new ServiceMessageCommandOutput(variables), capture));
     var result = runner.Execute(command.Build());
     return new CalamariResult(result.ExitCode, capture);
 }
        static Maybe <Version> GetPython3Version()
        {
            var executable = PythonBootstrapper.FindPythonExecutable();
            var command    = new CommandLine(executable).Argument("--version");
            var capture    = new CaptureCommandOutput();
            var runner     = new CommandLineRunner(
                new SplitCommandOutput(
                    new ConsoleCommandOutput(),
                    new ServiceMessageCommandOutput(new VariableDictionary()),
                    capture));
            var result = runner.Execute(command.Build());

            if (result.ExitCode != 0)
            {
                return(Maybe <Version> .None);
            }

            var allCapturedMessages = capture.AllMessages.Aggregate((a, b) => $"{a}, {b}");
            var pythonVersionMatch  = PythonVersionFinder.Match(allCapturedMessages);

            if (!pythonVersionMatch.Success)
            {
                return(Maybe <Version> .None);
            }

            var major = pythonVersionMatch.Groups[1].Value;
            var minor = pythonVersionMatch.Groups[2].Value;

            return(new Version(int.Parse(major), int.Parse(minor)).AsSome());
        }
예제 #4
0
 private static async Task Main(string[] args)
 {
     var runner = new CommandLineRunner <Program>(options =>
     {
         options
         .SetTitle("Tool to generate some fake reports");
     });
     await runner.Execute();
 }
예제 #5
0
 private static async Task Main(string[] args)
 {
     var runner = new CommandLineRunner <Program>(options =>
     {
         options
         .SetTitle("CMD to add new user");
     });
     await runner.Execute();
 }
        public void SetUp()
        {
            CommandLineRunner clr = new CommandLineRunner(new IgnoreCommandOutput());
            var result            = clr.Execute(new CommandLineInvocation("pwsh", "--version"));

            if (result.HasErrors)
            {
                Assert.Inconclusive("PowerShell Core is not installed on this machine");
            }
        }
        public void ScriptShouldFailIfExecutableDoesNotExist()
        {
            const string executable = "TestingCalamariThisExecutableShouldNeverExist";
            var          output     = new CaptureCommandOutput();
            var          subject    = new CommandLineRunner(output);
            var          result     = subject.Execute(new CommandLineInvocation(executable: executable, arguments: "--version"));

            result.HasErrors.Should().BeTrue();
            output.Errors.Should().Contain(CommandLineRunner.ConstructWin32ExceptionMessage(executable));
        }
예제 #8
0
        private void DeployTestSite(string sampleName, string framework)
        {
            var runner = new CommandLineRunner()
            {
                Timeout = TimeSpan.FromMinutes(5)
            };

            _testsitesource = Path.GetTempFileName();
            File.Delete(_testsitesource);
            Directory.CreateDirectory(_testsitesource);

            var sourcePath = PathHelper.GetTestAppFolder(sampleName);

            Assert.NotNull(sourcePath);

            runner.Execute($"git clean -xdff .", sourcePath);
            Assert.NotEqual(-1, runner.Execute($"robocopy {sourcePath} {_testsitesource} /E /S /XD node_modules")); // robcopy doesn't return 0
            File.Copy(PathHelper.GetNuGetConfig(), Path.Combine(_testsitesource, "NuGet.config"));

            _log.LogInformation($"Testsite sources are copied to {_testsitesource}.");

            CreateTestSite();

            Assert.Equal(0, runner.Execute("git add -A .", _testsitesource));
            Assert.Equal(0, runner.Execute("git commit -m \"init\"", _testsitesource));

            var giturl = $"https://{_username}:{_password}@{_testsitename}.scm.azurewebsites.net:443/{_testsitename}.git";

            Assert.Equal(0, runner.Execute($"git remote set-url azure {giturl}", _testsitesource));

            _log.LogInformation("Git repository is set up at testsite source folder");

            runner.Timeout = TimeSpan.FromMinutes(15);
            Assert.Equal(0, runner.Execute($"git push azure master", _testsitesource));
        }
        public void SetUp()
        {
            CommandLineRunner clr = new CommandLineRunner(ConsoleLog.Instance, new CalamariVariables());
            var result            = clr.Execute(new CommandLineInvocation("pwsh", "--version")
            {
                OutputToLog = false
            });

            if (result.HasErrors)
            {
                Assert.Inconclusive("PowerShell Core is not installed on this machine");
            }
        }
예제 #10
0
        public void BasicTest(string sampleName, string framework, int concurrency)
        {
            var testname = $"{sampleName}.{framework}.{concurrency}";

            var appsource = PathHelper.GetTestAppFolder(sampleName);

            Assert.NotNull(appsource);

            var powershell = new CommandLineRunner("powershell")
            {
                Timeout = TimeSpan.FromMinutes(5)
            };

            var deployScript    = PathHelper.GetScript("deploy-site.ps1");
            var tempLocation    = Path.Combine(_stagingFolder, testname);
            var deployArguments = $"{deployScript} -server {_server} -appsource {appsource} -username {_username} -password_file {_passwordFile} -framework {framework} -temp {tempLocation}";

            Console.WriteLine(deployArguments);

            var result = powershell.Execute(deployArguments);

            Assert.Equal(0, result);

            // Sleep for 5 seconds to allow the server to start.
            Thread.Sleep(TimeSpan.FromSeconds(5));

            var testScript = PathHelper.GetScript("throughput.ps1");
            var scenario   = PathHelper.GetScript("basic_scenario.wcat");
            var settings   = WriteWcatSettings(scenario, concurrency);
            var output     = Path.Combine(PathHelper.GetArtifactFolder(), testname);

            Directory.CreateDirectory(output);
            var testArguments = $"{testScript} -controller {_wcatControllerName} -clients {_wcatClients} -settings {settings} -scenario {scenario} -username {_username} -password_file {_passwordFile} -output {output}\\";

            Console.WriteLine(testArguments);

            result = powershell.Execute(testArguments);
            Assert.Equal(0, result);
        }
예제 #11
0
        public static string BuildSamplePackage(string name, string version, bool modifyPackage = false)
        {
            var nugetCommandLine = TestEnvironment.GetTestPath("NuGet", "NuGet.exe");

            Assert.That(File.Exists(nugetCommandLine), string.Format("NuGet.exe is not available (expected at {0}).", nugetCommandLine));

            var packageDirectory = TestEnvironment.GetTestPath("Fixtures", "Deployment", "Packages", name);

            Assert.That(Directory.Exists(packageDirectory), string.Format("Package {0} is not available (expected at {1}).", name, packageDirectory));

            var nuspec = Path.Combine(packageDirectory, name + ".nuspec");

            Assert.That(File.Exists(nuspec), string.Format("Nuspec for {0} is not available (expected at {1}.", name, nuspec));

            var output = Path.GetTempPath();
            var path   = Path.Combine(output, name + "." + version + ".nupkg");

            if (File.Exists(path))
            {
                File.Delete(path);
            }

            string indexFilePath = null;

            if (modifyPackage)
            {
                indexFilePath = AddFileToPackage(packageDirectory);
            }

            var runner = new CommandLineRunner(new ConsoleCommandOutput());
            var result = runner.Execute(CommandLine.Execute(nugetCommandLine)
                                        .Action("pack")
                                        .Argument(nuspec)
                                        .Flag("NoPackageAnalysis")
                                        .Argument("Version", version)
                                        .Argument("OutputDirectory", output)
                                        .Build());

            result.VerifySuccess();

            if (modifyPackage &&
                !String.IsNullOrWhiteSpace(indexFilePath) &&
                File.Exists(indexFilePath))
            {
                File.Delete(indexFilePath);
            }

            Assert.That(File.Exists(path), string.Format("The generated nupkg was unable to be found (expected at {0}).", path));
            return(path);
        }
예제 #12
0
        public void SetUp()
        {
            var path = new WindowsPowerShellCoreBootstrapper(new WindowsPhysicalFileSystem()).PathToPowerShellExecutable(new CalamariVariableDictionary());

            if (!File.Exists(path))
            {
                CommandLineRunner clr = new CommandLineRunner(new IgnoreCommandOutput());
                var result            = clr.Execute(new CommandLineInvocation("pwsh.exe", "--version"));
                if (result.HasErrors)
                {
                    Assert.Inconclusive("PowerShell Core is not installed on this machine");
                }
            }
        }
예제 #13
0
        public static string BuildSamplePackage(string name, string version, bool modifyPackage = false)
        {
            var currentDirectory = Path.GetDirectoryName(typeof(PackageBuilder).Assembly.FullLocalPath());

            var packageDirectory = Path.Combine(currentDirectory, "Fixtures\\Deployment\\Packages\\" + name);

            Assert.That(Directory.Exists(packageDirectory), packageDirectory);

            var nuspec = Path.Combine(packageDirectory, name + ".nuspec");

            Assert.That(File.Exists(nuspec));

            var output = Path.GetTempPath();
            var path   = Path.Combine(output, name + "." + version + ".nupkg");

            if (File.Exists(path))
            {
                File.Delete(path);
            }

            string indexFilePath = null;

            if (modifyPackage)
            {
                indexFilePath = AddFileToPackage(packageDirectory);
            }

            var runner = new CommandLineRunner(new ConsoleCommandOutput());
            var result = runner.Execute(CommandLine.Execute(ResolveNuGet(currentDirectory))
                                        .Action("pack")
                                        .Argument(nuspec)
                                        .Flag("NoPackageAnalysis")
                                        .Argument("Version", version)
                                        .Argument("OutputDirectory", output)
                                        .Build());

            result.VerifySuccess();

            if (modifyPackage &&
                !String.IsNullOrWhiteSpace(indexFilePath) &&
                File.Exists(indexFilePath))
            {
                File.Delete(indexFilePath);
            }

            Assert.That(File.Exists(path));
            return(path);
        }
예제 #14
0
        public static AzureCli Create(string workingDirectory)
        {
            var cmdRunner = new CommandLineRunner()
            {
                RedirectOutput = true,
                Timeout        = TimeSpan.FromSeconds(1)
            };

            if (cmdRunner.Execute("where azure") == -1)
            {
                return(null);
            }

            var azureCmd = cmdRunner.LastOutput.Trim(' ', '\n', '\r');

            if (!File.Exists(azureCmd))
            {
                return(null);
            }

            return(new AzureCli(azureCmd, workingDirectory));
        }
예제 #15
0
        CommandResult ExecuteCommandInternal(string arguments, out string result, ICommandOutput output = null)
        {
            var environmentVar = defaultEnvironmentVariables;

            if (environmentVariables != null)
            {
                environmentVar.MergeDictionaries(environmentVariables);
            }

            var commandLineInvocation = new CommandLineInvocation(TerraformExecutable,
                                                                  arguments, TemplateDirectory, environmentVar);

            var commandOutput = new CaptureOutput(output ?? new ConsoleCommandOutput());
            var cmd           = new CommandLineRunner(commandOutput);

            Log.Info(commandLineInvocation.ToString());

            var commandResult = cmd.Execute(commandLineInvocation);

            result = String.Join("\n", commandOutput.Infos);

            return(commandResult);
        }
예제 #16
0
        public static string BuildSamplePackage(string name, string version, bool modifyPackage = false)
        {
            var packageDirectory = TestEnvironment.GetTestPath("Fixtures", "Deployment", "Packages", name);

            Assert.That(Directory.Exists(packageDirectory), string.Format("Package {0} is not available (expected at {1}).", name, packageDirectory));

#if NET40
            var nugetCommandLine = TestEnvironment.GetTestPath("NuGet", "NuGet.exe");
            Assert.That(File.Exists(nugetCommandLine), string.Format("NuGet.exe is not available (expected at {0}).", nugetCommandLine));

            var target = Path.Combine(packageDirectory, name + ".nuspec");
            Assert.That(File.Exists(target), string.Format("Nuspec for {0} is not available (expected at {1}.", name, target));
#else
            var nugetCommandLine = "dotnet";

            var target = Path.Combine(packageDirectory, "project.json");
            Assert.That(File.Exists(target), string.Format("Project.json for {0} is not available (expected at {1}.", name, target));

            var     json    = File.ReadAllText(target);
            dynamic jsonObj = Newtonsoft.Json.JsonConvert.DeserializeObject(json);
            jsonObj["version"] = version;
            json = Newtonsoft.Json.JsonConvert.SerializeObject(jsonObj, Newtonsoft.Json.Formatting.Indented);
            File.WriteAllText(target, json);
#endif

            var output = Path.GetTempPath();
            var path   = Path.Combine(output, name + "." + version + ".nupkg");
            if (File.Exists(path))
            {
                File.Delete(path);
            }

            string indexFilePath = null;
            if (modifyPackage)
            {
                indexFilePath = AddFileToPackage(packageDirectory);
            }

            var runner = new CommandLineRunner(new ConsoleCommandOutput());
            var result = runner.Execute(CommandLine.Execute(nugetCommandLine)
                                        .Action("pack")
                                        .Argument(target)
#if NET40
                                        .Argument("Version", version)
                                        .Flag("NoPackageAnalysis")
                                        .Argument("OutputDirectory", output)
#else
                                        .DoubleDash()
                                        .Argument("version-suffix", version)
                                        .Argument("output", output)
#endif
                                        .Build());
            result.VerifySuccess();

            if (modifyPackage &&
                !String.IsNullOrWhiteSpace(indexFilePath) &&
                File.Exists(indexFilePath))
            {
                File.Delete(indexFilePath);
            }

            Assert.That(File.Exists(path), string.Format("The generated nupkg was unable to be found (expected at {0}).", path));
            return(path);
        }
예제 #17
0
        public override int Execute(string[] commandLineArguments)
        {
            Options.Parse(commandLineArguments);
            string deltaFilePath;
            string newFilePath;
            string basisFilePath;

            ValidateParameters(out basisFilePath, out deltaFilePath, out newFilePath);
            fileSystem.EnsureDiskHasEnoughFreeSpace(packageStore.GetPackagesDirectory());

            var commandLineRunner = new CommandLineRunner(new SplitCommandOutput(new ConsoleCommandOutput(),
                                                                                 new ServiceMessageCommandOutput(new VariableDictionary())));

            var tempNewFilePath = newFilePath + ".partial";
            var executable      = FindOctoDiffExecutable();
            var octoDiff        = CommandLine.Execute(executable)
                                  .Action("patch")
                                  .PositionalArgument(basisFilePath)
                                  .PositionalArgument(deltaFilePath)
                                  .PositionalArgument(tempNewFilePath);

            if (skipVerification)
            {
                octoDiff.Flag("skip-verification");
            }

            if (showProgress)
            {
                octoDiff.Flag("progress");
            }

            Log.Info("Applying delta to {0} with hash {1} and storing as {2}", basisFilePath, fileHash,
                     newFilePath);

            var result = commandLineRunner.Execute(octoDiff.Build());

            if (result.ExitCode != 0)
            {
                fileSystem.DeleteFile(tempNewFilePath, DeletionOptions.TryThreeTimes);
                throw new CommandLineException(executable, result.ExitCode, result.Errors);
            }

            File.Move(tempNewFilePath, newFilePath);

            if (!File.Exists(newFilePath))
            {
                throw new CommandException("Failed to apply delta file " + deltaFilePath + " to " +
                                           basisFilePath);
            }

            var package = packageStore.GetPackage(newFilePath);

            if (package == null)
            {
                return(0);
            }

            using (var file = new FileStream(package.FullPath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                var size = file.Length;
                Log.ServiceMessages.DeltaVerification(package.FullPath, package.Metadata.Hash, size);
            }

            return(0);
        }
예제 #18
0
        public static string GenerateConsoleApplication(string projectName, string destinationFolder)
        {
            var projectPath = Directory.CreateDirectory(Path.Combine(destinationFolder, projectName));

            CommandLineInvocation CreateCommandLineInvocation(string executable, string arguments)
            {
                return(new CommandLineInvocation(executable, arguments)
                {
                    OutputToLog = false,
                    WorkingDirectory = projectPath.FullName
                });
            }

            var clr    = new CommandLineRunner(ConsoleLog.Instance, new CalamariVariables());
            var result = clr.Execute(CreateCommandLineInvocation("dotnet", "new console -f netcoreapp3.1"));

            result.VerifySuccess();
            File.WriteAllText(Path.Combine(projectPath.FullName, "global.json"),
                              @"{
    ""sdk"": {
            ""version"": ""3.1.402"",
            ""rollForward"": ""latestFeature""
        }
    }");
            var programCS  = Path.Combine(projectPath.FullName, "Program.cs");
            var newProgram = $@"using System;
class Program
{{
    static void Main(string[] args)
    {{
        Console.WriteLine($""Hello from my custom {projectName}!"");
        Console.Write(String.Join(Environment.NewLine, args));
    }}
}}";

            var architecture = RuntimeInformation.ProcessArchitecture;
            var rid          = "win-x64";

            if (CalamariEnvironment.IsRunningOnMac)
            {
                rid = "osx-x64";
            }
            else if (CalamariEnvironment.IsRunningOnNix)
            {
                rid = "linux-x64";
            }

            if (architecture == Architecture.Arm)
            {
                rid = "linux-arm";
            }

            if (architecture == Architecture.Arm64)
            {
                rid = "linux-arm64";
            }

            File.WriteAllText(programCS, newProgram);
            var outputPath = Path.Combine(projectPath.FullName, "output");

            result = clr.Execute(CreateCommandLineInvocation("dotnet", $"publish -o {outputPath} -r {rid}"));
            result.VerifySuccess();

            return(outputPath);
        }
예제 #19
0
 public JObject CreateWebSiteGit(string location, string sitename, string siteaccount)
 {
     _runner.Execute($"site create --location \"{location}\" --git --gitusername \"{siteaccount}\" {sitename}", _workingDirectory);
     return(GetWebSiteInformation(sitename));
 }