Change pin-version to use the coherence build results

Fies #247
This commit is contained in:
Pranav K 2015-07-20 10:23:55 -07:00
parent 14b08da4f3
commit 8271552cc6
6 changed files with 175 additions and 89 deletions

1
.gitignore vendored
View File

@ -15,3 +15,4 @@ StyleCop.Cache
node_modules node_modules
*.snk *.snk
.nuget/NuGet.exe .nuget/NuGet.exe
project.lock.json

View File

@ -223,12 +223,12 @@ var buildTarget = "compile"
-// 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
@{ @{
// NOTE: Before running update the below monikers as needed var coherenceFeed = Environment.GetEnvironmentVariable("COHERENCE_FEED");
var branch = Environment.GetEnvironmentVariable("BUILD_BRANCH"); if (string.IsNullOrEmpty(coherenceFeed))
var stableBranches = new[] {"master"}; {
throw new Exception("COHERENCE_FEED not specified. Usually this is Packages-NoTimestamp directory of Coherence-Signed.");
}
var oldPreRelease = Environment.GetEnvironmentVariable("OLD_RELEASE");
var newPreRelease = Environment.GetEnvironmentVariable("NEW_RELEASE");
var excludeReposForJson = new[] var excludeReposForJson = new[]
{ {
"Coherence", "Coherence",
@ -237,68 +237,23 @@ var buildTarget = "compile"
"Entropy" "Entropy"
}; };
var oldCoreCLRBuild = Environment.GetEnvironmentVariable("CORECLR_RELEASE_BUILD_OLD"); var repos = GetAllRepos().Except(excludeReposForJson);
var newCoreCLRBuild = Environment.GetEnvironmentVariable("CORECLR_RELEASE_BUILD_NEW"); Parallel.ForEach(repos, CloneOrUpdate);
var oldCoreCLRPrerelease = Environment.GetEnvironmentVariable("OLD_CORECLR_RELEASE");
var newCoreCLRPrerelease = Environment.GetEnvironmentVariable("NEW_CORECLR_RELEASE");
var oldRoslynPrerelease = Environment.GetEnvironmentVariable("OLD_ROSLYN_RELEASE"); foreach (var repo in repos)
var newRoslynPrerelease = Environment.GetEnvironmentVariable("NEW_ROSLYN_RELEASE");
foreach (var repo in GetAllRepos().Except(excludeReposForJson))
{ {
CloneOrUpdate(repo); GitCommand(repo, "checkout master");
GitCommand(repo, string.Format("checkout {0}", branch)); if (File.Exists(Path.Combine(repo, "build.cmd")))
if(File.Exists(Path.Combine(repo, "build.cmd")))
{ {
File.Copy(Path.Combine("build-template", "build.cmd"), File.Copy(Path.Combine("build-template", "build.cmd"),
Path.Combine(repo, "build.cmd"), Path.Combine(repo, "build.cmd"),
overwrite: true); overwrite: true);
} }
// Process project.json files to pin version numbers var repoPath = Path.Combine(Directory.GetCurrentDirectory(), repo);
// Replace version in project.json
foreach(var file in Directory.GetFiles(repo,"project.json", SearchOption.AllDirectories))
{
var builder = new StringBuilder();
var contents = File.ReadAllLines(file);
foreach(var jsonEntry in contents) Exec("dnx", string.Format(@".\tools\PinVersion run ""{0}"" ""{1}""", repo, coherenceFeed), string.Empty);
{
if(jsonEntry.Contains("\"System.") || jsonEntry.Contains("CSharp"))
{
var oldSearchExp = BuildVersionExpression(branch, oldCoreCLRPrerelease, oldCoreCLRBuild);
var newReplaceExp = BuildVersionExpression(branch, newCoreCLRPrerelease, newCoreCLRBuild);
builder.AppendLine(jsonEntry.Replace(oldSearchExp, newReplaceExp));
}
else if(jsonEntry.Contains("CodeAnalysis."))
{
var oldSearchExp = BuildVersionExpression(branch, oldRoslynPrerelease);
var newReplaceExp = BuildVersionExpression(branch, newRoslynPrerelease);
builder.AppendLine(jsonEntry.Replace(oldSearchExp, newReplaceExp));
}
else if(jsonEntry.Contains("IdentityModel"))
{
// IdentityModel packages don't have a stable build and are updated very frequently on the NuGet feed
builder.AppendLine(jsonEntry);
}
else
{
var oldSearchExp = BuildVersionExpression(branch, oldPreRelease);
var newReplaceExp = BuildVersionExpression(branch, newPreRelease);
var newEntry = ProcessExcludesForPackages(jsonEntry, stableBranches.Contains(branch));
builder.AppendLine(newEntry.Replace(oldSearchExp, newReplaceExp));
}
}
File.WriteAllText(file, builder.ToString());
}
// Build projects to produce project.lock.json // Build projects to produce project.lock.json
Exec("build.cmd", "compile", repo); Exec("build.cmd", "compile", repo);
@ -325,7 +280,7 @@ var buildTarget = "compile"
GitCommand(repo, "commit -am \"Updating json files to pin versions and build.cmd to pin KoreBuild and DNX\""); GitCommand(repo, "commit -am \"Updating json files to pin versions and build.cmd to pin KoreBuild and DNX\"");
GitCommand(repo, string.Format("push origin {0}:{0} -f", branch)); GitCommand(repo, "push origin master:master -f");
} }
} }

22
tools/PinVersion.sln Normal file
View File

@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "PinVersion", "PinVersion\PinVersion.xproj", "{3D3B5750-0C24-4F1C-9304-B5E4D85CF5A0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3D3B5750-0C24-4F1C-9304-B5E4D85CF5A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3D3B5750-0C24-4F1C-9304-B5E4D85CF5A0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3D3B5750-0C24-4F1C-9304-B5E4D85CF5A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3D3B5750-0C24-4F1C-9304-B5E4D85CF5A0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>3d3b5750-0c24-4f1c-9304-b5e4d85cf5a0</ProjectGuid>
<RootNamespace>PinVersion</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

View File

@ -0,0 +1,74 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.IO;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NuGet;
namespace PinVersion
{
public class Program
{
public void Main(string[] args)
{
if (args.Length != 2)
{
Console.Error.WriteLine("Usage <repository-path> <package source>");
}
var repositoryPath = args[0];
var packageSource = args[1];
var packageRepository = PackageRepositoryFactory.Default.CreateRepository(packageSource);
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)
{
((JValue)projectJson["version"]).Value = latestPackage.Version.ToNormalizedString();
}
var frameworkDependencies = projectJson["frameworks"]
?.Cast<JProperty>()
?.Select(f => ((JObject)f.Value)["dependencies"])
?? Enumerable.Empty<JToken>();
var dependencies = Enumerable.Concat(new[] { projectJson["dependencies"] }, frameworkDependencies)
.Where(d => d != null)
.SelectMany(d => d)
.Cast<JProperty>();
foreach (var dependency in dependencies)
{
latestPackage = packageRepository.FindPackage(dependency.Name);
if (latestPackage != null)
{
if (dependency.Value.Type == JTokenType.Object)
{
// "key": { "version": "1.0.0-*", "type": "build" }
var value = (JObject)dependency.Value;
value["version"] = latestPackage.Version.ToNormalizedString();
}
else
{
// "key": "version"
dependency.Value = latestPackage.Version.ToNormalizedString();
}
}
}
using (var fileWriter = new JsonTextWriter(new StreamWriter(file)))
{
fileWriter.Formatting = Formatting.Indented;
fileWriter.Indentation = 4;
projectJson.WriteTo(fileWriter);
}
}
}
}
}

View File

@ -0,0 +1,15 @@
{
"version": "1.0.0-*",
"dependencies": {
"Newtonsoft.Json": "6.0.8",
"NuGet.Core": "2.8.6"
},
"commands": {
"PinVersion": "PinVersion"
},
"frameworks": {
"dnx451": { }
}
}