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.VersionTools;
|
|
|
|
|
using Microsoft.DotNet.VersionTools.Automation;
|
|
|
|
|
using Microsoft.DotNet.VersionTools.Dependencies;
|
2018-01-30 05:20:07 +00:00
|
|
|
|
using Microsoft.DotNet.VersionTools.Dependencies.BuildOutput;
|
2016-07-16 00:09:38 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2017-05-11 15:15:05 +00:00
|
|
|
|
using System.Diagnostics;
|
2016-07-16 00:09:38 +00:00
|
|
|
|
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
|
|
|
|
{
|
2017-05-11 15:15:05 +00:00
|
|
|
|
HandleDebugSwitch(ref args);
|
2016-03-07 20:24:36 +00:00
|
|
|
|
|
2017-02-09 22:25:48 +00:00
|
|
|
|
bool onlyUpdate = args.Length > 0 && string.Equals("--Update", args[0], StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
|
2018-03-29 21:43:38 +00:00
|
|
|
|
List<BuildInfo> buildInfos = new List<BuildInfo>(s_config.VersionFragments.Select<KeyValuePair<string, string>, BuildInfo>(fragment =>
|
|
|
|
|
GetBuildInfo(fragment.Key, fragment.Value, fetchLatestReleaseFile: false)));
|
2016-07-16 00:09:38 +00:00
|
|
|
|
IEnumerable<IDependencyUpdater> updaters = GetUpdaters();
|
2017-02-10 17:32:22 +00:00
|
|
|
|
var dependencyBuildInfos = buildInfos.Select(buildInfo =>
|
2018-01-30 05:20:07 +00:00
|
|
|
|
new BuildDependencyInfo(
|
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);
|
|
|
|
|
|
2017-02-28 19:33:37 +00:00
|
|
|
|
if (!onlyUpdate && updateResults.ChangesDetected())
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-30 05:20:07 +00:00
|
|
|
|
new PullRequestCreator(gitHubAuth)
|
2017-02-09 22:25:48 +00:00
|
|
|
|
.CreateOrUpdateAsync(
|
|
|
|
|
suggestedMessage,
|
|
|
|
|
suggestedMessage + $" ({upstreamBranch.Name})",
|
2018-01-30 05:20:07 +00:00
|
|
|
|
body,
|
|
|
|
|
upstreamBranch,
|
|
|
|
|
origin,
|
|
|
|
|
new PullRequestOptions())
|
2017-02-09 22:25:48 +00:00
|
|
|
|
.Wait();
|
2016-07-16 00:09:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-20 22:20:27 +00:00
|
|
|
|
private static BuildInfo GetBuildInfo(string name, string buildInfoFragment, bool fetchLatestReleaseFile = true)
|
|
|
|
|
{
|
|
|
|
|
const string FileUrlProtocol = "file://";
|
|
|
|
|
|
|
|
|
|
if (s_config.DotNetVersionUrl.StartsWith(FileUrlProtocol, StringComparison.Ordinal))
|
|
|
|
|
{
|
|
|
|
|
return BuildInfo.LocalFileGetAsync(
|
|
|
|
|
name,
|
|
|
|
|
s_config.DotNetVersionUrl.Substring(FileUrlProtocol.Length),
|
|
|
|
|
buildInfoFragment.Replace('/', Path.DirectorySeparatorChar),
|
|
|
|
|
fetchLatestReleaseFile)
|
|
|
|
|
.Result;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return BuildInfo.Get(name, $"{s_config.DotNetVersionUrl}/{buildInfoFragment}", fetchLatestReleaseFile);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-16 00:09:38 +00:00
|
|
|
|
private static IEnumerable<IDependencyUpdater> GetUpdaters()
|
|
|
|
|
{
|
2017-04-21 18:04:19 +00:00
|
|
|
|
string dependencyVersionsPath = Path.Combine("build", "DependencyVersions.props");
|
2018-03-29 21:43:38 +00:00
|
|
|
|
|
|
|
|
|
if (s_config.HasVersionFragment("aspnet"))
|
|
|
|
|
{
|
2018-09-05 16:07:44 +00:00
|
|
|
|
yield return CreateRegexUpdater(dependencyVersionsPath, "MicrosoftAspNetCoreAllPackageVersion", "Microsoft.AspNetCore.All");
|
2018-09-05 15:59:17 +00:00
|
|
|
|
yield return CreateRegexUpdater(dependencyVersionsPath, "DotnetEfPackageVersion", "dotnet-ef");
|
|
|
|
|
yield return CreateRegexUpdater(dependencyVersionsPath, "MicrosoftAspNetCoreDeveloperCertificatesXPlatPackageVersion", "Microsoft.AspNetCore.DeveloperCertificates.XPlat");
|
|
|
|
|
yield return CreateRegexUpdater(dependencyVersionsPath, "MicrosoftAspNetCoreMvcPackageVersion", "Microsoft.AspNetCore.Mvc");
|
|
|
|
|
yield return CreateRegexUpdater(dependencyVersionsPath, "DotnetDevCertsPackageVersion", "dotnet-dev-certs");
|
|
|
|
|
yield return CreateRegexUpdater(dependencyVersionsPath, "DotnetSqlCachePackageVersion", "dotnet-sql-cache");
|
|
|
|
|
yield return CreateRegexUpdater(dependencyVersionsPath, "DotnetUserSecretsPackageVersion", "dotnet-user-secrets");
|
|
|
|
|
yield return CreateRegexUpdater(dependencyVersionsPath, "DotnetWatchPackageVersion", "dotnet-watch");
|
2018-10-04 14:49:45 +00:00
|
|
|
|
yield return CreateRegexUpdater(dependencyVersionsPath, "MicrosoftNETSdkRazorPackageVersion", "Microsoft.NET.Sdk.Razor");
|
2018-03-29 21:43:38 +00:00
|
|
|
|
}
|
|
|
|
|
if (s_config.HasVersionFragment("clicommandlineparser"))
|
|
|
|
|
{
|
|
|
|
|
yield return CreateRegexUpdater(dependencyVersionsPath, "MicrosoftDotNetCliCommandLinePackageVersion", "Microsoft.DotNet.Cli.CommandLine");
|
|
|
|
|
}
|
|
|
|
|
if (s_config.HasVersionFragment("climigrate"))
|
|
|
|
|
{
|
|
|
|
|
yield return CreateRegexUpdater(dependencyVersionsPath, "MicrosoftDotNetProjectJsonMigrationPackageVersion", "Microsoft.DotNet.ProjectJsonMigration");
|
|
|
|
|
}
|
|
|
|
|
if (s_config.HasVersionFragment("coresetup"))
|
|
|
|
|
{
|
|
|
|
|
yield return CreateRegexUpdater(dependencyVersionsPath, "MicrosoftNETCoreAppPackageVersion", "Microsoft.NETCore.App");
|
|
|
|
|
yield return CreateRegexUpdater(dependencyVersionsPath, "MicrosoftDotNetPlatformAbstractionsPackageVersion", "Microsoft.DotNet.PlatformAbstractions");
|
|
|
|
|
yield return CreateRegexUpdater(dependencyVersionsPath, "MicrosoftExtensionsDependencyModelPackageVersion", "Microsoft.Extensions.DependencyModel");
|
|
|
|
|
}
|
|
|
|
|
if (s_config.HasVersionFragment("fsharp"))
|
|
|
|
|
{
|
|
|
|
|
yield return CreateRegexUpdater(dependencyVersionsPath, "MicrosoftFSharpCompilerPackageVersion", "Microsoft.FSharp.Compiler");
|
|
|
|
|
}
|
|
|
|
|
if (s_config.HasVersionFragment("msbuild"))
|
|
|
|
|
{
|
|
|
|
|
yield return CreateRegexUpdater(dependencyVersionsPath, "MicrosoftBuildPackageVersion", "Microsoft.Build");
|
|
|
|
|
}
|
|
|
|
|
if (s_config.HasVersionFragment("nugetclient"))
|
|
|
|
|
{
|
|
|
|
|
yield return CreateRegexUpdater(dependencyVersionsPath, "NuGetBuildTasksPackageVersion", "NuGet.Build.Tasks");
|
|
|
|
|
}
|
|
|
|
|
if (s_config.HasVersionFragment("roslyn"))
|
2018-01-30 23:43:41 +00:00
|
|
|
|
{
|
|
|
|
|
yield return CreateRegexUpdater(dependencyVersionsPath, "MicrosoftCodeAnalysisCSharpPackageVersion", "Microsoft.CodeAnalysis.CSharp");
|
|
|
|
|
}
|
2018-03-29 21:43:38 +00:00
|
|
|
|
if (s_config.HasVersionFragment("sdk"))
|
|
|
|
|
{
|
|
|
|
|
yield return CreateRegexUpdater(dependencyVersionsPath, "MicrosoftNETSdkPackageVersion", "Microsoft.NET.Sdk");
|
|
|
|
|
}
|
|
|
|
|
if (s_config.HasVersionFragment("templating"))
|
|
|
|
|
{
|
|
|
|
|
yield return CreateRegexUpdater(dependencyVersionsPath, "MicrosoftDotNetCommonItemTemplatesPackageVersion", "Microsoft.DotNet.Common.ItemTemplates");
|
|
|
|
|
yield return CreateRegexUpdater(dependencyVersionsPath, "MicrosoftDotNetTestProjectTemplates20PackageVersion", "Microsoft.DotNet.Test.ProjectTemplates.2.0");
|
|
|
|
|
yield return CreateRegexUpdater(dependencyVersionsPath, "MicrosoftTemplateEngineCliPackageVersion", "Microsoft.TemplateEngine.Cli");
|
|
|
|
|
}
|
|
|
|
|
if (s_config.HasVersionFragment("websdk"))
|
|
|
|
|
{
|
|
|
|
|
yield return CreateRegexUpdater(dependencyVersionsPath, "MicrosoftNETSdkWebPackageVersion", "Microsoft.NET.Sdk.Web");
|
|
|
|
|
}
|
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
|
|
|
|
}
|
2017-05-11 15:15:05 +00:00
|
|
|
|
|
|
|
|
|
private static void HandleDebugSwitch(ref string[] args)
|
|
|
|
|
{
|
|
|
|
|
if (args.Length > 0 && string.Equals("--debug", args[0], StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
args = args.Skip(1).ToArray();
|
|
|
|
|
WaitForDebugger();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void WaitForDebugger()
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Waiting for debugger to attach. Press ENTER to continue");
|
|
|
|
|
Console.WriteLine($"Process ID: {Process.GetCurrentProcess().Id}");
|
|
|
|
|
Console.ReadLine();
|
|
|
|
|
}
|
2016-03-07 20:24:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|