Esempio n. 1
0
        private static models.Commit DetermineCommit()
        {
            // e.g.: "4.3.0 (master/[a-f0-9A-F]{7..40})"
            var regex = new Regex("^[0-9].*\\((.*)/([0-9a-f]+)\\)");
            var match = regex.Match(GetMonoVersion());

            string branch, hash;

            if (match.Success)
            {
                branch = match.Groups [1].Value;
                hash   = match.Groups [2].Value;
                Logging.GetLogging().Debug("branch: " + branch + " hash: " + hash);
            }
            else
            {
                branch = "<unknown>";
                hash   = "<unknown>";
                Logging.GetLogging().Debug("couldn't read git information: \"" + GetMonoVersion() + "\"");
            }
            Octokit.Commit gitHubCommit = null;
            try {
                var gitHubClient = GitHubInterface.GitHubClient;
                Octokit.TreeResponse treeResponse = AsyncContext.Run(() => GitHubInterface.RunWithRetry(() => gitHubClient.GitDatabase.Tree.Get("mono", "mono", hash)));
                gitHubCommit = AsyncContext.Run(() => GitHubInterface.RunWithRetry(() => gitHubClient.GitDatabase.Commit.Get("mono", "mono", treeResponse.Sha)));
            } catch (Octokit.NotFoundException e) {
                Logging.GetLogging().Debug("Commit " + hash + " not found on GitHub");
                throw e;
            }
            if (gitHubCommit == null)
            {
                Logging.GetLogging().Debug("Could not get commit " + hash + " from GitHub");
            }
            else
            {
                hash = gitHubCommit.Sha;
                // commit.CommitDate = gitHubCommit.Committer.Date.DateTime;
                Logging.GetLogging().Info("Got commit " + hash + " from GitHub");
            }

            Logging.GetLogging().InfoFormat("Benchmarker | commit \"{0}\" on branch \"{1}\"", hash, branch);
            return(new models.Commit {
                Hash = hash,
                Branch = branch,
                Product = new models.Product {
                    Name = "mono",
                    GitHubUser = "******",
                    GitHubRepo = "mono"
                }
            });
        }
Esempio n. 2
0
        private static async Task <Octokit.Commit> ResolveFullHashViaGithub(Commit commit)
        {
            if (commit == null)
            {
                return(null);
            }

            Octokit.Commit       gitHubCommit = null;
            Octokit.TreeResponse treeResponse = null;
            try {
                var gitHubClient = GitHubInterface.GitHubClient;
                treeResponse = await GitHubInterface.RunWithRetry(() => gitHubClient.GitDatabase.Tree.Get(commit.Product.GitHubUser, commit.Product.GitHubRepo, commit.Hash));

                gitHubCommit = await GitHubInterface.RunWithRetry(() => gitHubClient.GitDatabase.Commit.Get(commit.Product.GitHubUser, commit.Product.GitHubRepo, treeResponse.Sha));
            } catch (Octokit.NotFoundException) {
                Console.WriteLine("Commit " + commit + " not found on GitHub");
            }

            return(gitHubCommit);
        }
Esempio n. 3
0
        public async static Task <bool> CompleteCommit(Config cfg, Commit commit)
        {
            if (commit.Product.Name == "mono" && !cfg.NoMono)
            {
                var binaryProtocolFile = cfg.ProducesBinaryProtocol ? "/tmp/binprot.dummy" : null;
                var info = NewProcessStartInfo(cfg, binaryProtocolFile);
                if (!String.IsNullOrWhiteSpace(info.FileName))
                {
                    /* Run without timing with --version */
                    info.Arguments = "--version";

                    Console.Out.WriteLine("\t$> {0} {1} {2}", PrintableEnvironmentVariables(info), info.FileName, info.Arguments);

                    var process      = Process.Start(info);
                    var version      = Task.Run(() => new StreamReader(process.StandardOutput.BaseStream).ReadToEnd()).Result;
                    var versionError = Task.Run(() => new StreamReader(process.StandardError.BaseStream).ReadToEnd()).Result;

                    process.WaitForExit();
                    process.Close();

                    var line  = version.Split(new char[] { '\n' }, 2) [0];
                    var regex = new Regex("^Mono JIT.*\\((.*)/([0-9a-f]+) (.*)\\)");
                    var match = regex.Match(line);

                    if (match.Success)
                    {
                        commit.Branch = match.Groups [1].Value;
                        var hash = match.Groups [2].Value;
                        if (commit.Hash != null)
                        {
                            if (!commit.Hash.StartsWith(hash))
                            {
                                Console.Error.WriteLine("Error: Commit hash for mono specified on command line does not match the one reported with --version.");
                                return(false);
                            }
                        }
                        else
                        {
                            commit.Hash = hash;
                        }
                        var date = match.Groups [3].Value;
                        Console.WriteLine("branch: " + commit.Branch + " hash: " + commit.Hash + " date: " + date);
                    }
                }

                if (commit.Branch == "(detached")
                {
                    commit.Branch = null;
                }

                try {
                    var gitRepoDir = Path.GetDirectoryName(cfg.Mono);
                    var repo       = new Repository(gitRepoDir);
                    var gitHash    = repo.RevParse(commit.Hash);
                    if (gitHash == null)
                    {
                        Console.WriteLine("Could not get commit " + commit.Hash + " from repository");
                    }
                    else
                    {
                        Console.WriteLine("Got commit " + gitHash + " from repository");

                        if (commit.Hash != null && commit.Hash != gitHash)
                        {
                            Console.Error.WriteLine("Error: Commit hash specified on command line does not match the one from the git repository.");
                            return(false);
                        }

                        commit.Hash          = gitHash;
                        commit.MergeBaseHash = repo.MergeBase(commit.Hash, "master");
                        commit.CommitDate    = repo.CommitDate(commit.Hash);

                        if (commit.CommitDate == null)
                        {
                            Console.Error.WriteLine("Error: Could not get commit date from the git repository.");
                            return(false);
                        }

                        Console.WriteLine("Commit {0} merge base {1} date {2}", commit.Hash, commit.MergeBaseHash, commit.CommitDate);
                    }
                } catch (Exception) {
                    Console.WriteLine("Could not get git repository");
                }
            }

            if (commit.Hash == null)
            {
                Console.Error.WriteLine("Error: cannot parse mono version and no commit given.");
                return(false);
            }

            Octokit.Commit gitHubCommit = await ResolveFullHashViaGithub(commit);

            if (gitHubCommit == null)
            {
                Console.WriteLine("Could not get commit " + commit.Hash + " from GitHub");
            }
            else
            {
                commit.Hash = gitHubCommit.Sha;
                if (commit.CommitDate == null)
                {
                    commit.CommitDate = gitHubCommit.Committer.Date.DateTime.ToLocalTime();
                }
                Console.WriteLine("Got commit " + commit.Hash + " from GitHub");
            }

            if (commit.CommitDate == null)
            {
                Console.Error.WriteLine("Error: Could not get a commit date.");
                return(false);
            }

            return(true);
        }
Esempio n. 4
0
        public async Task <Commit> GetCommit(string optionalCommitHash, string optionalGitRepoDir)
        {
            if (NoMono)
            {
                // FIXME: return a dummy commit
                return(null);
            }

            var info = NewProcessStartInfo();

            /* Run without timing with --version */
            info.Arguments = "--version";

            Console.Out.WriteLine("\t$> {0} {1} {2}", PrintableEnvironmentVariables(info), info.FileName, info.Arguments);

            var process      = Process.Start(info);
            var version      = Task.Run(() => new StreamReader(process.StandardOutput.BaseStream).ReadToEnd()).Result;
            var versionError = Task.Run(() => new StreamReader(process.StandardError.BaseStream).ReadToEnd()).Result;

            process.WaitForExit();
            process.Close();

            var line  = version.Split(new char[] { '\n' }, 2) [0];
            var regex = new Regex("^Mono JIT.*\\((.*)/([0-9a-f]+) (.*)\\)");
            var match = regex.Match(line);

            var commit = new Commit();

            if (match.Success)
            {
                commit.Branch = match.Groups [1].Value;
                commit.Hash   = match.Groups [2].Value;
                var date = match.Groups [3].Value;
                Console.WriteLine("branch: " + commit.Branch + " hash: " + commit.Hash + " date: " + date);
            }
            else
            {
                if (optionalCommitHash == null)
                {
                    Console.Error.WriteLine("Error: cannot parse mono version and no commit given.");
                    return(null);
                }
            }

            if (commit.Branch == "(detached")
            {
                commit.Branch = null;
            }

            if (optionalCommitHash != null)
            {
                if (commit.Hash != null && !optionalCommitHash.StartsWith(commit.Hash))
                {
                    Console.Error.WriteLine("Error: Commit hash specified on command line does not match the one reported with --version.");
                    return(null);
                }
                commit.Hash = optionalCommitHash;
            }

            try {
                var gitRepoDir = optionalGitRepoDir ?? Path.GetDirectoryName(Mono);
                var repo       = new Repository(gitRepoDir);
                var gitHash    = repo.RevParse(commit.Hash);
                if (gitHash == null)
                {
                    Console.WriteLine("Could not get commit " + commit.Hash + " from repository");
                }
                else
                {
                    Console.WriteLine("Got commit " + gitHash + " from repository");

                    if (optionalCommitHash != null && optionalCommitHash != gitHash)
                    {
                        Console.Error.WriteLine("Error: Commit hash specified on command line does not match the one from the git repository.");
                        return(null);
                    }

                    commit.Hash          = gitHash;
                    commit.MergeBaseHash = repo.MergeBase(commit.Hash, "master");
                    commit.CommitDate    = repo.CommitDate(commit.Hash);

                    if (commit.CommitDate == null)
                    {
                        Console.Error.WriteLine("Error: Could not get commit date from the git repository.");
                        return(null);
                    }

                    Console.WriteLine("Commit {0} merge base {1} date {2}", commit.Hash, commit.MergeBaseHash, commit.CommitDate);
                }
            } catch (Exception) {
                Console.WriteLine("Could not get git repository");
            }

            Octokit.Commit gitHubCommit = null;
            try {
                var gitHubClient = GitHubInterface.GitHubClient;
                gitHubCommit = await ParseInterface.RunWithRetry(() => gitHubClient.GitDatabase.Commit.Get("mono", "mono", commit.Hash), typeof(Octokit.NotFoundException));
            } catch (Octokit.NotFoundException) {
                Console.WriteLine("Commit " + commit.Hash + " not found on GitHub");
            }
            if (gitHubCommit == null)
            {
                Console.WriteLine("Could not get commit " + commit.Hash + " from GitHub");
            }
            else
            {
                if (optionalCommitHash != null && optionalCommitHash != gitHubCommit.Sha)
                {
                    Console.Error.WriteLine("Error: Commit hash specified on command line does not match the one from GitHub.");
                    return(null);
                }

                commit.Hash = gitHubCommit.Sha;
                if (commit.CommitDate == null)
                {
                    commit.CommitDate = gitHubCommit.Committer.Date.DateTime;
                }
                Console.WriteLine("Got commit " + commit.Hash + " from GitHub");
            }

            return(commit);
        }