Move to buildtools' VersionTools for update-dependencies.

This commit is contained in:
Eric Erhardt 2016-07-15 19:09:38 -05:00
parent 69eed12132
commit a27d02eb66
8 changed files with 96 additions and 544 deletions

View file

@ -1,25 +1,92 @@
// 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.
using Microsoft.DotNet.Cli.Build.Framework;
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;
namespace Microsoft.DotNet.Scripts
{
public class Program
{
public static int Main(string[] args)
private static readonly Config s_config = Config.Instance;
public static void Main(string[] args)
{
DebugHelper.HandleDebugSwitch(ref args);
return BuildSetup.Create(".NET CLI Dependency Updater")
.UseTargets(new[]
{
new BuildTarget("Default", "Dependency Updater Goals", new [] { "UpdateFiles", "PushPR" }),
new BuildTarget("UpdateFiles", "Dependency Updater Goals"),
new BuildTarget("PushPR", "Dependency Updater Goals"),
})
.UseAllTargetsFromAssembly<Program>()
.Run(args);
List<BuildInfo> buildInfos = new List<BuildInfo>();
buildInfos.Add(BuildInfo.Get("CoreFx", s_config.CoreFxVersionUrl, fetchLatestReleaseFile: false));
buildInfos.Add(BuildInfo.Get("CoreClr", s_config.CoreClrVersionUrl, fetchLatestReleaseFile: false));
buildInfos.Add(BuildInfo.Get("Roslyn", s_config.RoslynVersionUrl, fetchLatestReleaseFile: false));
buildInfos.Add(BuildInfo.Get("CoreSetup", s_config.CoreSetupVersionUrl, fetchLatestReleaseFile: false));
IEnumerable<IDependencyUpdater> updaters = GetUpdaters();
GitHubAuth gitHubAuth = new GitHubAuth(s_config.Password, s_config.UserName, s_config.Email);
DependencyUpdater dependencyUpdater = new DependencyUpdater(
gitHubAuth,
s_config.GitHubProject,
s_config.GitHubUpstreamOwner,
s_config.GitHubUpstreamBranch,
s_config.UserName,
s_config.GitHubPullRequestNotifications);
if (args.Length > 0 && string.Equals("--Update", args[0], StringComparison.OrdinalIgnoreCase))
{
dependencyUpdater.Update(updaters, buildInfos);
}
else
{
dependencyUpdater.UpdateAndSubmitPullRequestAsync(updaters, buildInfos);
}
}
private static IEnumerable<IDependencyUpdater> GetUpdaters()
{
yield return CreateProjectJsonUpdater();
yield return CreateRegexUpdater(@"build_projects\shared-build-targets-utils\DependencyVersions.cs", "CoreCLRVersion", "Microsoft.NETCore.Runtime.CoreCLR");
yield return CreateRegexUpdater(@"build_projects\shared-build-targets-utils\DependencyVersions.cs", "JitVersion", "Microsoft.NETCore.Jit");
yield return CreateRegexUpdater(@"build_projects\dotnet-cli-build\CliDependencyVersions.cs", "SharedFrameworkVersion", "Microsoft.NETCore.App");
yield return CreateRegexUpdater(@"build_projects\dotnet-cli-build\CliDependencyVersions.cs", "HostFxrVersion", "Microsoft.NETCore.DotNetHostResolver");
yield return CreateRegexUpdater(@"build_projects\dotnet-cli-build\CliDependencyVersions.cs", "SharedHostVersion", "Microsoft.NETCore.DotNetHost");
}
private static IDependencyUpdater CreateProjectJsonUpdater()
{
const string noUpdateFileName = ".noautoupdate";
IEnumerable<string> projectJsonFiles = Enumerable.Union(
Directory.GetFiles(Dirs.RepoRoot, "project.json", SearchOption.AllDirectories),
Directory.GetFiles(Path.Combine(Dirs.RepoRoot, @"src\dotnet\commands\dotnet-new"), "project.json.template", SearchOption.AllDirectories))
.Where(p => !File.Exists(Path.Combine(Path.GetDirectoryName(p), noUpdateFileName)) &&
!Path.GetDirectoryName(p).EndsWith("CSharp_Web", StringComparison.Ordinal));
return new ProjectJsonUpdater(projectJsonFiles)
{
SkipStableVersions = false
};
}
private static IDependencyUpdater CreateRegexUpdater(string repoRelativePath, string dependencyPropertyName, string packageId)
{
return new FileRegexPackageUpdater()
{
Path = Path.Combine(Dirs.RepoRoot, repoRelativePath),
PackageId = packageId,
Regex = new Regex($@"{dependencyPropertyName} = ""(?<version>.*)"";"),
VersionGroupName = "version"
};
}
}
}