|
|
|
@ -10,10 +10,10 @@ namespace ConsoleApplication |
|
|
|
using System.IO; |
|
|
|
using System.Linq; |
|
|
|
using System.Text; |
|
|
|
|
|
|
|
using System.Xml; |
|
|
|
using LibGit2Sharp; |
|
|
|
using Microsoft.DotNet.ProjectModel; |
|
|
|
using Newtonsoft.Json; |
|
|
|
using Microsoft.Build.Construction; |
|
|
|
using Microsoft.Build.Evaluation; |
|
|
|
using NuGet.Versioning; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -65,31 +65,29 @@ namespace ConsoleApplication |
|
|
|
{ |
|
|
|
var resetmode = args.Contains("reset"); |
|
|
|
|
|
|
|
// Find the project root where glbal.json lives
|
|
|
|
var root = ProjectRootResolver.ResolveRootDirectory("."); |
|
|
|
// Find the project root
|
|
|
|
var root = Path.GetFullPath(Path.Combine(LibGit2Sharp.Repository.Discover("."), "..")); |
|
|
|
|
|
|
|
// Lets find the repo
|
|
|
|
var repo = new LibGit2Sharp.Repository(root); |
|
|
|
|
|
|
|
// Lets find all the project.json files in the src folder (don't care about versioning `tests`)
|
|
|
|
var projectFiles = Directory.EnumerateFiles(Path.Combine(root, "src"), Project.FileName, SearchOption.AllDirectories); |
|
|
|
var projectFiles = Directory.EnumerateFiles(Path.Combine(root, "src"), "*.csproj", SearchOption.AllDirectories); |
|
|
|
|
|
|
|
ResetProject(projectFiles); |
|
|
|
|
|
|
|
// Open them and convert them to source projects
|
|
|
|
var projects = projectFiles.Select(x => ProjectReader.GetProject(x)) |
|
|
|
var projects = projectFiles.Select(x => ProjectRootElement.Open(x, ProjectCollection.GlobalProjectCollection, true)) |
|
|
|
.Select(x => new SourceProject(x, repo.Info.WorkingDirectory)) |
|
|
|
.ToList(); |
|
|
|
|
|
|
|
if (resetmode) |
|
|
|
{ |
|
|
|
ResetProject(projects); |
|
|
|
} |
|
|
|
else |
|
|
|
if (!resetmode) |
|
|
|
{ |
|
|
|
CaclulateProjectVersionNumber(projects, repo); |
|
|
|
|
|
|
|
UpdateVersionNumbers(projects); |
|
|
|
|
|
|
|
CreateBuildScript(projects); |
|
|
|
CreateBuildScript(projects, root); |
|
|
|
|
|
|
|
foreach (var p in projects) |
|
|
|
{ |
|
|
|
@ -98,12 +96,14 @@ namespace ConsoleApplication |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private static void CreateBuildScript(IEnumerable<SourceProject> projects) |
|
|
|
private static void CreateBuildScript(IEnumerable<SourceProject> projects, string root) |
|
|
|
{ |
|
|
|
var outputDir = Path.GetFullPath(Path.Combine(root, @"artifacts\bin\ImageSharp")); |
|
|
|
|
|
|
|
var sb = new StringBuilder(); |
|
|
|
foreach (var p in projects) |
|
|
|
{ |
|
|
|
sb.AppendLine($@"dotnet pack --configuration Release --output ""artifacts\bin\ImageSharp"" ""{p.ProjectFilePath}"""); |
|
|
|
sb.AppendLine($@"dotnet pack --configuration Release --output ""{outputDir}"" ""{p.ProjectFilePath}"""); |
|
|
|
} |
|
|
|
|
|
|
|
File.WriteAllText("build-inner.cmd", sb.ToString()); |
|
|
|
@ -113,17 +113,17 @@ namespace ConsoleApplication |
|
|
|
{ |
|
|
|
foreach (var p in projects) |
|
|
|
{ |
|
|
|
// TODO force update of all dependent projects to point to the newest build.
|
|
|
|
// we skip the build number and standard CI prefix on first commits
|
|
|
|
var newVersion = p.FinalVersionNumber; |
|
|
|
|
|
|
|
// create a backup file so we can rollback later without breaking formatting
|
|
|
|
File.Copy(p.FullProjectFilePath, $"{p.FullProjectFilePath}.bak", true); |
|
|
|
} |
|
|
|
|
|
|
|
dynamic projectFile = JsonConvert.DeserializeObject(File.ReadAllText(p.FullProjectFilePath)); |
|
|
|
foreach (var p in projects) |
|
|
|
{ |
|
|
|
// TODO force update of all dependent projects to point to the newest build.
|
|
|
|
// we skip the build number and standard CI prefix on first commits
|
|
|
|
var newVersion = p.FinalVersionNumber; |
|
|
|
|
|
|
|
projectFile.version = $"{newVersion}-*"; |
|
|
|
File.WriteAllText(p.FullProjectFilePath, JsonConvert.SerializeObject(projectFile, Formatting.Indented)); |
|
|
|
p.UpdateVersion(newVersion); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -168,7 +168,7 @@ namespace ConsoleApplication |
|
|
|
projects.ForEach(x => x.CalculateVersion(repo, branch)); |
|
|
|
} |
|
|
|
|
|
|
|
private static void ResetProject(List<SourceProject> projects) |
|
|
|
private static void ResetProject(IEnumerable<string> projectPaths) |
|
|
|
{ |
|
|
|
if (File.Exists("build-inner.cmd")) |
|
|
|
{ |
|
|
|
@ -176,12 +176,12 @@ namespace ConsoleApplication |
|
|
|
} |
|
|
|
|
|
|
|
// revert the project.json change be reverting it but skipp all the git stuff as its not needed
|
|
|
|
foreach (var p in projects) |
|
|
|
foreach (var p in projectPaths) |
|
|
|
{ |
|
|
|
if (File.Exists($"{p.FullProjectFilePath}.bak")) |
|
|
|
if (File.Exists($"{p}.bak")) |
|
|
|
{ |
|
|
|
File.Copy($"{p.FullProjectFilePath}.bak", p.FullProjectFilePath, true); |
|
|
|
File.Delete($"{p.FullProjectFilePath}.bak"); |
|
|
|
File.Copy($"{p}.bak", p, true); |
|
|
|
File.Delete($"{p}.bak"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -192,21 +192,24 @@ namespace ConsoleApplication |
|
|
|
public class SourceProject |
|
|
|
{ |
|
|
|
private readonly IEnumerable<string> dependencies; |
|
|
|
private readonly ProjectRootElement project; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="SourceProject"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="project">The project.</param>
|
|
|
|
/// <param name="root">The root.</param>
|
|
|
|
public SourceProject(Project project, string root) |
|
|
|
public SourceProject(ProjectRootElement project, string root) |
|
|
|
{ |
|
|
|
this.Name = project.Name; |
|
|
|
this.ProjectDirectory = project.ProjectDirectory.Substring(root.Length); |
|
|
|
this.ProjectFilePath = project.ProjectFilePath.Substring(root.Length); |
|
|
|
this.FullProjectFilePath = project.ProjectFilePath; |
|
|
|
this.Version = project.Version; |
|
|
|
this.dependencies = project.Dependencies.Select(x => x.Name); |
|
|
|
this.Name = project.Properties.FirstOrDefault(x => x.Name == "AssemblyTitle").Value; |
|
|
|
|
|
|
|
this.ProjectDirectory = project.DirectoryPath.Substring(root.Length); |
|
|
|
this.ProjectFilePath = project.ProjectFileLocation.File.Substring(root.Length); |
|
|
|
this.FullProjectFilePath = Path.GetFullPath(project.ProjectFileLocation.File); |
|
|
|
this.Version = new NuGetVersion(project.Properties.FirstOrDefault(x => x.Name == "VersionPrefix").Value); |
|
|
|
this.dependencies = project.Items.Where(x => x.ItemType == "ProjectReference").Select(x => Path.GetFullPath(Path.Combine(project.DirectoryPath, x.Include))); |
|
|
|
this.FinalVersionNumber = this.Version.ToFullString(); |
|
|
|
this.project = project; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -223,7 +226,7 @@ namespace ConsoleApplication |
|
|
|
/// <value>
|
|
|
|
/// The version.
|
|
|
|
/// </value>
|
|
|
|
public NuGetVersion Version { get; } |
|
|
|
public NuGetVersion Version { get; private set; } |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the dependent projects.
|
|
|
|
@ -279,7 +282,18 @@ namespace ConsoleApplication |
|
|
|
/// <param name="projects">The projects.</param>
|
|
|
|
public void PopulateDependencies(IEnumerable<SourceProject> projects) |
|
|
|
{ |
|
|
|
this.DependentProjects = projects.Where(x => this.dependencies.Contains(x.Name)).ToList(); |
|
|
|
this.DependentProjects = projects.Where(x => this.dependencies.Contains(x.FullProjectFilePath)).ToList(); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Update the version number in the project file
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="versionnumber">the new version number to save.</param>
|
|
|
|
internal void UpdateVersion(string versionnumber) |
|
|
|
{ |
|
|
|
this.project.AddProperty("VersionPrefix", versionnumber); |
|
|
|
this.Version = new NuGetVersion(versionnumber); |
|
|
|
this.project.Save(); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -334,11 +348,15 @@ namespace ConsoleApplication |
|
|
|
var blob = repo.Lookup<Blob>(projectFileChange.Oid); |
|
|
|
using (var s = blob.GetContentStream()) |
|
|
|
{ |
|
|
|
var project = new ProjectReader().ReadProject(s, this.Name, this.FullProjectFilePath, null); |
|
|
|
if (project.Version != this.Version) |
|
|
|
using (var reader = XmlReader.Create(s)) |
|
|
|
{ |
|
|
|
// version changed
|
|
|
|
return false; |
|
|
|
var proj = ProjectRootElement.Create(reader); |
|
|
|
var version = new NuGetVersion(proj.Properties.FirstOrDefault(x => x.Name == "VersionPrefix").Value); |
|
|
|
if (version != this.Version) |
|
|
|
{ |
|
|
|
// version changed
|
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|