зеркало из
1
0
Форкнуть 0

Refactor update-dependencies to update the runtime Dockerfiles

This commit is contained in:
MichaelSimons 2017-03-24 22:06:30 -05:00 коммит произвёл Michael Simons
Родитель bf0a616486
Коммит d573bf009d
4 изменённых файлов: 118 добавлений и 18 удалений

Просмотреть файл

@ -0,0 +1,72 @@
// 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 System;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Net.Http;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace Dotnet.Docker.Nightly
{
public static class CliDependencyHelper
{
private static readonly Lazy<HttpClient> DownloadClient = new Lazy<HttpClient>();
public static string GetSharedFrameworkVersion(string cliVersion)
{
Trace.TraceInformation($"Looking for the Shared Framework CLI '{cliVersion}' depends on.");
string cliCommitHash = GetCommitHash(cliVersion);
XDocument depVersions = DownloadDependencyVersions(cliCommitHash).Result;
XNamespace msbuildNamespace = "http://schemas.microsoft.com/developer/msbuild/2003";
string sharedFrameworkVersion = depVersions.Document.Root
.Element(msbuildNamespace + "PropertyGroup")
?.Element(msbuildNamespace + "CLI_SharedFrameworkVersion")
?.Value;
if (sharedFrameworkVersion == null)
{
throw new InvalidOperationException("Can't find CLI_SharedFrameworkVersion in DependencyVersions.props.");
}
Trace.TraceInformation($"Detected Shared Framework version '{sharedFrameworkVersion}'.");
return sharedFrameworkVersion;
}
private static string GetCommitHash(string cliVersion)
{
using (ZipArchive archive = DownloadCliInstaller(cliVersion).Result)
{
ZipArchiveEntry versionTxtEntry = archive.GetEntry($"sdk/{cliVersion}/.version");
if (versionTxtEntry == null)
{
throw new InvalidOperationException("Can't find `.version` information in installer.");
}
using (Stream versionTxt = versionTxtEntry.Open())
using (var versionTxtReader = new StreamReader(versionTxt))
{
string commitHash = versionTxtReader.ReadLine();
Trace.TraceInformation($"Found commit hash '{commitHash}' in `.versions`.");
return commitHash;
}
}
}
private static async Task<XDocument> DownloadDependencyVersions(string cliHash)
{
string downloadUrl = $"https://raw.githubusercontent.com/dotnet-bot/cli/{cliHash}/build/DependencyVersions.props";
Stream stream = await DownloadClient.Value.GetStreamAsync(downloadUrl);
return XDocument.Load(stream);
}
private static async Task<ZipArchive> DownloadCliInstaller(string version)
{
string downloadUrl = $"https://dotnetcli.blob.core.windows.net/dotnet/Sdk/{version}/dotnet-dev-win-x64.{version}.zip";
Stream nupkgStream = await DownloadClient.Value.GetStreamAsync(downloadUrl);
return new ZipArchive(nupkgStream);
}
}
}

Просмотреть файл

@ -22,6 +22,7 @@ namespace Dotnet.Docker.Nightly
private Lazy<string[]> _gitHubPullRequestNotifications = new Lazy<string[]>(() =>
GetEnvironmentVariable("GITHUB_PULL_REQUEST_NOTIFICATIONS", "")
.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries));
private Lazy<string> _runtimeReleasePrefix = new Lazy<string>(() => Environment.GetEnvironmentVariable("RUNTIME_RELEASE_PREFIX"));
private Config()
{
@ -39,6 +40,7 @@ namespace Dotnet.Docker.Nightly
public string GitHubProject => _gitHubProject.Value;
public string GitHubUpstreamBranch => _gitHubUpstreamBranch.Value;
public string[] GitHubPullRequestNotifications => _gitHubPullRequestNotifications.Value;
public string RuntimeReleasePrefix => _runtimeReleasePrefix.Value ?? CliReleasePrefix;
private static string GetEnvironmentVariable(string name, string defaultValue = null)
{

Просмотреть файл

@ -16,6 +16,8 @@ namespace Dotnet.Docker.Nightly
{
public static class Program
{
private const string CliBuildInfoName = "Cli";
private const string SharedFrameworkBuildInfoName = "SharedFramework";
private static readonly string s_repoRoot = Directory.GetCurrentDirectory();
private static readonly Config s_config = Config.s_Instance;
private static bool s_updateOnly = false;
@ -34,7 +36,7 @@ namespace Dotnet.Docker.Nightly
}
}
}
private static bool ParseArgs(string[] args)
{
foreach (string arg in args)
@ -63,25 +65,35 @@ namespace Dotnet.Docker.Nightly
private static DependencyUpdateResults UpdateFiles()
{
// The BuildInfo does not contain the CLI product version, so the version is retrieved from a
// particular CLI package (e.g. Microsoft.DotNet.Cli.Utils). Once the BuildInfo includes the
// product version, it should be utilized.
//
// This app does not update the version of the .NET Core runtime/framework in the Dockerfiles
// because the infrastructure is not in place to retrieve the version on which the SDK depends.
// This version is infrequently updated, so this is acceptable for now, but once the
// infrastructure is in place, this app should update the runtime/framework version also.
// Ideally this logic would depend on the CLI produces and consumes metadata. Since it doesn't
// exist various version information is inspected to obtain the latest CLI version along with
// the runtime (e.g. shared framework) it depends on.
IEnumerable<BuildInfo> buildInfos = new[] { BuildInfo.Get("Cli", s_config.CliVersionUrl, fetchLatestReleaseFile: false) };
BuildInfo cliBuildInfo = BuildInfo.Get(CliBuildInfoName, s_config.CliVersionUrl, fetchLatestReleaseFile: false);
string sharedFrameworkVersion = CliDependencyHelper.GetSharedFrameworkVersion(
$"{s_config.RuntimeReleasePrefix}-{cliBuildInfo.LatestReleaseVersion}");
IEnumerable<DependencyBuildInfo> buildInfos = new[]
{
new DependencyBuildInfo(cliBuildInfo, false, Enumerable.Empty<string>()),
new DependencyBuildInfo(
new BuildInfo() {
Name = SharedFrameworkBuildInfoName,
LatestReleaseVersion = sharedFrameworkVersion,
LatestPackages = new Dictionary<string, string>()
},
false,
Enumerable.Empty<string>()),
};
IEnumerable<IDependencyUpdater> updaters = GetUpdaters();
DependencyUpdater updater = new DependencyUpdater();
return updater.Update(updaters, buildInfos);
return DependencyUpdateUtils.Update(updaters, buildInfos);
}
private static Task CreatePullRequest(DependencyUpdateResults updateResults)
{
string commitMessage = $"Update {s_config.BranchTagPrefix} SDK to {updateResults.UsedBuildInfos.Single().LatestReleaseVersion}";
string cliVersion = updateResults.UsedBuildInfos.First(bi => bi.Name == CliBuildInfoName).LatestReleaseVersion;
string commitMessage = $"Update {s_config.BranchTagPrefix} SDK to {s_config.CliReleasePrefix}-{cliVersion}";
GitHubAuth gitHubAuth = new GitHubAuth(s_config.Password, s_config.UserName, s_config.Email);
@ -98,11 +110,12 @@ namespace Dotnet.Docker.Nightly
private static IEnumerable<IDependencyUpdater> GetUpdaters()
{
return Directory.GetFiles(s_repoRoot, "Dockerfile", SearchOption.AllDirectories)
.Select(path => CreateDependencyUpdater(path));
string[] dockerfiles = Directory.GetFiles(s_repoRoot, "Dockerfile", SearchOption.AllDirectories);
return dockerfiles.Select(path => CreateSdkUpdater(path))
.Union(dockerfiles.Select(path => CreateRuntimeUpdater(path)));
}
private static IDependencyUpdater CreateDependencyUpdater(string path)
private static IDependencyUpdater CreateSdkUpdater(string path)
{
string versionRegex;
if (string.IsNullOrEmpty(s_config.CliReleaseMoniker))
@ -117,10 +130,21 @@ namespace Dotnet.Docker.Nightly
return new FileRegexReleaseUpdater()
{
Path = path,
BuildInfoName = "Cli",
BuildInfoName = CliBuildInfoName,
Regex = new Regex($"ENV DOTNET_SDK_VERSION {versionRegex}"),
VersionGroupName = "version"
};
}
private static IDependencyUpdater CreateRuntimeUpdater(string path)
{
return new FileRegexReleaseUpdater()
{
Path = path,
BuildInfoName = SharedFrameworkBuildInfoName,
Regex = new Regex($@"ENV DOTNET_VERSION (?<version>{s_config.RuntimeReleasePrefix}-[^\r\n]*)"),
VersionGroupName = "version"
};
}
}
}

Просмотреть файл

@ -6,7 +6,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.DotNet.VersionTools" Version="1.0.26-prerelease-00708-05" />
<PackageReference Include="Microsoft.DotNet.VersionTools" Version="1.0.27-prerelease-01428-01" />
<PackageReference Include="System.Diagnostics.TextWriterTraceListener" Version="4.0.0" />
<PackageReference Include="NuGet.Packaging.Core.Types" Version="4.0.0" />
<PackageReference Include="NuGet.Packaging" Version="4.0.0" />
</ItemGroup>
</Project>