Cleaning up makefile.shade

This commit is contained in:
Pranav K 2016-03-24 16:54:45 -07:00
parent 300078b448
commit fad42eacea
22 changed files with 192 additions and 1180 deletions

View File

@ -0,0 +1,191 @@
#update-release
-// Merge dev branch to release
@{
Parallel.ForEach(GetAllRepos(), CloneOrUpdate);
Log.Info("************************************* Checking repos for diffs *************************");
foreach (var repo in GetAllRepos())
{
Log.Info("Checking repo: " + repo);
// Check if the repo previously had a release branch
try
{
GitCommand(repo, "rev-parse --verify --quiet origin/release");
}
catch
{
Log.Info("Repository " + repo + " does not have a release branch.");
continue;
}
try
{
GitCommand(repo, "log -1 --exit-code origin/dev..origin/release");
}
catch
{
Log.Warn("Unmerged changes in repository " + repo);
GitCommand(repo, "log origin/dev..origin/release");
throw;
}
}
Log.Info("No conflicts in repos, continuing with creating release branch.");
foreach (var repo in GetAllRepos())
{
GitCommand(repo, "checkout origin/dev -B release");
// Update NuGet.Config
var nugetConfigPath = Path.Combine(repo, "NuGet.config");
if (File.Exists(nugetConfigPath))
{
var original = File.ReadAllText(nugetConfigPath);
var modified = original
.Replace("https://www.myget.org/F/aspnetcidev", "https://www.myget.org/F/aspnetcirelease")
.Replace("https://www.myget.org/F/azureadwebstacknightly", "https://www.myget.org/F/azureadwebstackrelease");
if (!string.Equals(original, modified, StringComparison.Ordinal))
{
File.WriteAllText(nugetConfigPath, modified);
GitCommand(repo, "add NuGet.config");
GitCommand(repo, "commit -m \"Updating to release NuGet.config.\"");
}
}
GitCommand(repo, "push origin release:release");
GitCommand(repo, "checkout origin/dev -B dev");
GitCommand(repo, "merge release -s ours");
GitCommand(repo, "push origin dev:dev");
}
}
#update-master .pull-all
-// Merge release branch to master
-// 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
@{
if (string.IsNullOrEmpty(coherenceFeed))
{
throw new Exception("COHERENCE_FEED not specified. Usually this is Packages-NoTimestamp directory of Coherence-Signed.");
}
if (string.IsNullOrEmpty(koreBuildVersion))
{
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");
}
var excludeReposForJson = new[]
{
"Coherence",
"Coherence-Signed",
"dnvm",
"Entropy",
"Setup",
"libuv-build",
};
Exec("cmd", "/C dnu restore", @"tools\PinVersion");
foreach (var repo in GetAllRepos())
{
GitCommand(repo, "checkout origin/release -B master");
if (File.Exists(Path.Combine(repo, "NuGet.config")))
{
File.Copy(Path.Combine("build-template", "NuGet.master.config"),
Path.Combine(repo, "NuGet.config"),
overwrite: true);
GitCommand(repo, "add NuGet.*");
GitCommand(repo, "commit -m \"Updating NuGet.config\"");
}
}
var reposToPin = GetAllRepos().Except(excludeReposForJson);
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\"");
}
foreach (var repo in GetAllRepos())
{
GitCommand(repo, "push origin +master:master");
}
CallTarget("update-prerelease-tags");
}
#update-prerelease-tags
-// Update tags on each repo to have the latest release tag
@{
if (string.IsNullOrEmpty(preReleaseTag))
{
throw new Exception("PRERELEASETAG tag not defined");
}
var versionFile = "version.txt";
foreach (var repo in GetAllRepos())
{
GitCommand(repo, "pull --tags");
try
{
GitCommand(repo, string.Format("describe --tags > ..\\{0}", versionFile));
}
catch
{
Log.Warn(string.Format("{0} repo not tagged. Skipping....", repo));
continue;
}
var version = File.ReadAllText(versionFile);
File.Delete(versionFile);
Log.Info(string.Format("Current version on repo {0} is {1}", repo, version));
var majorVersion = version.Split(new string[]{"-"}, StringSplitOptions.None)[0];
var newVersion = majorVersion + string.Format("-{0}", preReleaseTag);
Log.Info(string.Format("New version for repo is {0}", newVersion));
GitCommand(repo, string.Format("tag -f -a {0} -m \"Tag for new release {0}\"", newVersion));
GitCommand(repo, "push origin --tags +" + newVersion);
}
}
functions
@{
IEnumerable<string> GetAllRepos()
{
var nonDefaultRepos = new[]
{
"DNX",
"Coherence",
"Coherence-Signed",
"dnvm",
"Setup",
};
return Enumerable.Concat(nonDefaultRepos, repositories);
}
}

View File

@ -2,6 +2,7 @@
var VERSION='0.2.1'
use-ci-loggers
use-release-management
use namespace='System'
use namespace='System.IO'
use namespace='System.Collections.Concurrent'
@ -322,184 +323,11 @@ var buildTarget = "compile"
}
}
#update-release
-// Merge dev branch to release
@{
Parallel.ForEach(GetAllRepos(), CloneOrUpdate);
Log.Info("************************************* Checking repos for diffs *************************");
foreach (var repo in GetAllRepos())
{
Log.Info("Checking repo: " + repo);
// Check if the repo previously had a release branch
try
{
GitCommand(repo, "rev-parse --verify --quiet origin/release");
}
catch
{
Log.Info("Repository " + repo + " does not have a release branch.");
continue;
}
try
{
GitCommand(repo, "log -1 --exit-code origin/dev..origin/release");
}
catch
{
Log.Warn("Unmerged changes in repository " + repo);
GitCommand(repo, "log origin/dev..origin/release");
throw;
}
}
Log.Info("No conflicts in repos, continuing with creating release branch.");
foreach (var repo in GetAllRepos())
{
GitCommand(repo, "checkout origin/dev -B release");
// Update NuGet.Config
var nugetConfigPath = Path.Combine(repo, "NuGet.config");
if (File.Exists(nugetConfigPath))
{
var original = File.ReadAllText(nugetConfigPath);
var modified = original
.Replace("https://www.myget.org/F/aspnetcidev", "https://www.myget.org/F/aspnetcirelease")
.Replace("https://www.myget.org/F/azureadwebstacknightly", "https://www.myget.org/F/azureadwebstackrelease");
if (!string.Equals(original, modified, StringComparison.Ordinal))
{
File.WriteAllText(nugetConfigPath, modified);
GitCommand(repo, "add NuGet.config");
GitCommand(repo, "commit -m \"Updating to release NuGet.config.\"");
}
}
GitCommand(repo, "push origin release:release");
GitCommand(repo, "checkout origin/dev -B dev");
GitCommand(repo, "merge release -s ours");
GitCommand(repo, "push origin dev:dev");
}
}
#pull-all
-Parallel.ForEach(GetAllRepos(), CloneOrUpdate);
#update-master .pull-all
-// Merge release branch to master
-// 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
@{
if (string.IsNullOrEmpty(coherenceFeed))
{
throw new Exception("COHERENCE_FEED not specified. Usually this is Packages-NoTimestamp directory of Coherence-Signed.");
}
if (string.IsNullOrEmpty(koreBuildVersion))
{
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");
}
var excludeReposForJson = new[]
{
"Coherence",
"Coherence-Signed",
"dnvm",
"Entropy",
"Setup",
"libuv-build",
};
Exec("cmd", "/C dnu restore", @"tools\PinVersion");
foreach (var repo in GetAllRepos())
{
GitCommand(repo, "checkout origin/release -B master");
if (File.Exists(Path.Combine(repo, "NuGet.config")))
{
File.Copy(Path.Combine("build-template", "NuGet.master.config"),
Path.Combine(repo, "NuGet.config"),
overwrite: true);
GitCommand(repo, "add NuGet.*");
GitCommand(repo, "commit -m \"Updating NuGet.config\"");
}
}
var reposToPin = GetAllRepos().Except(excludeReposForJson);
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\"");
}
foreach (var repo in GetAllRepos())
{
GitCommand(repo, "push origin +master:master");
}
CallTarget("update-prerelease-tags");
}
#update-prerelease-tags
-// Update tags on each repo to have the latest release tag
@{
if (string.IsNullOrEmpty(preReleaseTag))
{
throw new Exception("PRERELEASETAG tag not defined");
}
var versionFile = "version.txt";
foreach (var repo in GetAllRepos())
{
GitCommand(repo, "pull --tags");
try
{
GitCommand(repo, string.Format("describe --tags > ..\\{0}", versionFile));
}
catch
{
Log.Warn(string.Format("{0} repo not tagged. Skipping....", repo));
continue;
}
var version = File.ReadAllText(versionFile);
File.Delete(versionFile);
Log.Info(string.Format("Current version on repo {0} is {1}", repo, version));
var majorVersion = version.Split(new string[]{"-"}, StringSplitOptions.None)[0];
var newVersion = majorVersion + string.Format("-{0}", preReleaseTag);
Log.Info(string.Format("New version for repo is {0}", newVersion));
GitCommand(repo, string.Format("tag -f -a {0} -m \"Tag for new release {0}\"", newVersion));
GitCommand(repo, "push origin --tags +" + newVersion);
}
}
#only-compile .build-all
-Log.Warn("only-compile target is deprecated. Use build-all");
@ -624,15 +452,6 @@ var buildTarget = "compile"
}
}
#run-snapshot-manager
@{
Exec(@".nuget\nuget.exe", @"restore -out packages tools\TCDependencyManager\packages.config", "");
var programFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
var msbuildPath = Path.Combine(programFiles, "MSBuild", "12.0", "Bin", "MsBuild.exe");
Exec(msbuildPath, "TCDependencyManager.csproj", @"tools\TCDependencyManager");
Exec(@"tools\TCDependencyManager\bin\Debug\TCDependencyManager.exe", "", "");
}
#git-status description='Show status of repos known by Universe'
@{
foreach(var repo in repositories)
@ -797,20 +616,6 @@ functions
return true;
}
IEnumerable<string> GetAllRepos()
{
var nonDefaultRepos = new[]
{
"DNX",
"Coherence",
"Coherence-Signed",
"dnvm",
"Setup",
};
return Enumerable.Concat(nonDefaultRepos, repositories);
}
void RemoveSrcFolder(string repo)
{
var srcDir = Path.Combine(repo, "src");
@ -868,34 +673,6 @@ functions
.Replace("]", "|]");
}
// Create a search replace expression based on branch, prerelease tag and buildNumber
string BuildVersionExpression(string branch, string preRelease = "", string buildNumber = "")
{
var stableBranches = new[] {"master"};
var builder = new StringBuilder();
// Add pre release version tag
if(!String.IsNullOrEmpty(preRelease))
{
builder.Append("-");
builder.Append(preRelease);
}
// If buildnumber is provided, append.
// This for CORE CLR packages
if(!String.IsNullOrEmpty(buildNumber))
{
builder.Append("-");
builder.Append(buildNumber);
}
else if(!stableBranches.Contains(branch))
{
builder.Append("-*");
}
return builder.ToString();
}
static IEnumerable<string> GetRepositoriesToBuild()
{
IEnumerable<string> reposToBuild = new HashSet<string>(StringComparer.OrdinalIgnoreCase) {

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
</configuration>

View File

@ -1,129 +0,0 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.ServiceProcess;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualBasic.Logging;
using NuGet;
namespace NuGetClone
{
public class MyService : ServiceBase
{
private static readonly Uri DeveloperFeed = new Uri("https://www.myget.org/F/aspnetvnext/api/v2");
private static readonly ICredentials _credentials = new NetworkCredential("aspnetreadonly", "4d8a2d9c-7b80-4162-9978-47e918c9658c");
private Timer _timer;
private string _targetDirectory;
protected override void OnStart(string[] args)
{
base.OnStart(args);
Init();
_timer = new Timer(Run, null, TimeSpan.FromSeconds(1), TimeSpan.FromMinutes(2));
}
public void Init()
{
_targetDirectory = Environment.GetEnvironmentVariable("PROJECTK_PACKAGE_CACHE");
if (string.IsNullOrEmpty(_targetDirectory))
{
_targetDirectory = @"c:\projectk-cache";
}
var fileTraceListener = new FileLogTraceListener
{
AutoFlush = true,
Location = LogFileLocation.Custom,
CustomLocation = _targetDirectory,
BaseFileName = "ProjectKClone",
TraceOutputOptions = TraceOptions.DateTime,
LogFileCreationSchedule = LogFileCreationScheduleOption.Weekly
};
Trace.Listeners.Add(fileTraceListener);
}
public void Run(object state)
{
try
{
RunFromGallery();
}
catch (Exception ex)
{
Trace.WriteLine(String.Format("{0}: ERROR {1}", DateTime.Now, ex));
}
}
public void RunFromGallery()
{
Directory.CreateDirectory(_targetDirectory);
var client = new HttpClient(DeveloperFeed);
client.SendingRequest += (sender, e) =>
{
e.Request.Credentials = _credentials;
e.Request.PreAuthenticate = true;
};
var remoteRepo = new DataServicePackageRepository(client);
var targetRepo = new LocalPackageRepository(_targetDirectory);
var packages = remoteRepo.GetPackages()
.Where(p => p.IsAbsoluteLatestVersion)
.ToList();
Parallel.ForEach(packages,
new ParallelOptions { MaxDegreeOfParallelism = 4 },
package =>
{
// Some packages are updated without revving the version. We'll only opt not to re-download
// a package if an identical version does not exist on disk.
var existingPackage = targetRepo.FindPackage(package.Id, package.Version);
var dataServicePackage = (DataServicePackage)package;
if (existingPackage == null ||
!existingPackage.GetHash(dataServicePackage.PackageHashAlgorithm).Equals(dataServicePackage.PackageHash, StringComparison.Ordinal))
{
Trace.WriteLine(string.Format("{0}: Adding package {1}", DateTime.Now, package.GetFullName()));
var packagePath = GetPackagePath(package);
using (var input = package.GetStream())
using (var output = File.Create(packagePath))
{
input.CopyTo(output);
}
PurgeOldVersions(targetRepo, package);
}
});
}
private string GetPackagePath(IPackage package)
{
return Path.Combine(_targetDirectory, package.Id + "." + package.Version + ".nupkg");
}
private void PurgeOldVersions(LocalPackageRepository targetRepo, IPackage package)
{
foreach (var oldPackage in targetRepo.FindPackagesById(package.Id).Where(p => p.Version < package.Version))
{
try
{
var path = GetPackagePath(oldPackage);
Trace.WriteLine(string.Format("Deleting package {0}", oldPackage.GetFullName()));
File.Delete(path);
}
catch
{
// Ignore
}
}
}
protected override void OnStop()
{
base.OnStop();
}
}
}

View File

@ -1,45 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
namespace NuGetClone
{
[RunInstaller(true)]
public class MyServiceInstaller : Installer
{
internal const string ServiceName = "ProjectKClone";
public MyServiceInstaller()
{
var processInstaller = new ServiceProcessInstaller();
var serviceInstaller = new ServiceInstaller();
processInstaller.Account = ServiceAccount.LocalSystem;
processInstaller.Username = null;
processInstaller.Password = null;
serviceInstaller.ServiceName = ServiceName;
serviceInstaller.StartType = ServiceStartMode.Automatic;
serviceInstaller.ServiceName = ServiceName;
this.Installers.Add(processInstaller);
this.Installers.Add(serviceInstaller);
this.Committed += new InstallEventHandler(ServiceInstaller_Committed);
}
void ServiceInstaller_Committed(object sender, InstallEventArgs e)
{
// Auto Start the Service Once Installation is Finished.
var controller = new ServiceController(ServiceName);
controller.Start();
}
}
}

View File

@ -1,27 +0,0 @@
using System;
using System.Collections.Generic;
using System.Configuration.Install;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
namespace NuGetClone
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
public static void Main(string[] args)
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new MyService()
};
ServiceBase.Run(ServicesToRun);
}
}
}

View File

@ -1,80 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{7F7F6AD7-FF5E-48A2-9EE8-274E742787E1}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ProjectKClone</RootNamespace>
<AssemblyName>ProjectKClone</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="Microsoft.Web.XmlTransform">
<HintPath>packages\Microsoft.Web.Xdt.1.0.0\lib\net40\Microsoft.Web.XmlTransform.dll</HintPath>
</Reference>
<Reference Include="NuGet.Core, Version=2.8.50126.400, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>packages\Nuget.Core.2.8.0\lib\net40-Client\NuGet.Core.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration.Install" />
<Reference Include="System.Core" />
<Reference Include="System.Data.Services.Client" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Management" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.ServiceProcess" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="MyService.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="MyServiceInstaller.cs">
<SubType>Component</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -1,22 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21126.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectKClone", "ProjectKClone.csproj", "{7F7F6AD7-FF5E-48A2-9EE8-274E742787E1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7F7F6AD7-FF5E-48A2-9EE8-274E742787E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7F7F6AD7-FF5E-48A2-9EE8-274E742787E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7F7F6AD7-FF5E-48A2-9EE8-274E742787E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7F7F6AD7-FF5E-48A2-9EE8-274E742787E1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -1,36 +0,0 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("NuGetClone")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NuGetClone")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("cfb7b99d-4f04-4c77-ab79-b4d05aa5a1f5")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Web.Xdt" version="1.0.0" targetFramework="net451" />
<package id="Nuget.Core" version="2.8.0" targetFramework="net451" />
</packages>

View File

@ -1,3 +0,0 @@
<configuration>
</configuration>

View File

@ -1,107 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace TCDependencyManager
{
public class GitHubAPI
{
private const string BaseUrl = "https://api.github.com/";
private readonly string _oauthToken;
public GitHubAPI(string oauthToken)
{
_oauthToken = oauthToken;
}
public List<Repository> GetRepos()
{
using (var client = GetClient())
{
var response = client.GetAsync("orgs/aspnet/repos?page=1&per_page=100").Result;
return response.EnsureSuccessStatusCode()
.Content
.ReadAsAsync<List<Repository>>().Result;
}
}
public List<Project> GetProjects(Repository repo)
{
IEnumerable<string> projectNames = null;
using (var client = GetClient())
{
string path = string.Format("/repos/aspnet/{0}/contents/src?ref=dev", repo.Name);
var response = client.GetAsync(path).Result;
if (response.IsSuccessStatusCode)
{
var result = response.Content.ReadAsAsync<JArray>().Result;
projectNames = result.Select(r => r["name"].Value<string>());
}
else
{
projectNames = Enumerable.Empty<string>();
}
}
return projectNames
.AsParallel()
.Select(p => new Project
{
Repo = repo,
ProjectName = p,
Dependencies = ReadDependencies(repo, p)
})
.Where(p => p.Dependencies != null)
.ToList();
}
private List<string> ReadDependencies(Repository repo, string project)
{
using (var client = GetClient())
{
string path = string.Format("/repos/aspnet/{0}/contents/src/{1}/project.json?ref=dev", repo.Name, project);
var response = client.GetAsync(path).Result;
if (response.IsSuccessStatusCode)
{
var result = response.Content.ReadAsAsync<JObject>().Result;
var content = JsonConvert.DeserializeObject<JObject>(
Encoding.UTF8.GetString(
Convert.FromBase64String(result["content"].Value<string>())));
// Ignore shared repos since they can have the same names
if (content["shared"] != null)
{
return null;
}
var dependencies = (JObject)content["dependencies"];
if (dependencies != null)
{
return dependencies.Cast<JProperty>()
.Where(prop => !String.IsNullOrEmpty(prop.Value.Value<string>()))
.Select(prop => prop.Name)
.ToList();
}
return new List<string>(0);
}
}
// Ignore directories that do not have a project.json
return null;
}
private HttpClient GetClient()
{
var client = new HttpClient
{
BaseAddress = new Uri(BaseUrl)
};
client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("AspNet-CI", "1.0"));
client.DefaultRequestHeaders.Add("Authorization", "token " + _oauthToken);
return client;
}
}
}

View File

@ -1,13 +0,0 @@
using System.Collections.Generic;
namespace TCDependencyManager
{
public class Project
{
public Repository Repo { get; set; }
public string ProjectName { get; set; }
public List<string> Dependencies { get; set; }
}
}

View File

@ -1,15 +0,0 @@
using System.Collections.Generic;
namespace TCDependencyManager
{
public class Repository
{
private readonly HashSet<Repository> _dependencies = new HashSet<Repository>();
public string Id { get; set; }
public string Name { get; set; }
public HashSet<Repository> Dependencies { get { return _dependencies; } }
}
}

View File

@ -1,54 +0,0 @@
using System.Collections.Generic;
using Newtonsoft.Json;
namespace TCDependencyManager
{
public class SnapshotDependencies
{
public int Count { get; set; }
[JsonProperty("snapshot-dependency")]
public List<SnapshotDependency> Dependencies { get; set; }
}
public class SnapshotDependency
{
public string Id { get; set; }
public string Type { get; set; }
public Properties Properties { get; set; }
[JsonProperty("source-buildType")]
public BuildType BuildType { get; set; }
}
public class Properties
{
public List<NameValuePair> Property { get; set; }
}
public class BuildType
{
public string Id { get; set; }
public string Name { get; set; }
public string ProjectId { get; set; }
public string ProjectName { get; set; }
}
public class NameValuePair
{
public NameValuePair(string name, string value)
{
Name = name;
Value = value;
}
public string Name { get; set; }
public string Value { get; set; }
}
}

View File

@ -1,18 +0,0 @@
using System.Collections.Generic;
namespace TCDependencyManager
{
public class Triggers
{
public List<Trigger> Trigger { get; set; }
}
public class Trigger
{
public string Id { get; set; }
public string Type { get; set; }
public Properties Properties { get; set; }
}
}

View File

@ -1,80 +0,0 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Net;
namespace TCDependencyManager
{
class Program
{
private static readonly string[] _excludedRepos = new[] { "xunit", "kruntime", "coreclr", "universe", "rolsyn" };
static int Main(string[] args)
{
var teamCityUrl = GetEnv("TEAMCITY_SERVERURL");
var teamCityUser = GetEnv("TEAMCITY_USER");
var teamCityPass = GetEnv("TEAMCITY_PASSWORD");
var githubCreds = GetEnv("GITHUB_CREDS");
var teamCity = new TeamCityAPI(teamCityUrl,
new NetworkCredential(teamCityUser, teamCityPass));
var gitHub = new GitHubAPI(githubCreds);
Console.WriteLine("Listing GitHub repos");
var repos = gitHub.GetRepos()
.Where(repo => !_excludedRepos.Contains(repo.Name, StringComparer.OrdinalIgnoreCase))
.ToList();
Console.WriteLine("Listing projects under repos");
var projects = repos.AsParallel()
.SelectMany(repo => gitHub.GetProjects(repo))
.ToList();
Console.WriteLine("Creating dependency tree");
MapRepoDependencies(projects);
Console.WriteLine("Ensuring dependencies are consistent on TeamCity");
foreach (var repo in repos.Where(p => p.Dependencies.Any()))
{
var dependencies = repo.Dependencies
.Select(r => r.Name)
.Concat(new[] { "CoreCLR" });
teamCity.EnsureDependencies(repo.Name, dependencies);
}
return 0;
}
private static void MapRepoDependencies(List<Project> projects)
{
var projectLookup = projects.ToDictionary(project => project.ProjectName, StringComparer.OrdinalIgnoreCase);
foreach (var project in projects)
{
foreach (var dependency in project.Dependencies)
{
Project dependencyProject;
if (projectLookup.TryGetValue(dependency, out dependencyProject) &&
project.Repo != dependencyProject.Repo)
{
project.Repo.Dependencies.Add(dependencyProject.Repo);
}
}
}
}
private static string GetEnv(string key)
{
var envValue = Environment.GetEnvironmentVariable(key);
if (String.IsNullOrEmpty(envValue))
{
throw new ArgumentNullException(key);
}
return envValue;
}
}
}

View File

@ -1,36 +0,0 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("TCDependencyManager")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TCDependencyManager")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("9645f4a8-75b5-46ad-8539-7d9c5f61c4c9")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -1,74 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{72C96182-352E-44EC-B157-AFEBDC7A74DD}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TCDependencyManager</RootNamespace>
<AssemblyName>TCDependencyManager</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>..\..\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Net.Http.Formatting, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Microsoft.AspNet.WebApi.Client.5.1.1\lib\net45\System.Net.Http.Formatting.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Models\Triggers.cs" />
<Compile Include="TeamCityAPI.cs" />
<Compile Include="GitHubAPI.cs" />
<Compile Include="Program.cs" />
<Compile Include="Models\Projects.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Models\Repository.cs" />
<Compile Include="Models\SnapshotDependency.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -1,22 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21126.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TCDependencyManager", "TCDependencyManager.csproj", "{72C96182-352E-44EC-B157-AFEBDC7A74DD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{72C96182-352E-44EC-B157-AFEBDC7A74DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{72C96182-352E-44EC-B157-AFEBDC7A74DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{72C96182-352E-44EC-B157-AFEBDC7A74DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{72C96182-352E-44EC-B157-AFEBDC7A74DD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -1,179 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
namespace TCDependencyManager
{
public class TeamCityAPI
{
private const string TriggersEndPoint = "httpAuth/app/rest/buildTypes/{0}/triggers";
private readonly string _teamCityUrl;
private readonly ICredentials _creds;
public TeamCityAPI(string teamCityUrl, ICredentials creds)
{
_teamCityUrl = teamCityUrl;
_creds = creds;
}
public bool TryGetSnapshotDependencies(string configId, out List<string> dependencies)
{
string url = String.Format("httpAuth/app/rest/buildTypes/{0}/snapshot-dependencies", configId);
var client = GetClient();
var response = client.GetAsync(url).Result;
if (response.StatusCode == HttpStatusCode.NotFound)
{
// We don't have the config setup on the CI. That is ok.
dependencies = null;
return false;
}
dependencies = response.EnsureSuccessStatusCode()
.Content.ReadAsAsync<SnapshotDependencies>()
.Result
.Dependencies.Select(f => f.Id)
.ToList();
return true;
}
public List<Trigger> GetTriggers(string configId)
{
string url = String.Format(TriggersEndPoint, configId);
var client = GetClient();
var response = client.GetAsync(url).Result;
if (response.StatusCode == HttpStatusCode.NotFound)
{
// We don't have the config setup on the CI. That is ok.
return null;
}
var triggers = response.EnsureSuccessStatusCode()
.Content.ReadAsAsync<Triggers>()
.Result;
return triggers.Trigger;
}
public void AddFinishTriggers(string configId, IEnumerable<string> finishConfigIds)
{
foreach (var finishConfigId in finishConfigIds)
{
var props = new Properties
{
Property = new List<NameValuePair>
{
new NameValuePair("afterSuccessfulBuildOnly", "true"),
new NameValuePair("dependsOn", finishConfigId)
}
};
var trigger = new Trigger
{
Id = "Trigger_" + finishConfigId,
Properties = props,
Type = "buildDependencyTrigger"
};
string url = String.Format(TriggersEndPoint, configId);
var client = GetClient();
var response = client.PostAsync(url, GetJsonContent(trigger)).Result;
response.EnsureSuccessStatusCode();
}
}
public void SetDependencies(string configId, IEnumerable<string> dependencies)
{
foreach (var dependencyId in dependencies)
{
Console.WriteLine("For {0} adding: {1}", configId, dependencyId);
string url = String.Format("httpAuth/app/rest/buildTypes/{0}/snapshot-dependencies", configId);
var client = GetClient();
var props = new Properties
{
Property = new List<NameValuePair>
{
new NameValuePair("run-build-if-dependency-failed", "true"),
new NameValuePair("take-successful-builds-only", "true"),
new NameValuePair("take-started-build-with-same-revisions", "true")
}
};
var snapshotDependency = new SnapshotDependency
{
Id = dependencyId,
Type = "snapshot_dependency",
Properties = props,
BuildType = new BuildType
{
Id = dependencyId,
Name = dependencyId,
ProjectId = "AspNet",
ProjectName = "AspNet"
}
};
var content = GetJsonContent(snapshotDependency);
var response = client.PostAsync(url, content).Result;
response.EnsureSuccessStatusCode();
}
}
public void EnsureDependencies(string configId, IEnumerable<string> dependencies)
{
List<string> currentDependencies;
if (TryGetSnapshotDependencies(configId, out currentDependencies))
{
dependencies = dependencies.Select(NormalizeId);
var dependenciesToAdd = dependencies.Except(currentDependencies, StringComparer.OrdinalIgnoreCase);
SetDependencies(configId, dependenciesToAdd);
var currentTriggers = GetTriggers(configId)
.Where(t => t.Type.Equals("buildDependencyTrigger", StringComparison.OrdinalIgnoreCase))
.Select(t => t.Properties.Property.First(f => f.Name.Equals("dependsOn", StringComparison.OrdinalIgnoreCase)).Value);
var triggersToAdd = dependencies.Except(currentTriggers);
AddFinishTriggers(configId, triggersToAdd);
}
}
private static StringContent GetJsonContent<TVal>(TVal value)
{
var serialized = JsonConvert.SerializeObject(value,
new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
});
var content = new StringContent(serialized);
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
return content;
}
private static string NormalizeId(string dependencyId)
{
return dependencyId.Replace(".", "");
}
private HttpClient GetClient()
{
var handler = new HttpClientHandler
{
PreAuthenticate = true,
Credentials = _creds
};
var client = new HttpClient(handler)
{
BaseAddress = new Uri(_teamCityUrl)
};
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
return client;
}
}
}

View File

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.AspNet.WebApi.Client" version="5.1.1" targetFramework="net451" />
<package id="Newtonsoft.Json" version="4.5.11" targetFramework="net451" />
</packages>