Fix update-dependencies to read all package versions from Latest_Packages.txt.
This commit is contained in:
parent
e27ef0f18c
commit
6fe3f86140
4 changed files with 69 additions and 56 deletions
|
@ -32,9 +32,15 @@ $env:PATH = "$env:DOTNET_INSTALL_DIR;$env:PATH"
|
|||
|
||||
$appPath = "$PSScriptRoot\update-dependencies"
|
||||
|
||||
# Restore the build scripts
|
||||
Write-Host "Restoring Build Script projects..."
|
||||
pushd $PSScriptRoot
|
||||
# Restore the build_projects
|
||||
Write-Host "Restoring Microsoft.DotNet.Cli.Build.Framework..."
|
||||
pushd $PSScriptRoot\..\build_projects\Microsoft.DotNet.Cli.Build.Framework
|
||||
dotnet restore --infer-runtimes
|
||||
if($LASTEXITCODE -ne 0) { throw "Failed to restore" }
|
||||
popd
|
||||
|
||||
# Restore update-dependencies
|
||||
pushd $appPath
|
||||
dotnet restore --infer-runtimes
|
||||
if($LASTEXITCODE -ne 0) { throw "Failed to restore" }
|
||||
popd
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace Microsoft.DotNet.Scripts
|
|||
///
|
||||
/// The following Environment Variables can optionally be specified:
|
||||
///
|
||||
/// COREFX_VERSION_URL - The Url to get the current CoreFx version. (ex. "https://raw.githubusercontent.com/dotnet/versions/master/build-info/dotnet/corefx/master/Latest.txt")
|
||||
/// COREFX_VERSION_URL - The Url to get the current CoreFx package versions. (ex. "https://raw.githubusercontent.com/dotnet/versions/master/build-info/dotnet/corefx/release/1.0.0/Latest_Packages.txt")
|
||||
/// GITHUB_ORIGIN_OWNER - The owner of the GitHub fork to push the commit and create the PR from. (ex. "dotnet-bot")
|
||||
/// GITHUB_UPSTREAM_OWNER - The owner of the GitHub base repo to create the PR to. (ex. "dotnet")
|
||||
/// GITHUB_PROJECT - The repo name under the ORIGIN and UPSTREAM owners. (ex. "cli")
|
||||
|
@ -33,7 +33,7 @@ namespace Microsoft.DotNet.Scripts
|
|||
private Lazy<string> _email = new Lazy<string>(() => GetEnvironmentVariable("GITHUB_EMAIL"));
|
||||
private Lazy<string> _password = new Lazy<string>(() => GetEnvironmentVariable("GITHUB_PASSWORD"));
|
||||
|
||||
private Lazy<string> _coreFxVersionUrl = new Lazy<string>(() => GetEnvironmentVariable("COREFX_VERSION_URL", "https://raw.githubusercontent.com/dotnet/versions/master/build-info/dotnet/corefx/master/Latest.txt"));
|
||||
private Lazy<string> _coreFxVersionUrl = new Lazy<string>(() => GetEnvironmentVariable("COREFX_VERSION_URL", "https://raw.githubusercontent.com/dotnet/versions/master/build-info/dotnet/corefx/release/1.0.0/Latest_Packages.txt"));
|
||||
private Lazy<string> _gitHubOriginOwner;
|
||||
private Lazy<string> _gitHubUpstreamOwner = new Lazy<string>(() => GetEnvironmentVariable("GITHUB_UPSTREAM_OWNER", "dotnet"));
|
||||
private Lazy<string> _gitHubProject = new Lazy<string>(() => GetEnvironmentVariable("GITHUB_PROJECT", "cli"));
|
||||
|
|
|
@ -1,15 +1,23 @@
|
|||
// 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.Collections.Generic;
|
||||
using NuGet.Versioning;
|
||||
|
||||
namespace Microsoft.DotNet.Scripts
|
||||
{
|
||||
public class DependencyInfo
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string IdPattern { get; set; }
|
||||
public string IdExclusionPattern { get; set; }
|
||||
public List<PackageInfo> NewVersions { get; set; }
|
||||
public string NewReleaseVersion { get; set; }
|
||||
|
||||
public bool IsUpdated { get; set; }
|
||||
}
|
||||
|
||||
public class PackageInfo
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public NuGetVersion Version { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ using System.Linq;
|
|||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.DotNet.Cli.Build.Framework;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
@ -28,24 +29,51 @@ namespace Microsoft.DotNet.Scripts
|
|||
[Target]
|
||||
public static BuildTargetResult GetDependencies(BuildTargetContext c)
|
||||
{
|
||||
string coreFxLkgVersion = s_client.GetStringAsync(Config.Instance.CoreFxVersionUrl).Result;
|
||||
coreFxLkgVersion = coreFxLkgVersion.Trim();
|
||||
|
||||
const string coreFxIdPattern = @"^(?i)((System\..*)|(NETStandard\.Library)|(Microsoft\.CSharp)|(Microsoft\.NETCore.*)|(Microsoft\.TargetingPack\.Private\.(CoreCLR|NETNative))|(Microsoft\.Win32\..*)|(Microsoft\.VisualBasic))$";
|
||||
const string coreFxIdExclusionPattern = @"System.CommandLine|Microsoft.NETCore.App";
|
||||
|
||||
List<DependencyInfo> dependencyInfos = c.GetDependencyInfos();
|
||||
dependencyInfos.Add(new DependencyInfo()
|
||||
{
|
||||
Name = "CoreFx",
|
||||
IdPattern = coreFxIdPattern,
|
||||
IdExclusionPattern = coreFxIdExclusionPattern,
|
||||
NewReleaseVersion = coreFxLkgVersion
|
||||
});
|
||||
|
||||
dependencyInfos.Add(CreateDependencyInfo("CoreFx", Config.Instance.CoreFxVersionUrl).Result);
|
||||
|
||||
return c.Success();
|
||||
}
|
||||
|
||||
private static async Task<DependencyInfo> CreateDependencyInfo(string name, string packageVersionsUrl)
|
||||
{
|
||||
List<PackageInfo> newPackageVersions = new List<PackageInfo>();
|
||||
|
||||
using (Stream versionsStream = await s_client.GetStreamAsync(packageVersionsUrl))
|
||||
using (StreamReader reader = new StreamReader(versionsStream))
|
||||
{
|
||||
string currentLine;
|
||||
while ((currentLine = await reader.ReadLineAsync()) != null)
|
||||
{
|
||||
int spaceIndex = currentLine.IndexOf(' ');
|
||||
|
||||
newPackageVersions.Add(new PackageInfo()
|
||||
{
|
||||
Id = currentLine.Substring(0, spaceIndex),
|
||||
Version = new NuGetVersion(currentLine.Substring(spaceIndex + 1))
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
string newReleaseVersion = newPackageVersions
|
||||
.Where(p => p.Version.IsPrerelease)
|
||||
.Select(p => p.Version.Release)
|
||||
.FirstOrDefault()
|
||||
??
|
||||
// if there are no prerelease versions, just grab the first version
|
||||
newPackageVersions
|
||||
.Select(p => p.Version.ToNormalizedString())
|
||||
.FirstOrDefault();
|
||||
|
||||
return new DependencyInfo()
|
||||
{
|
||||
Name = name,
|
||||
NewVersions = newPackageVersions,
|
||||
NewReleaseVersion = newReleaseVersion
|
||||
};
|
||||
}
|
||||
|
||||
[Target(nameof(ReplaceProjectJson), nameof(ReplaceCrossGen))]
|
||||
public static BuildTargetResult ReplaceVersions(BuildTargetContext c) => c.Success();
|
||||
|
||||
|
@ -103,52 +131,23 @@ namespace Microsoft.DotNet.Scripts
|
|||
string id = dependencyProperty.Name;
|
||||
foreach (DependencyInfo dependencyInfo in dependencyInfos)
|
||||
{
|
||||
if (Regex.IsMatch(id, dependencyInfo.IdPattern))
|
||||
foreach (PackageInfo packageInfo in dependencyInfo.NewVersions)
|
||||
{
|
||||
if (string.IsNullOrEmpty(dependencyInfo.IdExclusionPattern) || !Regex.IsMatch(id, dependencyInfo.IdExclusionPattern))
|
||||
if (id == packageInfo.Id)
|
||||
{
|
||||
string version;
|
||||
if (dependencyProperty.Value is JObject)
|
||||
{
|
||||
version = dependencyProperty.Value["version"].Value<string>();
|
||||
}
|
||||
else if (dependencyProperty.Value is JValue)
|
||||
{
|
||||
version = dependencyProperty.Value.ToString();
|
||||
dependencyProperty.Value["version"] = packageInfo.Version.ToNormalizedString();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Invalid package project.json version {dependencyProperty}");
|
||||
dependencyProperty.Value = packageInfo.Version.ToNormalizedString();
|
||||
}
|
||||
|
||||
VersionRange dependencyVersionRange = VersionRange.Parse(version);
|
||||
NuGetVersion dependencyVersion = dependencyVersionRange.MinVersion;
|
||||
// mark the DependencyInfo as updated so we can tell which dependencies were updated
|
||||
dependencyInfo.IsUpdated = true;
|
||||
|
||||
string newReleaseVersion = dependencyInfo.NewReleaseVersion;
|
||||
|
||||
if (!string.IsNullOrEmpty(dependencyVersion.Release) && dependencyVersion.Release != newReleaseVersion)
|
||||
{
|
||||
string newVersion = new NuGetVersion(
|
||||
dependencyVersion.Major,
|
||||
dependencyVersion.Minor,
|
||||
dependencyVersion.Patch,
|
||||
newReleaseVersion,
|
||||
dependencyVersion.Metadata).ToNormalizedString();
|
||||
|
||||
if (dependencyProperty.Value is JObject)
|
||||
{
|
||||
dependencyProperty.Value["version"] = newVersion;
|
||||
}
|
||||
else
|
||||
{
|
||||
dependencyProperty.Value = newVersion;
|
||||
}
|
||||
|
||||
// mark the DependencyInfo as updated so we can tell which dependencies were updated
|
||||
dependencyInfo.IsUpdated = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue