Update PinVersion tool use dotnet and v3 NuGet packages
This commit is contained in:
parent
6307533967
commit
0e4d154134
|
|
@ -101,20 +101,17 @@
|
||||||
-// Pin versions of packages in project.json and updated project.lock.json
|
-// Pin versions of packages in project.json and updated project.lock.json
|
||||||
-// More information https://github.com/aspnet/Universe/wiki/%23pin-version-:-Pinning-package-version-for-a-particular-release-in-project.json
|
-// More information https://github.com/aspnet/Universe/wiki/%23pin-version-:-Pinning-package-version-for-a-particular-release-in-project.json
|
||||||
@{
|
@{
|
||||||
|
var koreBuildTag = GetEnvironmentParameter("KOREBUILD_TAG");
|
||||||
|
var coherenceFeed = GetEnvironmentParameter("COHERENCE_FEED");
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(coherenceFeed))
|
if (string.IsNullOrEmpty(coherenceFeed))
|
||||||
{
|
{
|
||||||
throw new Exception("COHERENCE_FEED not specified. Usually this is Packages-NoTimestamp directory of Coherence-Signed.");
|
throw new Exception("COHERENCE_FEED not specified. Usually this is Packages-NoTimestamp directory of Coherence-Signed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(koreBuildVersion))
|
if (string.IsNullOrEmpty(koreBuildTag))
|
||||||
{
|
{
|
||||||
throw new Exception("KOREBUILD_VERSION environment variable is not specified.");
|
throw new Exception("KOREBUILD_TAG environment variable is not specified.");
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(nugetVersion))
|
|
||||||
{
|
|
||||||
throw new Exception("NUGET_VERSION not specified. This is most recent stable build of NuGet from http://dist.nuget.org/index.html. e.g. v3.2");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var excludeReposForJson = new[]
|
var excludeReposForJson = new[]
|
||||||
|
|
@ -127,7 +124,7 @@
|
||||||
"libuv-build",
|
"libuv-build",
|
||||||
};
|
};
|
||||||
|
|
||||||
Exec("cmd", "/C dnu restore", @"tools\PinVersion");
|
Exec("dotnet", "restore", "tools/PinVersion");
|
||||||
|
|
||||||
foreach (var repo in GetAllRepos())
|
foreach (var repo in GetAllRepos())
|
||||||
{
|
{
|
||||||
|
|
@ -144,19 +141,33 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
var reposToPin = GetAllRepos().Except(excludeReposForJson);
|
var reposToPin = GetAllRepos().Except(excludeReposForJson);
|
||||||
|
var repositoryNamesFile = Path.GetTempFileName();
|
||||||
|
|
||||||
|
File.WriteAllLines(repositoryNamesFile, reposToPin.Select(r => Path.Combine(Directory.GetCurrentDirectory(), r)));
|
||||||
|
var pinToolsArgs = string.Format(@"run -p tools/PinVersion ""{0}"" ""{1}"" ""{2}""",
|
||||||
|
coherenceFeed,
|
||||||
|
koreBuildTag,
|
||||||
|
repositoryNamesFile);
|
||||||
|
Exec("dotnet", pinToolsArgs, "");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File.Delete(repositoryNamesFile);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var repo in reposToPin)
|
foreach (var repo in reposToPin)
|
||||||
{
|
{
|
||||||
var repoPath = Path.Combine(Directory.GetCurrentDirectory(), repo);
|
var repoPath = Path.Combine(Directory.GetCurrentDirectory(), repo);
|
||||||
|
try
|
||||||
Exec("dnx",
|
{
|
||||||
string.Format(@"run ""{0}"" ""{1}"" ""{2}""",
|
GitCommand(repo, "commit -am \"Updating json files to pin versions and build files to pin KoreBuild\"");
|
||||||
Path.Combine(Directory.GetCurrentDirectory(), repo),
|
}
|
||||||
coherenceFeed,
|
catch
|
||||||
koreBuildVersion),
|
{
|
||||||
@"tools\PinVersion");
|
// Don't fail if there was nothing to add.
|
||||||
|
}
|
||||||
GitCommand(repo, "commit -am \"Updating json files to pin versions and build.cmd to pin KoreBuild and DNX\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var repo in GetAllRepos())
|
foreach (var repo in GetAllRepos())
|
||||||
|
|
@ -170,6 +181,7 @@
|
||||||
#update-prerelease-tags
|
#update-prerelease-tags
|
||||||
-// Update tags on each repo to have the latest release tag
|
-// Update tags on each repo to have the latest release tag
|
||||||
@{
|
@{
|
||||||
|
var preReleaseTag = GetEnvironmentParameter("PRERELEASETAG");
|
||||||
if (string.IsNullOrEmpty(preReleaseTag))
|
if (string.IsNullOrEmpty(preReleaseTag))
|
||||||
{
|
{
|
||||||
throw new Exception("PRERELEASETAG tag not defined");
|
throw new Exception("PRERELEASETAG tag not defined");
|
||||||
|
|
@ -180,6 +192,7 @@
|
||||||
foreach (var repo in GetAllRepos())
|
foreach (var repo in GetAllRepos())
|
||||||
{
|
{
|
||||||
GitCommand(repo, "pull --tags");
|
GitCommand(repo, "pull --tags");
|
||||||
|
string version = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -187,12 +200,15 @@
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
Log.Warn(string.Format("{0} repo not tagged. Skipping....", repo));
|
version = "1.0.0-" + preReleaseTag;
|
||||||
continue;
|
Log.Warn(string.Format("{0} repo not tagged. Using default version {1}.", repo, version));
|
||||||
}
|
}
|
||||||
|
|
||||||
var version = File.ReadAllText(versionFile);
|
if (version == null)
|
||||||
File.Delete(versionFile);
|
{
|
||||||
|
version = File.ReadAllText(versionFile);
|
||||||
|
File.Delete(versionFile);
|
||||||
|
}
|
||||||
|
|
||||||
Log.Info(string.Format("Current version on repo {0} is {1}", repo, version));
|
Log.Info(string.Format("Current version on repo {0} is {1}", repo, version));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<configuration>
|
||||||
|
<packageSources>
|
||||||
|
<clear />
|
||||||
|
<add key="AspNetVNext" value="https://www.myget.org/f/aspnetmaster/api/v3/index.json" />
|
||||||
|
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
|
||||||
|
</packageSources>
|
||||||
|
</configuration>
|
||||||
|
|
@ -35,11 +35,8 @@ functions
|
||||||
static string kBuildVersion = GetEnvironmentParameter("DNX_BUILD_VERSION");
|
static string kBuildVersion = GetEnvironmentParameter("DNX_BUILD_VERSION");
|
||||||
static string ciVolatileShare = GetEnvironmentParameter("CI_VOLATILE_SHARE");
|
static string ciVolatileShare = GetEnvironmentParameter("CI_VOLATILE_SHARE");
|
||||||
static string koreBuildTargets = GetEnvironmentParameter("KOREBUILD_BUILD_TARGETS");
|
static string koreBuildTargets = GetEnvironmentParameter("KOREBUILD_BUILD_TARGETS");
|
||||||
static string coherenceFeed = GetEnvironmentParameter("COHERENCE_FEED");
|
|
||||||
static string koreBuildVersion = GetEnvironmentParameter("KOREBUILD_VERSION");
|
|
||||||
static string nugetVersion = GetEnvironmentParameter("NUGET_VERSION");
|
static string nugetVersion = GetEnvironmentParameter("NUGET_VERSION");
|
||||||
static string nugetExe = GetEnvironmentParameter("PUSH_NUGET_EXE");
|
static string nugetExe = GetEnvironmentParameter("PUSH_NUGET_EXE");
|
||||||
static string preReleaseTag = GetEnvironmentParameter("PRERELEASETAG");
|
|
||||||
static string universeCommitsFile = GetEnvironmentParameter("UNIVERSE_COMMITS_FILE");
|
static string universeCommitsFile = GetEnvironmentParameter("UNIVERSE_COMMITS_FILE");
|
||||||
static bool skipNoCredentials = GetEnvironmentParameter("UNIVERSE_SKIP_NO_CREDENTIALS", value => value == "1");
|
static bool skipNoCredentials = GetEnvironmentParameter("UNIVERSE_SKIP_NO_CREDENTIALS", value => value == "1");
|
||||||
static string repositoryInclude = GetEnvironmentParameter("KOREBUILD_REPOSITORY_INCLUDE");
|
static string repositoryInclude = GetEnvironmentParameter("KOREBUILD_REPOSITORY_INCLUDE");
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,8 @@
|
||||||
<ProjectGuid>3d3b5750-0c24-4f1c-9304-b5e4d85cf5a0</ProjectGuid>
|
<ProjectGuid>3d3b5750-0c24-4f1c-9304-b5e4d85cf5a0</ProjectGuid>
|
||||||
<RootNamespace>PinVersion</RootNamespace>
|
<RootNamespace>PinVersion</RootNamespace>
|
||||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<SchemaVersion>2.0</SchemaVersion>
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
|
||||||
|
|
@ -2,38 +2,56 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using NuGet;
|
using NuGet.Common;
|
||||||
|
using NuGet.Protocol.Core.Types;
|
||||||
|
using NuGet.Protocol.Core.v3;
|
||||||
|
using NuGet.Versioning;
|
||||||
|
|
||||||
namespace PinVersion
|
namespace PinVersion
|
||||||
{
|
{
|
||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
public void Main(string[] args)
|
private static ConcurrentDictionary<string, Task<NuGetVersion>> _packageVersionLookup =
|
||||||
|
new ConcurrentDictionary<string, Task<NuGetVersion>>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
if (args.Length != 3)
|
if (args.Length != 3)
|
||||||
{
|
{
|
||||||
Console.Error.WriteLine("Usage <repository-path> <package source> <Korebuild Version>");
|
Console.Error.WriteLine("Usage <package source> <Korebuild Tag> <repository-names-file>");
|
||||||
}
|
}
|
||||||
|
|
||||||
var repositoryPath = args[0];
|
var packageSource = args[0];
|
||||||
var packageSource = args[1];
|
var korebuildTag = args[1];
|
||||||
var korebuildVersion = args[2];
|
|
||||||
|
|
||||||
var packageRepository = PackageRepositoryFactory.Default.CreateRepository(packageSource);
|
var repositoryNames = File.ReadAllLines(args[2]);
|
||||||
|
|
||||||
|
Task.WaitAll(repositoryNames
|
||||||
|
.Select(repositoryPath => ExecuteAsync(repositoryPath, packageSource, korebuildTag))
|
||||||
|
.ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task ExecuteAsync(string repositoryPath, string packageSource, string korebuildTag)
|
||||||
|
{
|
||||||
|
var packageRepository = Repository.Factory.GetCoreV3(packageSource);
|
||||||
|
var metadataResource = await packageRepository.GetResourceAsync<MetadataResource>();
|
||||||
|
|
||||||
// Pin project.json files
|
// Pin project.json files
|
||||||
foreach (var file in Directory.EnumerateFiles(repositoryPath, "project.json", SearchOption.AllDirectories))
|
foreach (var file in Directory.EnumerateFiles(repositoryPath, "project.json", SearchOption.AllDirectories))
|
||||||
{
|
{
|
||||||
var projectJson = JObject.Parse(File.ReadAllText(file));
|
var projectJson = JObject.Parse(File.ReadAllText(file));
|
||||||
var directoryName = Path.GetFileName(Path.GetDirectoryName(file));
|
var projectName = Path.GetFileName(Path.GetDirectoryName(file));
|
||||||
var latestPackage = packageRepository.FindPackage(directoryName);
|
var latestPackageVersion = await GetOrAddVersion(metadataResource, projectName);
|
||||||
if (latestPackage != null)
|
if (latestPackageVersion != null)
|
||||||
{
|
{
|
||||||
((JValue)projectJson["version"]).Value = latestPackage.Version.ToNormalizedString();
|
((JValue)projectJson["version"]).Value = latestPackageVersion.ToNormalizedString();
|
||||||
}
|
}
|
||||||
|
|
||||||
var frameworkDependencies = projectJson["frameworks"]
|
var frameworkDependencies = projectJson["frameworks"]
|
||||||
|
|
@ -47,19 +65,19 @@ namespace PinVersion
|
||||||
|
|
||||||
foreach (var dependency in dependencies)
|
foreach (var dependency in dependencies)
|
||||||
{
|
{
|
||||||
latestPackage = packageRepository.FindPackage(dependency.Name);
|
latestPackageVersion = await GetOrAddVersion(metadataResource, dependency.Name);
|
||||||
if (latestPackage != null)
|
if (latestPackageVersion != null)
|
||||||
{
|
{
|
||||||
if (dependency.Value.Type == JTokenType.Object)
|
if (dependency.Value.Type == JTokenType.Object)
|
||||||
{
|
{
|
||||||
// "key": { "version": "1.0.0-*", "type": "build" }
|
// "key": { "version": "1.0.0-*", "type": "build" }
|
||||||
var value = (JObject)dependency.Value;
|
var value = (JObject)dependency.Value;
|
||||||
value["version"] = latestPackage.Version.ToNormalizedString();
|
value["version"] = latestPackageVersion.ToNormalizedString();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// "key": "version"
|
// "key": "version"
|
||||||
dependency.Value = latestPackage.Version.ToNormalizedString();
|
dependency.Value = latestPackageVersion.ToNormalizedString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -70,51 +88,38 @@ namespace PinVersion
|
||||||
fileWriter.Indentation = 2;
|
fileWriter.Indentation = 2;
|
||||||
projectJson.WriteTo(fileWriter);
|
projectJson.WriteTo(fileWriter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update KoreBuild path
|
||||||
|
|
||||||
|
var buildFiles = new[] { "build.ps1", "build.sh" };
|
||||||
|
foreach (var buildFile in buildFiles)
|
||||||
|
{
|
||||||
|
var buildFilePath = Path.Combine(repositoryPath, buildFile);
|
||||||
|
if (File.Exists(buildFilePath))
|
||||||
|
{
|
||||||
|
var content = File.ReadAllText(buildFilePath);
|
||||||
|
var replaced = content.Replace("KoreBuild/archive/release.zip", $"KoreBuild/archive/{korebuildTag}.zip");
|
||||||
|
|
||||||
|
if (content != replaced)
|
||||||
|
{
|
||||||
|
File.WriteAllText(buildFilePath, replaced);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Pin the build scripts
|
private static Task<NuGetVersion> GetOrAddVersion(MetadataResource resource, string packageId)
|
||||||
//TODO: handle build.sh files too
|
{
|
||||||
var dnxPackageName = "dnx-clr-win-x86";
|
return _packageVersionLookup.GetOrAdd(packageId, id =>
|
||||||
var dnxPackage = packageRepository.FindPackage(dnxPackageName);
|
|
||||||
if (dnxPackage == null)
|
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(
|
return resource.GetLatestVersion(
|
||||||
$"Could not find the DNX package with name '{dnxPackageName}' to " +
|
packageId,
|
||||||
"pin the build script");
|
includePrerelease: true,
|
||||||
}
|
includeUnlisted: false,
|
||||||
|
log: NullLogger.Instance,
|
||||||
var buildCmdFiles = Directory.GetFiles(repositoryPath, "build.cmd", SearchOption.TopDirectoryOnly);
|
token: default(CancellationToken));
|
||||||
if (buildCmdFiles == null || buildCmdFiles.Length == 0)
|
});
|
||||||
{
|
|
||||||
throw new InvalidOperationException($"No build.cmd files found at {repositoryPath}");
|
|
||||||
}
|
|
||||||
|
|
||||||
var buildCmdFile = buildCmdFiles[0];
|
|
||||||
var buildCmdFileContent = File.ReadAllText(buildCmdFile);
|
|
||||||
buildCmdFileContent = buildCmdFileContent.Replace(
|
|
||||||
"SET BUILDCMD_KOREBUILD_VERSION=\"\"",
|
|
||||||
$"SET BUILDCMD_KOREBUILD_VERSION={korebuildVersion}");
|
|
||||||
buildCmdFileContent = buildCmdFileContent.Replace(
|
|
||||||
"SET BUILDCMD_DNX_VERSION=\"\"",
|
|
||||||
$"SET BUILDCMD_DNX_VERSION={dnxPackage.Version.ToNormalizedString()}");
|
|
||||||
|
|
||||||
// Replace all content of the file
|
|
||||||
File.WriteAllText(buildCmdFile, buildCmdFileContent);
|
|
||||||
|
|
||||||
// Pin the global.json
|
|
||||||
var globalJsonPath = Path.Combine(repositoryPath, "global.json");
|
|
||||||
var globalJson = JObject.Parse(File.ReadAllText(globalJsonPath));
|
|
||||||
globalJson["sdk"] = new JObject
|
|
||||||
{
|
|
||||||
["version"] = dnxPackage.Version.ToNormalizedString()
|
|
||||||
};
|
|
||||||
|
|
||||||
using (var fileWriter = new JsonTextWriter(new StreamWriter(globalJsonPath)))
|
|
||||||
{
|
|
||||||
fileWriter.Formatting = Formatting.Indented;
|
|
||||||
fileWriter.Indentation = 2;
|
|
||||||
globalJson.WriteTo(fileWriter);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,13 @@
|
||||||
{
|
{
|
||||||
"version": "1.0.0-*",
|
"version": "1.0.0-*",
|
||||||
"dependencies": {
|
"buildOptions": {
|
||||||
"Newtonsoft.Json": "8.0.2",
|
"emitEntryPoint": true
|
||||||
"NuGet.Core": "2.8.6"
|
},
|
||||||
},
|
"dependencies": {
|
||||||
|
"Newtonsoft.Json": "8.0.3",
|
||||||
"commands": {
|
"NuGet.Protocol.Core.v3": "3.5.0-beta-final"
|
||||||
"PinVersion": "PinVersion"
|
},
|
||||||
},
|
"frameworks": {
|
||||||
|
"net451": { }
|
||||||
"frameworks": {
|
}
|
||||||
"dnx451": { }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue