コード例 #1
0
ファイル: ShellRunner.cs プロジェクト: goverdovskiy/cement
        private int RunThreeTimes(string commandWithArguments, string workingDirectory, TimeSpan timeout, RetryStrategy retryStrategy = RetryStrategy.IfTimeout)
        {
            int exitCode = RunOnce(commandWithArguments, workingDirectory, timeout);
            int times    = 2;

            while (times-- > 0 && NeedRunAgain(retryStrategy, exitCode))
            {
                if (HasTimeout)
                {
                    timeout = TimoutHelper.IncreaceTimeout(timeout);
                }
                exitCode = RunOnce(commandWithArguments, workingDirectory, timeout);
            }
            return(exitCode);
        }
コード例 #2
0
        private int RunThreeTimes(string commandWithArguments, string workingDirectory, TimeSpan timeout, RetryStrategy retryStrategy = RetryStrategy.IfTimeout)
        {
            int exitCode = RunOnce(commandWithArguments, workingDirectory, timeout);
            int times    = 2;

            while (times-- > 0 && NeedRunAgain(retryStrategy, exitCode))
            {
                if (HasTimeout)
                {
                    timeout = TimoutHelper.IncreaceTimeout(timeout);
                }
                exitCode = RunOnce(commandWithArguments, workingDirectory, timeout);
                log.Debug($"EXECUTED {startInfo.FileName} {startInfo.Arguments} in {workingDirectory} with exitCode {exitCode} and retryStrategy {retryStrategy}");
            }
            return(exitCode);
        }
コード例 #3
0
        private int RunThreeTimes(string commandWithArguments, string workingDirectory, TimeSpan timeout)
        {
            int result = RunOnce(commandWithArguments, workingDirectory, timeout);

            if (!HasTimeout)
            {
                return(result);
            }

            timeout = TimoutHelper.IncreaceTimeout(timeout);
            int times = 2;

            while (times-- > 0 && HasTimeout)
            {
                result = RunOnce(commandWithArguments, workingDirectory, timeout);
            }
            return(result);
        }
コード例 #4
0
        private static void UpdateGitPackage(Package package)
        {
            var runner = new ShellRunner(Log);

            var timeout = TimeSpan.FromMinutes(1);

            for (int i = 0; i < 3; i++)
            {
                using (var tempDir = new TempDirectory())
                {
                    if (runner.RunOnce(
                            $"git clone {package.Url} {Path.Combine(tempDir.Path, package.Name)}",
                            Directory.GetCurrentDirectory(),
                            timeout)
                        != 0)
                    {
                        if (runner.HasTimeout && i < 2)
                        {
                            timeout = TimoutHelper.IncreaceTimeout(timeout);
                            continue;
                        }

                        throw new CementException(
                                  $"Failed to update package {package.Name}:\n{runner.Output}\nError message:\n{runner.Errors}\n" +
                                  $"Ensure that command 'git clone {package.Url}' works in cmd");
                    }
                    lock (Helper.PackageLockObject)
                    {
                        if (!Directory.Exists(Helper.GetGlobalCementDirectory()))
                        {
                            Directory.CreateDirectory(Helper.GetGlobalCementDirectory());
                        }
                        File.Copy(Path.Combine(tempDir.Path, package.Name, "modules"),
                                  Helper.GetPackagePath(package.Name), true);
                    }
                    break;
                }
            }
        }
コード例 #5
0
ファイル: GitRepository.cs プロジェクト: Fr1z2r/cement
        public IList <Branch> GetRemoteBranches()
        {
            log.Info($"{"[" + ModuleName + "]",-30}Get remote branches");
            var sw       = Stopwatch.StartNew();
            var exitCode = runner.RunInDirectory(RepoPath, "git ls-remote --heads", TimoutHelper.GetStartTimeout());

            sw.Stop();
            if (sw.Elapsed > TimeSpan.FromSeconds(10))
            {
                log.DebugFormat("{0, -30}Elapsed git ls-remote --heads: [{1}]", "[" + ModuleName + "]", sw.Elapsed);
            }

            if (exitCode != 0)
            {
                throw new GitBranchException(
                          $"Failed to get remote branches in {RepoPath}. Error message:\n{runner.Errors}");
            }

            var branches = runner.Output.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);

            return(branches.Select(s => new Branch(s)).Where(b => b.Name != null).ToList());
        }