Пример #1
0
        static async Task Main(string[] args)
        {
            if (args[0] == "appcenter")
            {
                var basePath        = args[1];
                var runLimit        = int.Parse(args[2]);
                var appCenterApiKey = args[3];

                var p = new OptionSet()
                {
                    { "base-path=", s => basePath = s },
                    { "appCenterApiKey=", s => appCenterApiKey = s },
                    { "runLimit=", s => runLimit = int.Parse(s) },
                };

                var list = p.Parse(args);

                new AppCenterTestsDownloader(appCenterApiKey).Download(appCenterApiKey, basePath, runLimit).Wait();

                ProcessFiles(basePath, basePath, null, "", "ios", "0");
                ProcessFiles(basePath, basePath, null, "", "Android", "0");
            }
            else if (args[0] == "azdo")
            {
                var basePath              = "";
                var runLimit              = 0;
                var pat                   = "";
                var sourceBranch          = "";
                var targetBranchParam     = "";
                var artifactName          = "";
                var artifactInnerBasePath = "";                 // base path inside the artifact archive
                var definitionName        = "";                 // Build.DefinitionName
                var projectName           = "";                 // System.TeamProject
                var serverUri             = "";                 // System.TeamFoundationCollectionUri
                var currentBuild          = 0;                  // Build.BuildId

                var githubPAT        = "";
                var sourceRepository = "";
                var githubPRid       = "";

                var p = new OptionSet()
                {
                    { "base-path=", s => basePath = s },
                    { "pat=", s => pat = s },
                    { "run-limit=", s => runLimit = int.Parse(s) },
                    { "source-branch=", s => sourceBranch = s },                       // Build.SourceBranchName
                    { "target-branch=", s => targetBranchParam = s },                  // System.PullRequest.TargetBranch
                    { "artifact-name=", s => artifactName = s },
                    { "artifact-inner-path=", s => artifactInnerBasePath = s },
                    { "definition-name=", s => definitionName = s },
                    { "project-name=", s => projectName = s },
                    { "server-uri=", s => serverUri = s },
                    { "current-build=", s => currentBuild = int.Parse(s) },

                    //
                    // GitHub PR comments related
                    //
                    { "github-pat=", s => githubPAT = s },
                    { "source-repository=", s => sourceRepository = s },
                    { "github-pr-id=", s => githubPRid = s }
                };

                var list = p.Parse(args);

                var targetBranch = !string.IsNullOrEmpty(targetBranchParam) && targetBranchParam != "$(System.PullRequest.TargetBranch)" ? targetBranchParam : sourceBranch;

                var downloader = new AzureDevopsDownloader(pat, serverUri);
                var artifacts  = await downloader.DownloadArtifacts(basePath, projectName, definitionName, artifactName, sourceBranch, targetBranch, currentBuild, runLimit);

                var artifactsBasePath = Path.Combine(basePath, "artifacts");
                var results           = new List <CompareResult>();

                foreach (var platform in GetValidPlatforms(artifactsBasePath))
                {
                    var result = ProcessFiles(basePath, artifactsBasePath, artifacts, artifactInnerBasePath, platform, currentBuild.ToString());
                    results.Add(result);
                }

                await TryPublishPRComments(results, githubPAT, sourceRepository, githubPRid, currentBuild);
            }
            else if (args[0] == "compare")
            {
                var leftPath   = args[0];
                var rightPath  = args[1];
                var outputPath = args[2];

                var q = from leftFilePath in Directory.EnumerateFiles(leftPath, "*.png")
                        let leftFileName = Path.GetFileName(leftFilePath)
                                           join rightFilePath in Directory.EnumerateFiles(rightPath, "*.png") on leftFileName equals Path.GetFileName(rightFilePath) into gj
                                           from pair in gj.DefaultIfEmpty()
                                           select new
                {
                    LeftPath  = leftFilePath,
                    RightPath = pair
                };

                using (var file = new StreamWriter(outputPath))
                {
                    file.Write("<html><body>");
                    file.Write("<table>");

                    foreach (var pair in q)
                    {
                        var areValidFiles = pair.LeftPath != null && pair.RightPath != null;
                        var areEqual      = areValidFiles ?
                                            File.ReadAllBytes(pair.LeftPath).SequenceEqual(File.ReadAllBytes(pair.RightPath))
                                                        : false;

                        if (!areEqual)
                        {
                            file.Write("<tr>");
                            file.Write("<td>");
                            file.Write($"<img src=\"file:///{pair.LeftPath}\" width=400 height=400 />");
                            file.Write("</td>");
                            file.Write("<td>");
                            file.Write($"<img src=\"file:///{pair.RightPath}\"  width=400 height=400 />");
                            file.Write("</td>");
                            file.Write("</tr>");
                        }
                    }
                    file.Write("</table>");
                    file.Write("</body></html>");
                }
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            if (args[0] == "appcenter")
            {
                if (args.Length != 4)
                {
                    Console.WriteLine("tc [base path] [run limit] [api key]");
                    return;
                }

                var basePath = args[1];
                var runLimit = int.Parse(args[2]);
                var apiKey   = args[3];

                new AppCenterTestsDownloader(apiKey).Download(apiKey, basePath, runLimit).Wait();

                ProcessFiles(args, basePath, "ios");
                ProcessFiles(args, basePath, "Android");
            }
            else if (args[0] == "azdo")
            {
                var pat            = args[1];
                var basePath       = args[2];
                var sourceBranch   = args[3];                                                                                                    // Build.SourceBranchName
                var targetBranch   = !string.IsNullOrEmpty(args[4]) && args[4] != "$(System.PullRequest.TargetBranch)" ? args[4] : sourceBranch; // System.PullRequest.TargetBranch
                var artifactName   = args[5];
                var definitionName = args[6];                                                                                                    // Build.DefinitionName
                var projectName    = args[7];                                                                                                    // System.TeamProject
                var serverUri      = args[8];                                                                                                    // System.TeamFoundationCollectionUri
                var currentBuild   = int.Parse(args[9]);                                                                                         // Build.BuildId
                var runLimit       = int.Parse(args[10]);

                var downloader = new AzureDevopsDownloader(pat, serverUri);
                downloader.DownloadArtifacts(Path.Combine(basePath, "wasm"), projectName, definitionName, artifactName, sourceBranch, targetBranch, currentBuild, runLimit).Wait();

                ProcessFiles(args, basePath, "wasm");
            }
            else if (args[0] == "compare")
            {
                var leftPath   = args[0];
                var rightPath  = args[1];
                var outputPath = args[2];

                var q = from leftFilePath in Directory.EnumerateFiles(leftPath, "*.png")
                        let leftFileName = Path.GetFileName(leftFilePath)
                                           join rightFilePath in Directory.EnumerateFiles(rightPath, "*.png") on leftFileName equals Path.GetFileName(rightFilePath) into gj
                                           from pair in gj.DefaultIfEmpty()
                                           select new
                {
                    LeftPath  = leftFilePath,
                    RightPath = pair
                };

                using (var file = new StreamWriter(outputPath))
                {
                    file.Write("<html><body>");
                    file.Write("<table>");

                    foreach (var pair in q)
                    {
                        var areValidFiles = pair.LeftPath != null && pair.RightPath != null;
                        var areEqual      = areValidFiles ?
                                            File.ReadAllBytes(pair.LeftPath).SequenceEqual(File.ReadAllBytes(pair.RightPath))
                                                        : false;

                        if (!areEqual)
                        {
                            file.Write("<tr>");
                            file.Write("<td>");
                            file.Write($"<img src=\"file:///{pair.LeftPath}\" width=400 height=400 />");
                            file.Write("</td>");
                            file.Write("<td>");
                            file.Write($"<img src=\"file:///{pair.RightPath}\"  width=400 height=400 />");
                            file.Write("</td>");
                            file.Write("</tr>");
                        }
                    }
                    file.Write("</table>");
                    file.Write("</body></html>");
                }
            }
        }