diff --git a/_use-release-management.shade b/_use-release-management.shade index 66f0721f29..c25da8038d 100644 --- a/_use-release-management.shade +++ b/_use-release-management.shade @@ -101,20 +101,17 @@ -// 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 @{ + var koreBuildTag = GetEnvironmentParameter("KOREBUILD_TAG"); + var coherenceFeed = GetEnvironmentParameter("COHERENCE_FEED"); if (string.IsNullOrEmpty(coherenceFeed)) { 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."); - } - - 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"); + throw new Exception("KOREBUILD_TAG environment variable is not specified."); } var excludeReposForJson = new[] @@ -127,7 +124,7 @@ "libuv-build", }; - Exec("cmd", "/C dnu restore", @"tools\PinVersion"); + Exec("dotnet", "restore", "tools/PinVersion"); foreach (var repo in GetAllRepos()) { @@ -144,19 +141,33 @@ } 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) { var repoPath = Path.Combine(Directory.GetCurrentDirectory(), repo); - - Exec("dnx", - string.Format(@"run ""{0}"" ""{1}"" ""{2}""", - Path.Combine(Directory.GetCurrentDirectory(), repo), - coherenceFeed, - koreBuildVersion), - @"tools\PinVersion"); - - GitCommand(repo, "commit -am \"Updating json files to pin versions and build.cmd to pin KoreBuild and DNX\""); + try + { + GitCommand(repo, "commit -am \"Updating json files to pin versions and build files to pin KoreBuild\""); + } + catch + { + // Don't fail if there was nothing to add. + } } foreach (var repo in GetAllRepos()) @@ -170,6 +181,7 @@ #update-prerelease-tags -// Update tags on each repo to have the latest release tag @{ + var preReleaseTag = GetEnvironmentParameter("PRERELEASETAG"); if (string.IsNullOrEmpty(preReleaseTag)) { throw new Exception("PRERELEASETAG tag not defined"); @@ -180,6 +192,7 @@ foreach (var repo in GetAllRepos()) { GitCommand(repo, "pull --tags"); + string version = null; try { @@ -187,12 +200,15 @@ } catch { - Log.Warn(string.Format("{0} repo not tagged. Skipping....", repo)); - continue; + version = "1.0.0-" + preReleaseTag; + Log.Warn(string.Format("{0} repo not tagged. Using default version {1}.", repo, version)); } - var version = File.ReadAllText(versionFile); - File.Delete(versionFile); + if (version == null) + { + version = File.ReadAllText(versionFile); + File.Delete(versionFile); + } Log.Info(string.Format("Current version on repo {0} is {1}", repo, version)); diff --git a/build-template/NuGet.master.config b/build-template/NuGet.master.config new file mode 100644 index 0000000000..adbb3c1710 --- /dev/null +++ b/build-template/NuGet.master.config @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/makefile.shade b/makefile.shade index 5bccbf0454..64519d29ac 100644 --- a/makefile.shade +++ b/makefile.shade @@ -35,11 +35,8 @@ functions static string kBuildVersion = GetEnvironmentParameter("DNX_BUILD_VERSION"); static string ciVolatileShare = GetEnvironmentParameter("CI_VOLATILE_SHARE"); 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 nugetExe = GetEnvironmentParameter("PUSH_NUGET_EXE"); - static string preReleaseTag = GetEnvironmentParameter("PRERELEASETAG"); static string universeCommitsFile = GetEnvironmentParameter("UNIVERSE_COMMITS_FILE"); static bool skipNoCredentials = GetEnvironmentParameter("UNIVERSE_SKIP_NO_CREDENTIALS", value => value == "1"); static string repositoryInclude = GetEnvironmentParameter("KOREBUILD_REPOSITORY_INCLUDE"); diff --git a/tools/PinVersion/PinVersion.xproj b/tools/PinVersion/PinVersion.xproj index 98a40175b2..7e71282c55 100644 --- a/tools/PinVersion/PinVersion.xproj +++ b/tools/PinVersion/PinVersion.xproj @@ -9,9 +9,8 @@ 3d3b5750-0c24-4f1c-9304-b5e4d85cf5a0 PinVersion ..\artifacts\obj\$(MSBuildProjectName) - ..\artifacts\bin\$(MSBuildProjectName)\ + .\bin\ - 2.0 diff --git a/tools/PinVersion/Program.cs b/tools/PinVersion/Program.cs index f6c7ff1463..840f96e356 100644 --- a/tools/PinVersion/Program.cs +++ b/tools/PinVersion/Program.cs @@ -2,38 +2,56 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Concurrent; using System.IO; using System.Linq; +using System.Threading; +using System.Threading.Tasks; using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using NuGet; +using NuGet.Common; +using NuGet.Protocol.Core.Types; +using NuGet.Protocol.Core.v3; +using NuGet.Versioning; namespace PinVersion { public class Program { - public void Main(string[] args) + private static ConcurrentDictionary> _packageVersionLookup = + new ConcurrentDictionary>(StringComparer.OrdinalIgnoreCase); + + public static void Main(string[] args) { if (args.Length != 3) { - Console.Error.WriteLine("Usage "); + Console.Error.WriteLine("Usage "); } - var repositoryPath = args[0]; - var packageSource = args[1]; - var korebuildVersion = args[2]; + var packageSource = args[0]; + var korebuildTag = args[1]; - 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(); // Pin project.json files foreach (var file in Directory.EnumerateFiles(repositoryPath, "project.json", SearchOption.AllDirectories)) { var projectJson = JObject.Parse(File.ReadAllText(file)); - var directoryName = Path.GetFileName(Path.GetDirectoryName(file)); - var latestPackage = packageRepository.FindPackage(directoryName); - if (latestPackage != null) + var projectName = Path.GetFileName(Path.GetDirectoryName(file)); + var latestPackageVersion = await GetOrAddVersion(metadataResource, projectName); + if (latestPackageVersion != null) { - ((JValue)projectJson["version"]).Value = latestPackage.Version.ToNormalizedString(); + ((JValue)projectJson["version"]).Value = latestPackageVersion.ToNormalizedString(); } var frameworkDependencies = projectJson["frameworks"] @@ -47,19 +65,19 @@ namespace PinVersion foreach (var dependency in dependencies) { - latestPackage = packageRepository.FindPackage(dependency.Name); - if (latestPackage != null) + latestPackageVersion = await GetOrAddVersion(metadataResource, dependency.Name); + if (latestPackageVersion != null) { if (dependency.Value.Type == JTokenType.Object) { // "key": { "version": "1.0.0-*", "type": "build" } var value = (JObject)dependency.Value; - value["version"] = latestPackage.Version.ToNormalizedString(); + value["version"] = latestPackageVersion.ToNormalizedString(); } else { // "key": "version" - dependency.Value = latestPackage.Version.ToNormalizedString(); + dependency.Value = latestPackageVersion.ToNormalizedString(); } } } @@ -70,51 +88,38 @@ namespace PinVersion fileWriter.Indentation = 2; 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 - //TODO: handle build.sh files too - var dnxPackageName = "dnx-clr-win-x86"; - var dnxPackage = packageRepository.FindPackage(dnxPackageName); - if (dnxPackage == null) + private static Task GetOrAddVersion(MetadataResource resource, string packageId) + { + return _packageVersionLookup.GetOrAdd(packageId, id => { - throw new InvalidOperationException( - $"Could not find the DNX package with name '{dnxPackageName}' to " + - "pin the build script"); - } - - var buildCmdFiles = Directory.GetFiles(repositoryPath, "build.cmd", SearchOption.TopDirectoryOnly); - 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); - } + return resource.GetLatestVersion( + packageId, + includePrerelease: true, + includeUnlisted: false, + log: NullLogger.Instance, + token: default(CancellationToken)); + }); } } } diff --git a/tools/PinVersion/project.json b/tools/PinVersion/project.json index 99aed69ada..c3eb212f02 100644 --- a/tools/PinVersion/project.json +++ b/tools/PinVersion/project.json @@ -1,15 +1,13 @@ { - "version": "1.0.0-*", - "dependencies": { - "Newtonsoft.Json": "8.0.2", - "NuGet.Core": "2.8.6" - }, - - "commands": { - "PinVersion": "PinVersion" - }, - - "frameworks": { - "dnx451": { } - } + "version": "1.0.0-*", + "buildOptions": { + "emitEntryPoint": true + }, + "dependencies": { + "Newtonsoft.Json": "8.0.3", + "NuGet.Protocol.Core.v3": "3.5.0-beta-final" + }, + "frameworks": { + "net451": { } + } }