2016-03-07 20:24:36 +00:00
|
|
|
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
|
|
2016-07-16 00:09:38 +00:00
|
|
|
|
using Microsoft.DotNet.Cli.Utils;
|
|
|
|
|
using Microsoft.DotNet.VersionTools;
|
|
|
|
|
using Microsoft.DotNet.VersionTools.Automation;
|
|
|
|
|
using Microsoft.DotNet.VersionTools.Dependencies;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text.RegularExpressions;
|
2016-03-07 20:24:36 +00:00
|
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Scripts
|
|
|
|
|
{
|
|
|
|
|
public class Program
|
|
|
|
|
{
|
2016-07-16 00:09:38 +00:00
|
|
|
|
private static readonly Config s_config = Config.Instance;
|
|
|
|
|
|
|
|
|
|
public static void Main(string[] args)
|
2016-03-07 20:24:36 +00:00
|
|
|
|
{
|
|
|
|
|
DebugHelper.HandleDebugSwitch(ref args);
|
|
|
|
|
|
2017-02-09 22:25:48 +00:00
|
|
|
|
bool onlyUpdate = args.Length > 0 && string.Equals("--Update", args[0], StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
|
2016-07-16 00:09:38 +00:00
|
|
|
|
List<BuildInfo> buildInfos = new List<BuildInfo>();
|
|
|
|
|
|
|
|
|
|
buildInfos.Add(BuildInfo.Get("Roslyn", s_config.RoslynVersionUrl, fetchLatestReleaseFile: false));
|
|
|
|
|
buildInfos.Add(BuildInfo.Get("CoreSetup", s_config.CoreSetupVersionUrl, fetchLatestReleaseFile: false));
|
|
|
|
|
|
|
|
|
|
IEnumerable<IDependencyUpdater> updaters = GetUpdaters();
|
2017-02-10 17:32:22 +00:00
|
|
|
|
var dependencyBuildInfos = buildInfos.Select(buildInfo =>
|
2017-02-09 22:25:48 +00:00
|
|
|
|
new DependencyBuildInfo(
|
2017-02-10 17:32:22 +00:00
|
|
|
|
buildInfo,
|
2017-02-09 22:25:48 +00:00
|
|
|
|
upgradeStableVersions: true,
|
|
|
|
|
disabledPackages: Enumerable.Empty<string>()));
|
|
|
|
|
DependencyUpdateResults updateResults = DependencyUpdateUtils.Update(updaters, dependencyBuildInfos);
|
|
|
|
|
|
|
|
|
|
if (updateResults.ChangesDetected() && !onlyUpdate)
|
2016-07-16 00:09:38 +00:00
|
|
|
|
{
|
2017-02-09 22:25:48 +00:00
|
|
|
|
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;
|
2017-02-10 17:32:22 +00:00
|
|
|
|
if (s_config.GitHubPullRequestNotifications.Any())
|
2017-02-09 22:25:48 +00:00
|
|
|
|
{
|
|
|
|
|
body += PullRequestCreator.NotificationString(s_config.GitHubPullRequestNotifications);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
new PullRequestCreator(gitHubAuth, origin, upstreamBranch)
|
|
|
|
|
.CreateOrUpdateAsync(
|
|
|
|
|
suggestedMessage,
|
|
|
|
|
suggestedMessage + $" ({upstreamBranch.Name})",
|
|
|
|
|
body)
|
|
|
|
|
.Wait();
|
2016-07-16 00:09:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static IEnumerable<IDependencyUpdater> GetUpdaters()
|
|
|
|
|
{
|
2017-02-14 01:03:36 +00:00
|
|
|
|
yield return CreateRegexUpdater(Path.Combine("build", "Microsoft.DotNet.Cli.DependencyVersions.props"), "CLI_SharedFrameworkVersion", "Microsoft.NETCore.App");
|
2016-07-16 00:09:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-09 22:25:48 +00:00
|
|
|
|
private static IDependencyUpdater CreateRegexUpdater(string repoRelativePath, string propertyName, string packageId)
|
2016-07-16 00:09:38 +00:00
|
|
|
|
{
|
|
|
|
|
return new FileRegexPackageUpdater()
|
|
|
|
|
{
|
|
|
|
|
Path = Path.Combine(Dirs.RepoRoot, repoRelativePath),
|
|
|
|
|
PackageId = packageId,
|
2017-02-09 22:25:48 +00:00
|
|
|
|
Regex = new Regex($@"<{propertyName}>(?<version>.*)</{propertyName}>"),
|
2016-07-16 00:09:38 +00:00
|
|
|
|
VersionGroupName = "version"
|
|
|
|
|
};
|
2016-03-07 20:24:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|