private async Task <OperationResult <AgentInformation> > RunAgentAsync(StartAgentInformation startAgentInformation, GitRepository agentRepository) { var args = new ShellRunnerArgs(agentRepository.Directory, "docker", false, $"run -p {startAgentInformation.Port}:80 -d agent:latest"); var runAgentResult = await shellRunner.RunAsync(args); if (!runAgentResult.IsSuccessful) { return(OperationResult <AgentInformation> .Failed($"Cannot run container with agent. Error: {runAgentResult.Error}")); } logger.LogInformation(await runAgentResult.Value.Output.ReadToEndAsync()); return(OperationResult <AgentInformation> .Success(new AgentInformation(new Uri($"http://localhost:{startAgentInformation.Port}")))); }
public static void AppendLogger(string loggerPath, IEnumerable <string> componentPaths, ILog log) { var baseDirectory = Path.GetDirectoryName(loggerPath); var loggerName = Path.GetFileName(loggerPath); var extractor = new ShellRunner(new ShellRunnerSettings("jar") { Arguments = $"-xf {loggerName} org", WorkingDirectory = baseDirectory }, log); var updateTasks = componentPaths.Select(x => { var filename = Path.GetFileName(x); var updater = new ShellRunner(new ShellRunnerSettings("jar") { Arguments = $"-uf {filename} org", WorkingDirectory = baseDirectory }, log); return(updater.RunAsync(TimeSpan.FromSeconds(30), CancellationToken.None)); }).ToArray(); extractor.Run(TimeSpan.FromSeconds(30), CancellationToken.None); Task.WaitAll(updateTasks); }
public async Task <OperationResult <GitRepository> > CloneAsync(CancellationToken cancellationToken = default) { using var scope = logger.BeginScope("Clone"); var arguments = new List <string> { "clone", GetUrlWithAccessToken(), gitProjectInformation.TargetDirectory, "--verbose" }; if (gitProjectInformation.CloneRecursive) { arguments.Add("--recursive"); } var processRunArgs = new ShellRunnerArgs(gitProjectInformation.WorkingDirectory, "git", false, arguments.ToArray()); var cloneProcessResult = await shellRunner.RunAsync(processRunArgs, cancellationToken); if (!cloneProcessResult.IsSuccessful) { return(OperationResult <GitRepository> .Failed(cloneProcessResult.Error)); } logger.LogInformation(await cloneProcessResult.Value.Error.ReadToEndAsync()); logger.LogInformation(await cloneProcessResult.Value.Output.ReadToEndAsync()); var repositoryDirectory = Path.Combine(gitProjectInformation.WorkingDirectory, gitProjectInformation.TargetDirectory); return(OperationResult <GitRepository> .Success(new GitRepository(shellRunner, repositoryDirectory, loggerFactory.CreateLogger <GitRepository>()))); }
public async Task <VoidOperationResult> CheckoutAsync(string branch) { using var scope = logger.BeginScope("Checkout"); var shellRunnerArgs = new ShellRunnerArgs(Directory, "git", false, "checkout", branch); var checkoutProcessResult = await shellRunner.RunAsync(shellRunnerArgs); if (!checkoutProcessResult.IsSuccessful) { return(VoidOperationResult.Failed(checkoutProcessResult.Error)); } logger.LogInformation(await checkoutProcessResult.Value.Error.ReadToEndAsync()); return(VoidOperationResult.Success()); }
public void Run_should_work() { var runner = new ShellRunner( new ShellRunnerSettings("ping") { Arguments = "google.com -n 2" }, new SynchronousConsoleLog()); runner.RunAsync(5.Seconds(), CancellationToken.None) .Wait(5.Seconds()).Should().BeTrue(); }
public void Run_should_stop_after_timeout() { var runner = new ShellRunner( new ShellRunnerSettings("ping") { Arguments = "google.com -n 100" }, new SynchronousConsoleLog()); runner.RunAsync(5.Seconds(), CancellationToken.None) .ContinueWith(_ => {}) .Wait(10.Seconds()).Should().BeTrue(); }