protected override void TraceListenedExecute()
        {
            GitHubAuth auth = null;

            if (string.IsNullOrEmpty(GitHubAuthToken))
            {
                Log.LogMessage(
                    MessageImportance.Low,
                    $"No value for '{nameof(GitHubAuthToken)}'. " +
                    "Accessing GitHub API anonymously.");
            }
            else
            {
                auth = new GitHubAuth(GitHubAuthToken, GitHubUser);
            }

            using (var client = new GitHubClient(auth))
            {
                DependencyUpdateResults updateResults = UpdateToRemote(client);

                MadeChanges            = updateResults.ChangesDetected();
                SuggestedCommitMessage = updateResults.GetSuggestedCommitMessage();

                if (MadeChanges)
                {
                    Log.LogMessage(
                        MessageImportance.Normal,
                        $"Suggested commit message: '{SuggestedCommitMessage}'");
                }
                else
                {
                    Log.LogMessage(MessageImportance.Normal, "No changes performed.");
                }
            }
        }
Ejemplo n.º 2
0
        public static async Task Main(string[] args)
        {
            try
            {
                Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));

                Options.Parse(args);

                DependencyUpdateResults updateResults = await UpdateFilesAsync();

                if (updateResults.ChangesDetected())
                {
                    if (Options.UpdateOnly)
                    {
                        Trace.TraceInformation($"Changes made but no GitHub credentials specified, skipping PR creation");
                    }
                    else
                    {
                        await CreatePullRequestAsync(updateResults);
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine($"Failed to update dependencies:{Environment.NewLine}{e.ToString()}");
                Environment.Exit(1);
            }

            Environment.Exit(0);
        }
Ejemplo n.º 3
0
        protected DependencyUpdateResults UpdateToRemote(GitHubClient client)
        {
            // Use the commit hash of the remote dotnet/versions repo master branch.
            string versionsCommitHash = client
                                        .GetReferenceAsync(new GitHubProject("versions", "dotnet"), "heads/master")
                                        .Result.Object.Sha;

            DependencyUpdateResults updateResults = DependencyUpdateUtils.Update(
                CreateUpdaters().ToArray(),
                CreateDependencyInfos(true, versionsCommitHash).ToArray());

            // Update CurrentRef for each applicable build info used.
            if (!string.IsNullOrEmpty(CurrentRefXmlPath))
            {
                foreach (ITaskItem item in updateResults.UsedInfos
                         .OfType <TaskItemBuildDependencyInfo>()
                         .Distinct()
                         .Select(info => info.SourceItem)
                         .Where(item => !string.IsNullOrEmpty(item.GetMetadata(CurrentRefMetadataName))))
                {
                    UpdateProperty(
                        CurrentRefXmlPath,
                        $"{item.ItemSpec}{CurrentRefMetadataName}",
                        versionsCommitHash);
                }
            }

            return(updateResults);
        }
        public async Task ExecuteAsync()
        {
            IEnumerable <IDependencyInfo> dependencyInfos = new IDependencyInfo[]
            {
                CreateBuildInfo(RuntimeImageVariant,
                                this.options.DateStampRuntime ?? this.options.DateStampAll ?? String.Empty),
                CreateBuildInfo(SdkImageVariant,
                                this.options.DateStampSdk ?? this.options.DateStampAll ?? String.Empty),
                CreateBuildInfo(AspnetImageVariant,
                                this.options.DateStampAspnet ?? this.options.DateStampAll ?? String.Empty),
                CreateBuildInfo(WcfImageVariant,
                                this.options.DateStampWcf ?? this.options.DateStampAll ?? String.Empty),
            };

            DependencyUpdateResults updateResults = UpdateFiles(dependencyInfos);

            if (updateResults.ChangesDetected())
            {
                if (this.options.UpdateOnly)
                {
                    Trace.TraceInformation($"Changes made but no GitHub credentials specified, skipping PR creation");
                }
                else
                {
                    await CreatePullRequestAsync(dependencyInfos);
                }
            }
        }
        public static void Main(string[] args)
        {
            Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));

            if (ParseArgs(args))
            {
                DependencyUpdateResults updateResults = UpdateFiles();

                if (!s_updateOnly && updateResults.ChangesDetected())
                {
                    CreatePullRequest(updateResults).Wait();
                }
            }
        }
Ejemplo n.º 6
0
        public static void Main(string[] args)
        {
            HandleDebugSwitch(ref args);

            bool onlyUpdate = args.Length > 0 && string.Equals("--Update", args[0], StringComparison.OrdinalIgnoreCase);

            List <BuildInfo> buildInfos = new List <BuildInfo>();

            buildInfos.Add(GetBuildInfo("CoreSetup", s_config.CoreSetupVersionFragment, fetchLatestReleaseFile: false));

            if (s_config.HasRoslynVersionFragment)
            {
                buildInfos.Add(GetBuildInfo("Roslyn", s_config.RoslynVersionFragment, fetchLatestReleaseFile: false));
            }

            IEnumerable <IDependencyUpdater> updaters = GetUpdaters();
            var dependencyBuildInfos = buildInfos.Select(buildInfo =>
                                                         new BuildDependencyInfo(
                                                             buildInfo,
                                                             upgradeStableVersions: true,
                                                             disabledPackages: Enumerable.Empty <string>()));
            DependencyUpdateResults updateResults = DependencyUpdateUtils.Update(updaters, dependencyBuildInfos);

            if (!onlyUpdate && updateResults.ChangesDetected())
            {
                GitHubAuth    gitHubAuth     = new GitHubAuth(s_config.Password, s_config.UserName, s_config.Email);
                GitHubProject origin         = new GitHubProject(s_config.GitHubProject, s_config.UserName);
                GitHubBranch  upstreamBranch = new GitHubBranch(
                    s_config.GitHubUpstreamBranch,
                    new GitHubProject(s_config.GitHubProject, s_config.GitHubUpstreamOwner));

                string suggestedMessage = updateResults.GetSuggestedCommitMessage();
                string body             = string.Empty;
                if (s_config.GitHubPullRequestNotifications.Any())
                {
                    body += PullRequestCreator.NotificationString(s_config.GitHubPullRequestNotifications);
                }

                new PullRequestCreator(gitHubAuth)
                .CreateOrUpdateAsync(
                    suggestedMessage,
                    suggestedMessage + $" ({upstreamBranch.Name})",
                    body,
                    upstreamBranch,
                    origin,
                    new PullRequestOptions())
                .Wait();
            }
        }
        private static Task CreatePullRequest(DependencyUpdateResults updateResults)
        {
            string commitMessage = $"Update {s_config.BranchTagPrefix} SDK to {updateResults.UsedBuildInfos.Single().LatestReleaseVersion}";

            GitHubAuth gitHubAuth = new GitHubAuth(s_config.Password, s_config.UserName, s_config.Email);

            PullRequestCreator prCreator = new PullRequestCreator(
                gitHubAuth,
                new GitHubProject(s_config.GitHubProject, gitHubAuth.User),
                new GitHubBranch(s_config.GitHubUpstreamBranch, new GitHubProject(s_config.GitHubProject, s_config.GitHubUpstreamOwner)),
                s_config.UserName,
                new SingleBranchNamingStrategy($"UpdateDependencies-{s_config.BranchTagPrefix}")
                );

            return(prCreator.CreateOrUpdateAsync(commitMessage, commitMessage, string.Empty));
        }
Ejemplo n.º 8
0
        public static void Main(string[] args)
        {
            DebugHelper.HandleDebugSwitch(ref args);

            bool onlyUpdate;

            ParseArgs(args, out onlyUpdate);

            List <BuildInfo> buildInfos = new List <BuildInfo>();

            buildInfos.Add(GetBuildInfo("CoreFx", s_config.CoreFxVersionUrl, fetchLatestReleaseFile: false));
            buildInfos.Add(GetBuildInfo("CoreClr", s_config.CoreClrVersionUrl, fetchLatestReleaseFile: false));
            buildInfos.Add(GetBuildInfo("Standard", s_config.StandardVersionUrl, fetchLatestReleaseFile: false));

            IEnumerable <IDependencyUpdater> updaters = GetUpdaters();
            var dependencyBuildInfos = buildInfos.Select(buildInfo =>
                                                         new DependencyBuildInfo(
                                                             buildInfo,
                                                             upgradeStableVersions: true,
                                                             disabledPackages: Enumerable.Empty <string>()));
            DependencyUpdateResults updateResults = DependencyUpdateUtils.Update(updaters, dependencyBuildInfos);

            if (!onlyUpdate && updateResults.ChangesDetected())
            {
                GitHubAuth    gitHubAuth     = new GitHubAuth(s_config.Password, s_config.UserName, s_config.Email);
                GitHubProject origin         = new GitHubProject(s_config.GitHubProject, s_config.UserName);
                GitHubBranch  upstreamBranch = new GitHubBranch(
                    s_config.GitHubUpstreamBranch,
                    new GitHubProject(s_config.GitHubProject, s_config.GitHubUpstreamOwner));

                string suggestedMessage = updateResults.GetSuggestedCommitMessage();
                string body             = string.Empty;
                if (s_config.GitHubPullRequestNotifications.Any())
                {
                    body += PullRequestCreator.NotificationString(s_config.GitHubPullRequestNotifications);
                }

                new PullRequestCreator(gitHubAuth, origin, upstreamBranch)
                .CreateOrUpdateAsync(
                    suggestedMessage,
                    suggestedMessage + $" ({upstreamBranch.Name})",
                    body)
                .Wait();
            }
        }
Ejemplo n.º 9
0
        private static void CreatePullRequest(DependencyUpdateResults updateResults)
        {
            GitHubAuth    gitHubAuth     = new GitHubAuth(config.Password, config.UserName, config.Email);
            GitHubProject origin         = new GitHubProject(config.GitHubProject, config.UserName);
            GitHubBranch  upstreamBranch = new GitHubBranch(config.GitHubUpstreamBranch, new GitHubProject(config.GitHubProject, config.GitHubUpstreamOwner));

            string commitMessage = updateResults.GetSuggestedCommitMessage();
            string body          = string.Empty;

            if (config.GitHubPullRequestNotifications.Any())
            {
                body += PullRequestCreator.NotificationString(config.GitHubPullRequestNotifications);
            }

            new PullRequestCreator(gitHubAuth, origin, upstreamBranch)
            .CreateOrUpdateAsync(commitMessage, commitMessage + $" ({upstreamBranch.Name})", body)
            .Wait();
        }
Ejemplo n.º 10
0
        private static async Task ExecuteAsync(Options options)
        {
            Options = options;

            try
            {
                ErrorTraceListener errorTraceListener = new ErrorTraceListener();
                Trace.Listeners.Add(errorTraceListener);
                Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));

                IEnumerable <IDependencyInfo> buildInfos = Options.ProductVersions
                                                           .Select(kvp => CreateDependencyBuildInfo(kvp.Key, kvp.Value))
                                                           .ToArray();
                DependencyUpdateResults updateResults = UpdateFiles(buildInfos);
                if (updateResults.ChangesDetected())
                {
                    if (Options.UpdateOnly)
                    {
                        Trace.TraceInformation($"Changes made but no GitHub credentials specified, skipping PR creation");
                    }
                    else
                    {
                        await CreatePullRequestAsync();
                    }
                }

                if (errorTraceListener.Errors.Any())
                {
                    string errors = string.Join(Environment.NewLine, errorTraceListener.Errors);
                    Console.Error.WriteLine("Failed to update dependencies due to the following errors:");
                    Console.Error.WriteLine(errors);
                    Console.Error.WriteLine();
                    Console.Error.WriteLine("You may need to use the --compute-shas option if checksum files are missing.");
                    Environment.Exit(1);
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine($"Failed to update dependencies:{Environment.NewLine}{e}");
                Environment.Exit(1);
            }

            Environment.Exit(0);
        }
Ejemplo n.º 11
0
        public static void Main(string[] args)
        {
            Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));

            if (!ParseArgs(args, out bool updateOnly))
            {
                return;
            }

            IEnumerable <IDependencyUpdater>  updaters = GetUpdaters();
            IEnumerable <DependencyBuildInfo> buildInfoDependencies = GetBuildInfoDependencies();

            DependencyUpdateResults updateResults = DependencyUpdateUtils.Update(updaters, buildInfoDependencies);

            if (!updateOnly && updateResults.ChangesDetected())
            {
                CreatePullRequest(updateResults);
            }
        }
Ejemplo n.º 12
0
        public override bool Execute()
        {
            MsBuildTraceListener[] listeners = Trace.Listeners.AddMsBuildTraceListeners(Log);
            try
            {
                IDependencyUpdater[] updaters   = GetDependencyUpdaters().ToArray();
                BuildInfo[]          buildInfos = GetBuildInfos().ToArray();
                var updater = new DependencyUpdater();

                DependencyUpdateResults updateResults = updater.Update(updaters, buildInfos);

                if (updateResults.ChangesDetected())
                {
                    var gitHubAuth = new GitHubAuth(GitHubAuthToken, GitHubUser, GitHubEmail);

                    var origin = new GitHubProject(ProjectRepoName, GitHubUser);

                    var upstreamBranch = new GitHubBranch(
                        ProjectRepoBranch,
                        new GitHubProject(ProjectRepoName, ProjectRepoOwner));

                    string suggestedMessage = updateResults.GetSuggestedCommitMessage();
                    string body             = string.Empty;
                    if (NotifyGitHubUsers != null)
                    {
                        body += PullRequestCreator.NotificationString(NotifyGitHubUsers.Select(item => item.ItemSpec));
                    }

                    var prCreator = new PullRequestCreator(gitHubAuth, origin, upstreamBranch, GitHubAuthor);
                    prCreator.CreateOrUpdateAsync(
                        suggestedMessage,
                        suggestedMessage + $" ({ProjectRepoBranch})",
                        body,
                        forceCreate: AlwaysCreateNewPullRequest).Wait();
                }
            }
            finally
            {
                Trace.Listeners.RemoveMsBuildTraceListeners(listeners);
            }

            return(true);
        }
Ejemplo n.º 13
0
        public static async Task Main(string[] args)
        {
            try
            {
                ErrorTraceListener errorTraceListener = new ErrorTraceListener();
                Trace.Listeners.Add(errorTraceListener);
                Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));

                Options.Parse(args);

                IEnumerable <IDependencyInfo> buildInfos    = GetBuildInfo();
                DependencyUpdateResults       updateResults = UpdateFiles(buildInfos);
                if (updateResults.ChangesDetected())
                {
                    if (Options.UpdateOnly)
                    {
                        Trace.TraceInformation($"Changes made but no GitHub credentials specified, skipping PR creation");
                    }
                    else
                    {
                        await CreatePullRequestAsync();
                    }
                }

                if (errorTraceListener.Errors.Any())
                {
                    string errors = String.Join(Environment.NewLine, errorTraceListener.Errors);
                    Console.Error.WriteLine("Failed to update dependencies due to the following errors:");
                    Console.Error.WriteLine(errors);
                    Console.Error.WriteLine();
                    Console.Error.WriteLine("You may need to use the --compute-shas option if checksum files are missing.");
                    Environment.Exit(1);
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine($"Failed to update dependencies:{Environment.NewLine}{e.ToString()}");
                Environment.Exit(1);
            }

            Environment.Exit(0);
        }
Ejemplo n.º 14
0
        private static async Task CreatePullRequestAsync(DependencyUpdateResults updateResults)
        {
            GitHubAuth         gitHubAuth = new GitHubAuth(Options.GitHubPassword, Options.GitHubUser, Options.GitHubEmail);
            PullRequestCreator prCreator  = new PullRequestCreator(gitHubAuth, Options.GitHubUser);
            PullRequestOptions prOptions  = new PullRequestOptions()
            {
                BranchNamingStrategy = new SingleBranchNamingStrategy($"UpdateDependencies-{Options.GitHubUpstreamBranch}")
            };

            string sdkVersion    = updateResults.UsedInfos.GetBuildVersion(SdkBuildInfoName);
            string commitMessage = $"Update {Options.GitHubUpstreamBranch} SDK to {sdkVersion}";

            await prCreator.CreateOrUpdateAsync(
                commitMessage,
                commitMessage,
                string.Empty,
                new GitHubBranch(Options.GitHubUpstreamBranch, new GitHubProject(Options.GitHubProject, Options.GitHubUpstreamOwner)),
                new GitHubProject(Options.GitHubProject, gitHubAuth.User),
                prOptions);
        }
Ejemplo n.º 15
0
        private async Task CreatePullRequestAsync(DependencyUpdateResults updateResults)
        {
            var gitHubAuth = new GitHubAuth(GitHubPassword, GitHubUser, GitHubEmail);
            var prCreator  = new PullRequestCreator(gitHubAuth, GitHubUser);
            var prOptions  = new PullRequestOptions()
            {
                BranchNamingStrategy = new SingleBranchNamingStrategy($"UpdateDependencies-{GitHubUpstreamBranch}")
            };

            var runtimeVersion = updateResults.UsedInfos.First().SimpleVersion;
            var commitMessage  = $"Update aspnetcore on {GitHubUpstreamBranch} to {runtimeVersion}";

            await prCreator.CreateOrUpdateAsync(
                commitMessage,
                commitMessage,
                string.Empty,
                new GitHubBranch(GitHubUpstreamBranch, new GitHubProject(GitHubProject, GitHubUpstreamOwner)),
                new GitHubProject(GitHubProject, gitHubAuth.User),
                prOptions);
        }
Ejemplo n.º 16
0
        public static void Main(string[] args)
        {
            try
            {
                Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));

                if (ParseArgs(args))
                {
                    DependencyUpdateResults updateResults = UpdateFiles();

                    if (!s_updateOnly && updateResults.ChangesDetected())
                    {
                        CreatePullRequest(updateResults).Wait();
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine($"Failed to update dependencies:{Environment.NewLine}{e.ToString()}");
            }
        }
Ejemplo n.º 17
0
        protected override void TraceListenedExecute()
        {
            // Use the commit sha of versions repo master (not just "master") for stable upgrade.
            var    gitHubAuth = new GitHubAuth(GitHubAuthToken, GitHubUser, GitHubEmail);
            var    client     = new GitHubClient(gitHubAuth);
            string masterSha  = client
                                .GetReferenceAsync(new GitHubProject("versions", "dotnet"), "heads/master")
                                .Result.Object.Sha;

            foreach (ITaskItem item in DependencyBuildInfo)
            {
                if (!string.IsNullOrEmpty(item.GetMetadata(CurrentRefMetadataName)))
                {
                    item.SetMetadata(CurrentRefMetadataName, masterSha);
                }
                string autoUpgradeBranch = item.GetMetadata(AutoUpgradeBranchMetadataName);
                if (!string.IsNullOrEmpty(autoUpgradeBranch))
                {
                    item.SetMetadata(CurrentBranchMetadataName, autoUpgradeBranch);
                }
            }

            DependencyUpdateResults updateResults = DependencyUpdateUtils.Update(
                CreateUpdaters().ToArray(),
                CreateBuildInfoDependencies().ToArray());

            // Update CurrentRef and CurrentBranch for each applicable build info used.
            if (!string.IsNullOrEmpty(CurrentRefXmlPath))
            {
                foreach (BuildInfo info in updateResults.UsedBuildInfos)
                {
                    ITaskItem infoItem = FindDependencyBuildInfo(info.Name);

                    if (!string.IsNullOrEmpty(infoItem.GetMetadata(CurrentRefMetadataName)))
                    {
                        UpdateProperty(
                            CurrentRefXmlPath,
                            $"{info.Name}{CurrentRefMetadataName}",
                            masterSha);
                    }

                    string autoUpgradeBranch = infoItem.GetMetadata(AutoUpgradeBranchMetadataName);
                    if (!string.IsNullOrEmpty(autoUpgradeBranch))
                    {
                        UpdateProperty(
                            CurrentRefXmlPath,
                            $"{info.Name}{CurrentBranchMetadataName}",
                            autoUpgradeBranch);
                    }
                }
            }

            if (updateResults.ChangesDetected())
            {
                var origin = new GitHubProject(ProjectRepoName, GitHubUser);

                var upstreamBranch = new GitHubBranch(
                    ProjectRepoBranch,
                    new GitHubProject(ProjectRepoName, ProjectRepoOwner));

                string suggestedMessage = updateResults.GetSuggestedCommitMessage();
                string body             = string.Empty;
                if (NotifyGitHubUsers != null)
                {
                    body += PullRequestCreator.NotificationString(NotifyGitHubUsers.Select(item => item.ItemSpec));
                }

                var prCreator = new PullRequestCreator(gitHubAuth, origin, upstreamBranch, GitHubAuthor);
                prCreator.CreateOrUpdateAsync(
                    suggestedMessage,
                    suggestedMessage + $" ({ProjectRepoBranch})",
                    body,
                    forceCreate: AlwaysCreateNewPullRequest).Wait();
            }
            else
            {
                Log.LogMessage("No update required: no changes detected.");
            }
        }