This repository has been archived by the owner on Nov 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add infrastructure to generate global solution
- Loading branch information
Showing
6 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
external | ||
|
||
# Build Folders (you can keep bin if you'd like, to store dlls and pdbs) | ||
[Bb]in/ | ||
[Oo]bj/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
|
||
<!-- Thanks to Thomas Frenzel (https://github.com/dotnet/sdk/issues/1151#issuecomment-385133284) --> | ||
<PropertyGroup> | ||
<ReplacePackageReferences Condition="$(ReplacePackageReferences) == ''">true</ReplacePackageReferences> | ||
<SolutionPath>$(MSBuildThisFileDirectory)\nuke.sln</SolutionPath> | ||
</PropertyGroup> | ||
|
||
<Choose> | ||
<When Condition="$(ReplacePackageReferences) AND '$(SolutionPath)' != '' AND '$(SolutionPath)' != '*undefined*' AND Exists('$(SolutionPath)')"> | ||
|
||
<PropertyGroup> | ||
<SolutionFileContent>$([System.IO.File]::ReadAllText($(SolutionPath)))</SolutionFileContent> | ||
<SmartSolutionDir>$([System.IO.Path]::GetDirectoryName( $(SolutionPath) ))</SmartSolutionDir> | ||
<RegexPattern>(?<="[PackageName]", ")(.*)(?=", ")</RegexPattern> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<!-- Keep the identity of the package reference --> | ||
<SmartPackageReference Include="@(PackageReference)"> | ||
<PackageName>%(Identity)</PackageName> | ||
<InSolution>$(SolutionFileContent.Contains('\%(Identity).csproj'))</InSolution> | ||
</SmartPackageReference> | ||
|
||
<!-- Filter them by mapping them to another itemGroup using the WithMetadataValue item function --> | ||
<PackageInSolution Include="@(SmartPackageReference -> WithMetadataValue('InSolution', True) )"> | ||
<Pattern>$(RegexPattern.Replace('[PackageName]','%(PackageName)') )</Pattern> | ||
<SmartPath>$([System.Text.RegularExpressions.Regex]::Match( '$(SolutionFileContent)', '%(Pattern)' ))</SmartPath> | ||
</PackageInSolution> | ||
|
||
<ProjectReference Include="@(PackageInSolution -> '$(SmartSolutionDir)\%(SmartPath)' )"/> | ||
|
||
<!-- Remove the package references that are now referenced as projects --> | ||
<PackageReference Remove="@(PackageInSolution -> '%(PackageName)' )"/> | ||
</ItemGroup> | ||
|
||
</When> | ||
</Choose> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright 2019 Maintainers of NUKE. | ||
// Distributed under the MIT License. | ||
// https://github.com/nuke-build/nuke/blob/master/LICENSE | ||
|
||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using Nuke.Common; | ||
using Nuke.Common.Git; | ||
using Nuke.Common.IO; | ||
using Nuke.Common.ProjectModel; | ||
using Nuke.Common.Utilities.Collections; | ||
using Octokit; | ||
using static Nuke.Common.ControlFlow; | ||
using static Nuke.Common.IO.PathConstruction; | ||
using static Nuke.Common.IO.SerializationTasks; | ||
using static Nuke.Common.ProjectModel.ProjectModelTasks; | ||
using static Nuke.Common.Tools.Git.GitTasks; | ||
|
||
partial class Build | ||
{ | ||
[Parameter] readonly bool UseSSH; | ||
|
||
AbsolutePath ExternalRepositoriesDirectory => RootDirectory / "external"; | ||
AbsolutePath ExternalRepositoriesFile => ExternalRepositoriesDirectory / "repositories.yml"; | ||
|
||
IEnumerable<GitRepository> ExternalRepositories => | ||
YamlDeserializeFromFile<string[]>(ExternalRepositoriesFile).Select(x => GitRepository.FromUrl(x)); | ||
|
||
Target CheckoutExternalRepositories => _ => _ | ||
.Executes(() => | ||
{ | ||
string GetDefaultBranch(GitRepository repository) | ||
{ | ||
var client = new GitHubClient(new ProductHeaderValue(nameof(NukeBuild))); | ||
var repo = client.Repository.Get(repository.GetGitHubOwner(), repository.GetGitHubName()).Result; | ||
return repo.DefaultBranch; | ||
} | ||
|
||
foreach (var repository in ExternalRepositories) | ||
{ | ||
var repositoryDirectory = ExternalRepositoriesDirectory / repository.GetGitHubName(); | ||
var origin = UseSSH ? repository.SshUrl : repository.HttpsUrl; | ||
|
||
if (!Directory.Exists(repositoryDirectory)) | ||
Git($"clone {origin} {repositoryDirectory} --branch {GetDefaultBranch(repository)} --progress"); | ||
else | ||
{ | ||
SuppressErrors(() => Git($"remote add origin {origin}", repositoryDirectory)); | ||
Git($"remote set-url origin {origin}", repositoryDirectory); | ||
} | ||
} | ||
}); | ||
|
||
Target CreateGlobalSolution => _ => _ | ||
.DependsOn(CheckoutExternalRepositories) | ||
.Executes(() => | ||
{ | ||
var global = CreateSolution(); | ||
global.Configurations = Solution.Configurations; | ||
|
||
SolutionFolder GetParentFolder(PrimitiveProject solutionFolder) => | ||
global.AllSolutionFolders.FirstOrDefault(x => x.ProjectId == solutionFolder.SolutionFolder?.ProjectId); | ||
|
||
void AddSolution(Solution solution, SolutionFolder folder = null) | ||
{ | ||
solution.AllSolutionFolders.ForEach(x => global.AddSolutionFolder(x.Name, x.ProjectId, GetParentFolder(x) ?? folder)); | ||
solution.AllSolutionFolders.ForEach(x => global.GetSolutionFolder(x.ProjectId).Items = x.Items); | ||
solution.AllProjects.ForEach(x => global.AddProject(x.Name, x.TypeId, x.Path, x.ProjectId, x.Configurations, GetParentFolder(x) ?? folder)); | ||
} | ||
|
||
AddSolution(Solution); | ||
|
||
ExternalRepositoriesDirectory.GlobFiles("*/*.sln") | ||
.Select(x => ParseSolution(x)) | ||
.ForEach(x => AddSolution(x, global.AddSolutionFolder(x.Name))); | ||
|
||
global.SaveAs(RootDirectory / "nuke-global.sln"); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
- https://github.com/nuke-build/azure-keyvault.git | ||
- https://github.com/nuke-build/docfx.git | ||
- https://github.com/nuke-build/docker.git | ||
- https://github.com/nuke-build/helm.git | ||
- https://github.com/nuke-build/kubernetes.git | ||
- https://github.com/nuke-build/nswag.git | ||
- https://github.com/nuke-build/presentation.git | ||
- https://github.com/nuke-build/resharper.git | ||
- https://github.com/nuke-build/template.git | ||
- https://github.com/nuke-build/visualstudio.git | ||
- https://github.com/nuke-build/vscode.git | ||
- https://github.com/nuke-build/web.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters