Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .build/Build.Environment.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Nuke.Common.IO;
using Nuke.Common.IO;

partial class Build
{
AbsolutePath SourceDirectory => RootDirectory / "src";

AbsolutePath AllSolutionFile => SourceDirectory / "All.sln";
}
AbsolutePath AllSolutionFile => SourceDirectory / "All.slnx";
}
61 changes: 43 additions & 18 deletions .build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,91 @@
using System.Linq;
using Newtonsoft.Json;
using Nuke.Common;
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Utilities.Collections;
using static Nuke.Common.Tools.DotNet.DotNetTasks;
using static Helpers;

partial class Build : NukeBuild
{
/// Support plugins are available for:
/// - JetBrains ReSharper https://nuke.build/resharper
/// - JetBrains Rider https://nuke.build/rider
/// - Microsoft VisualStudio https://nuke.build/visualstudio
/// - Microsoft VSCode https://nuke.build/vscode
public static int Main() => Execute<Build>(x => x.Compile);

[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
private readonly Configuration _configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;
readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;

Target Clean => _ => _
.Before(Restore)
.Executes(() =>
{
SourceDirectory
.GlobDirectories("**/bin", "**/obj")
.ForEach(x => x.DeleteDirectory());
});

Target Restore => _ => _
.Executes(() =>
{
Helpers.DotNetBuildSolution(AllSolutionFile);
DotNetRestore(x => x.SetProjectFile(AllSolutionFile));
EnsureSolutionExists(AllSolutionFile);

DotNetRestore(s => s
.SetProjectFile(AllSolutionFile));
});

Target Compile => _ => _
.DependsOn(Restore)
.Executes(() =>
{
if (!InvokedTargets.Contains(Restore))
Helpers.DotNetBuildSolution(AllSolutionFile);
EnsureSolutionExists(AllSolutionFile);

DotNetBuild(s => s
.SetProjectFile(AllSolutionFile)
.SetConfiguration(Configuration)
.SetNoRestore(InvokedTargets.Contains(Restore)));
});

DotNetBuild(c => c
Target Test => _ => _
.DependsOn(Compile)
.Executes(() =>
{
DotNetTest(s => s
.SetProjectFile(AllSolutionFile)
.SetNoRestore(InvokedTargets.Contains(Restore))
.SetConfiguration(_configuration));
.SetConfiguration(Configuration)
.SetNoBuild(InvokedTargets.Contains(Compile))
.SetNoRestore(InvokedTargets.Contains(Restore)));
});

Target Reset => _ => _
.Executes(() =>
{
TryDelete(AllSolutionFile);
EnsureSolutionExists(AllSolutionFile);

DotNetRestore(s => s
.SetProjectFile(AllSolutionFile));
});

Target MatrixGenerate => _ => _
.Executes(() =>
{
Helpers.DotNetBuildSolution(AllSolutionFile);
var all = AllSolutionFile.ReadSolution();
EnsureSolutionExists(AllSolutionFile);

var solution = AllSolutionFile.ReadSolution();
var matrix = new
{
include = all
include = solution
.GetAllProjects("*.Tests")
.Select(p => new
{
name = Path.GetFileNameWithoutExtension(p.Path),
path = Path.GetRelativePath(RootDirectory, p.Path),
path = RootDirectory.GetRelativePathTo(p.Path).ToString(),
directoryPath = Path.GetDirectoryName(p.Path)
}).ToArray()
})
.ToArray()
};

File.WriteAllText(RootDirectory / "matrix.json", JsonConvert.SerializeObject(matrix));
File.WriteAllText(RootDirectory / "matrix.json", JsonConvert.SerializeObject(matrix, Formatting.Indented));
});
}
57 changes: 35 additions & 22 deletions .build/Helpers.cs
Original file line number Diff line number Diff line change
@@ -1,44 +1,57 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Nuke.Common.Tooling;
using Nuke.Common.IO;
using Nuke.Common.Tools.DotNet;

static class Helpers
{
static readonly string[] s_directories =
static readonly string[] Directories =
[
"Infrastructure",
"Service.Runner",
"Service.Supervisor"
];

static IEnumerable<string> GetAllProjects(string source, IEnumerable<string> directories)
public static void EnsureSolutionExists(AbsolutePath path)
{
return directories
.Select(directory => Path.Combine(source, directory))
.SelectMany(path => Directory.EnumerateFiles(path, "*.csproj", SearchOption.AllDirectories));
}
if (File.Exists(path))
return;

public static IReadOnlyCollection<Output> DotNetBuildSolution(string solution)
{
if (File.Exists(solution))
return Array.Empty<Output>();
var solution = Path.GetFileNameWithoutExtension(path);

var root = Path.GetDirectoryName(solution);
if (string.IsNullOrWhiteSpace(root))
return Array.Empty<Output>();
DotNetTasks.DotNet($"new sln -n {solution} --format slnx", path.Parent);

var projects = GetAllProjects(root, s_directories);
var working = Path.GetDirectoryName(solution);
foreach (var (folder, projects) in GetProjectsByFolder(path.Parent))
{
var args = string.Join(" ", projects.Select(p => $"\"{p}\""));
DotNetTasks.DotNet($"sln \"{path}\" add --solution-folder \"{folder}\" {args}", path.Parent);
}
}

var list = new List<Output>();
public static void TryDelete(AbsolutePath file)
{
if (File.Exists(file))
File.Delete(file);
}

var args = string.Join(" ", projects.Select(t => $"\"{t}\""));
list.AddRange(DotNetTasks.DotNet($"new sln -n {Path.GetFileNameWithoutExtension(solution)} --format sln", working));
list.AddRange(DotNetTasks.DotNet($"sln \"{solution}\" add {args}", working));
static IEnumerable<(string Folder, List<string> Projects)> GetProjectsByFolder(AbsolutePath path)
{
return Directories
.Select(directory => path / directory)
.Where(path => Directory.Exists(path))
.SelectMany(directory => Directory.EnumerateFiles(directory, "*.csproj", SearchOption.AllDirectories))
.GroupBy(project => GetSolutionFolder(path, project))
.Select(group => (group.Key, group.ToList()));
}

static string GetSolutionFolder(AbsolutePath path, string project)
{
var relative = Path.GetRelativePath(path, project);
var parts = relative.Replace('\\', '/').Split('/');

return list;
// structure: TopLevelDir/Category/ProjectFolder/Project.csproj
// returns: TopLevelDir/Category (e.g., "Infrastructure/src")
return parts.Length >= 2 ? $"{parts[0]}/{parts[1]}" : parts[0];
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,6 @@ schema-settings.json

# Nuke
All.sln
All.slnx

!.gitkeep
6 changes: 4 additions & 2 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
"Clean",
"Compile",
"MatrixGenerate",
"Restore"
"Reset",
"Restore",
"Test"
]
},
"Verbosity": {
Expand Down Expand Up @@ -101,7 +103,7 @@
"allOf": [
{
"properties": {
"_configuration": {
"Configuration": {
"type": "string",
"description": "Configuration to build - Default is 'Debug' (local) or 'Release' (server)",
"enum": [
Expand Down
79 changes: 0 additions & 79 deletions src/Infrastructure/Giantnodes.Infrastructure.sln

This file was deleted.

15 changes: 15 additions & 0 deletions src/Infrastructure/Giantnodes.Infrastructure.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Solution>
<Folder Name="/src/">
<Project Path="src/EntityFrameworkCore/Giantnodes.Infrastructure.EntityFrameworkCore.csproj" />
<Project Path="src/GraphQL/Giantnodes.Infrastructure.GraphQL.csproj" />
<Project Path="src/Infrastructure/Giantnodes.Infrastructure.csproj" />
<Project Path="src/MassTransit/Giantnodes.Infrastructure.MassTransit.csproj" />
<Project Path="src/Pipelines.MassTransit/Giantnodes.Infrastructure.Pipelines.MassTransit.csproj" />
<Project Path="src/Pipelines/Giantnodes.Infrastructure.Pipelines.csproj" />
</Folder>
<Folder Name="/tests/">
<Project Path="tests/GraphQL.Tests/Giantnodes.Infrastructure.GraphQL.Tests.csproj" />
<Project Path="tests/Infrastructure.Tests/Giantnodes.Infrastructure.Tests.csproj" />
<Project Path="tests/Pipelines.Tests/Giantnodes.Infrastructure.Pipelines.Tests.csproj" />
</Folder>
</Solution>
51 changes: 0 additions & 51 deletions src/Service.Runner/Giantnodes.Service.Runner.sln

This file was deleted.

10 changes: 10 additions & 0 deletions src/Service.Runner/Giantnodes.Service.Runner.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Solution>
<Folder Name="/src/">
<Project Path="src/Components/Giantnodes.Service.Runner.Components.csproj" />
<Project Path="src/Console/Giantnodes.Service.Runner.Console.csproj" />
<Project Path="src/Contracts/Giantnodes.Service.Runner.Contracts.csproj" />
<Project Path="src/Infrastructure/Giantnodes.Service.Runner.Infrastructure.csproj" />
<Project Path="src/Persistence/Giantnodes.Service.Runner.Persistence.csproj" />
</Folder>
<Folder Name="/test/" />
</Solution>
7 changes: 0 additions & 7 deletions src/Service.Runner/global.json

This file was deleted.

Loading
Loading