diff --git a/.space.kts b/.space.kts index 484284705..4081ff8ff 100644 --- a/.space.kts +++ b/.space.kts @@ -1,4 +1,4 @@ -job("Pack") { +job("Build and check") { container(displayName = "Build and check", image = "mcr.microsoft.com/dotnet/sdk") { shellScript { content = "dotnet run --project ./build -- check" diff --git a/build/Targets/BenchmarksTarget.cs b/build/BenchmarksTarget.cs similarity index 91% rename from build/Targets/BenchmarksTarget.cs rename to build/BenchmarksTarget.cs index a1bd64715..26018aec7 100644 --- a/build/Targets/BenchmarksTarget.cs +++ b/build/BenchmarksTarget.cs @@ -1,10 +1,11 @@ // ReSharper disable ClassNeverInstantiated.Global -namespace Build.Targets; + +namespace Build; internal class BenchmarksTarget( Settings settings, - ICommands commands, - IPaths paths, + Commands commands, + Paths paths, ITeamCityArtifactsWriter artifactsWriter) : IInitializable, ITarget { @@ -25,7 +26,6 @@ public Task InitializeAsync() => commands.Register( public Task RunAsync(CancellationToken cancellationToken) { - Info("Benchmarking"); var solutionDirectory = paths.SolutionDirectory; var logsDirectory = Path.Combine(solutionDirectory, ".logs"); Directory.CreateDirectory(logsDirectory); @@ -37,14 +37,13 @@ public Task RunAsync(CancellationToken cancellationToken) else { Directory.CreateDirectory(artifactsDirectory); - - var benchmark = new DotNetRun() + new DotNetRun() .WithProject(Path.Combine("benchmarks", "Pure.DI.Benchmarks", "Pure.DI.Benchmarks.csproj")) .WithConfiguration(settings.Configuration) .WithArgs("--artifacts", artifactsDirectory, "--", "--filter") - .AddArgs(Reports.Select(filter => $"*{filter}*").ToArray()); - - benchmark.Run().Succeed("Benchmarking"); + .AddArgs(Reports.Select(filter => $"*{filter}*").ToArray()) + .Run() + .Succeed("Benchmarking"); } var index = 0; diff --git a/build/Targets/CompatibilityCheckTarget.cs b/build/CompatibilityCheckTarget.cs similarity index 98% rename from build/Targets/CompatibilityCheckTarget.cs rename to build/CompatibilityCheckTarget.cs index f85bcdd45..d569b8133 100644 --- a/build/Targets/CompatibilityCheckTarget.cs +++ b/build/CompatibilityCheckTarget.cs @@ -5,14 +5,14 @@ // ReSharper disable ReturnTypeCanBeEnumerable.Local // ReSharper disable InvertIf -namespace Build.Targets; +namespace Build; using NuGet.Versioning; internal class CompatibilityCheckTarget( Settings settings, - ICommands commands, - IPaths paths, + Commands commands, + Paths paths, INuGet nuGet, [Tag(typeof(GeneratorTarget))] ITarget generatorTarget, [Tag(typeof(LibrariesTarget))] ITarget> librariesTarget) @@ -27,7 +27,6 @@ public Task InitializeAsync() => commands.Register( [SuppressMessage("Performance", "CA1861:Avoid constant arrays as arguments")] public async Task> RunAsync(CancellationToken cancellationToken) { - Info("Compatibility checks"); var generatorPackage = await generatorTarget.RunAsync(cancellationToken); var libraries = await librariesTarget.RunAsync(cancellationToken); @@ -68,7 +67,7 @@ public async Task> RunAsync(CancellationToken cance { await CompatibilityCheckAsync(generatorPackage.Path, framework, cancellationToken); } - + var packages = new List { generatorPackage }; // Libraries diff --git a/build/DeployTarget.cs b/build/DeployTarget.cs new file mode 100644 index 000000000..c89a90ca4 --- /dev/null +++ b/build/DeployTarget.cs @@ -0,0 +1,38 @@ +// ReSharper disable ClassNeverInstantiated.Global + +namespace Build; + +internal class DeployTarget( + Settings settings, + Commands commands, + [Tag(typeof(PackTarget))] ITarget> packTarget) + : IInitializable, ITarget +{ + public Task InitializeAsync() => commands.Register( + this, + "Deploys packages", + "deploy", + "dp"); + + public async Task RunAsync(CancellationToken cancellationToken) + { + if (string.IsNullOrWhiteSpace(settings.NuGetKey)) + { + Warning("The NuGet key was not specified, the packages will not be pushed."); + return 0; + } + + var packages = await packTarget.RunAsync(cancellationToken); + foreach (var package in packages.Where(i => i.Deploy)) + { + new DotNetNuGetPush() + .WithPackage(package.Path) + .WithSources("https://api.nuget.org/v3/index.json") + .WithApiKey(settings.NuGetKey) + .Build() + .Succeed(); + } + + return 0; + } +} \ No newline at end of file diff --git a/build/Targets/GeneratorTarget.cs b/build/GeneratorTarget.cs similarity index 80% rename from build/Targets/GeneratorTarget.cs rename to build/GeneratorTarget.cs index ad975b250..a0cdfda5b 100644 --- a/build/Targets/GeneratorTarget.cs +++ b/build/GeneratorTarget.cs @@ -4,14 +4,15 @@ // ReSharper disable ClassNeverInstantiated.Global // ReSharper disable ReturnTypeCanBeEnumerable.Local // ReSharper disable InvertIf -namespace Build.Targets; + +namespace Build; using System.IO.Compression; using NuGet.Versioning; internal class GeneratorTarget( Settings settings, - ICommands commands) + Commands commands) : IInitializable, ITarget { public Task InitializeAsync() => commands.Register( @@ -19,26 +20,29 @@ public Task InitializeAsync() => commands.Register( "Builds and tests generator", "generator", "g"); - + [SuppressMessage("Performance", "CA1861:Avoid constant arrays as arguments")] public Task RunAsync(CancellationToken cancellationToken) { - Info("Building generator"); // Generator package var generatorProjectDirectory = Path.Combine("src", "Pure.DI"); var generatorPackages = settings.CodeAnalysis .Select(codeAnalysis => CreateGeneratorPackage(settings.Version, codeAnalysis, generatorProjectDirectory)); - return Task.FromResult(new Package(Path.GetFullPath(MergeGeneratorPackages(settings.Version, generatorPackages, generatorProjectDirectory)), true)); + return Task.FromResult( + new Package( + Path.GetFullPath(MergeGeneratorPackages(settings.Version, generatorPackages, generatorProjectDirectory)), + true)); } - + private string CreateGeneratorPackage(NuGetVersion packageVersion, CodeAnalysis codeAnalysis, string projectDirectory) { var analyzerRoslynPackageVersion = codeAnalysis.AnalyzerRoslynPackageVersion; var analyzerRoslynVersion = new Version(analyzerRoslynPackageVersion.Major, analyzerRoslynPackageVersion.Minor); Info($"Build package for Roslyn {analyzerRoslynVersion}."); - List<(string, string)> props = [ + List<(string, string)> props = + [ ("configuration", settings.Configuration), ("version", packageVersion.ToString()), ("AnalyzerRoslynVersion", analyzerRoslynVersion.ToString()), @@ -49,39 +53,44 @@ private string CreateGeneratorPackage(NuGetVersion packageVersion, CodeAnalysis { props.Add(("CI", "true")); } - - Info($"Building {codeAnalysis.AnalyzerRoslynPackageVersion}"); - var build = new MSBuild() + + new MSBuild() + .WithShortName($"Building {codeAnalysis.AnalyzerRoslynPackageVersion}") .WithTarget("clean;rebuild") .WithRestore(true) - .WithProps(props); - - var buildResult = build.Build(); - buildResult.Succeed(); + .WithProps(props) + .Build() + .Succeed(); - Info($"Testing {codeAnalysis.AnalyzerRoslynPackageVersion}"); - var test = new DotNetTest() + var testResult = new DotNetTest() + .WithShortName($"Testing {codeAnalysis.AnalyzerRoslynPackageVersion}") .WithProps(props) .WithConfiguration(settings.Configuration) .WithNoBuild(true) - .WithNoLogo(true); + .WithNoLogo(true) + .Build(); - var testResult = test.Build(); WriteLine(testResult.ToString(), Color.Details); testResult.Succeed(); - Info($"Packing {codeAnalysis.AnalyzerRoslynPackageVersion}"); - var pack = new DotNetPack() + new DotNetPack() + .WithShortName($"Packing {codeAnalysis.AnalyzerRoslynPackageVersion}") .WithProps(props) .WithConfiguration(settings.Configuration) .WithNoBuild(true) .WithNoLogo(true) - .WithProject(Path.Combine(projectDirectory, "Pure.DI.csproj")); - - pack.Build().Succeed(); - return Path.Combine(projectDirectory, "bin", $"roslyn{analyzerRoslynVersion}", settings.Configuration, $"Pure.DI.{packageVersion.ToString()}.nupkg"); + .WithProject(Path.Combine(projectDirectory, "Pure.DI.csproj")) + .Build() + .Succeed(); + + return Path.Combine( + projectDirectory, + "bin", + $"roslyn{analyzerRoslynVersion}", + settings.Configuration, + $"Pure.DI.{packageVersion.ToString()}.nupkg"); } - + private string MergeGeneratorPackages(NuGetVersion packageVersion, IEnumerable mergingPackages, string projectDirectory) { var targetPackage = Path.GetFullPath(Path.Combine(projectDirectory, "bin", settings.Configuration, $"Pure.DI.{packageVersion}.nupkg")); @@ -126,11 +135,12 @@ private string MergeGeneratorPackages(NuGetVersion packageVersion, IEnumerable 0); + newStream.Flush(); WriteLine($"{entry.FullName,-100} - merged", Color.Details); } } - + return targetPackage; } } \ No newline at end of file diff --git a/build/GlobalUsings.cs b/build/GlobalUsings.cs index 045d24d0b..378e60fd6 100644 --- a/build/GlobalUsings.cs +++ b/build/GlobalUsings.cs @@ -2,7 +2,6 @@ global using System.CommandLine; global using System.Diagnostics.CodeAnalysis; -global using Build.Targets; global using Build.Tools; global using HostApi; global using JetBrains.TeamCity.ServiceMessages.Write.Special; diff --git a/build/Targets/IInitializable.cs b/build/IInitializable.cs similarity index 70% rename from build/Targets/IInitializable.cs rename to build/IInitializable.cs index 8fb092d87..65a7e8dd2 100644 --- a/build/Targets/IInitializable.cs +++ b/build/IInitializable.cs @@ -1,4 +1,4 @@ -namespace Build.Targets; +namespace Build; internal interface IInitializable { diff --git a/build/Targets/ITarget.cs b/build/ITarget.cs similarity index 78% rename from build/Targets/ITarget.cs rename to build/ITarget.cs index f34e5525d..6d134a709 100644 --- a/build/Targets/ITarget.cs +++ b/build/ITarget.cs @@ -1,4 +1,4 @@ -namespace Build.Targets; +namespace Build; internal interface ITarget { diff --git a/build/Targets/LibrariesTarget.cs b/build/LibrariesTarget.cs similarity index 83% rename from build/Targets/LibrariesTarget.cs rename to build/LibrariesTarget.cs index 0c5444fe0..177d2e432 100644 --- a/build/Targets/LibrariesTarget.cs +++ b/build/LibrariesTarget.cs @@ -4,14 +4,15 @@ // ReSharper disable ClassNeverInstantiated.Global // ReSharper disable ReturnTypeCanBeEnumerable.Local // ReSharper disable InvertIf -namespace Build.Targets; + +namespace Build; using NuGet.Versioning; internal class LibrariesTarget( Settings settings, - ICommands commands, - ISdk sdk) + Commands commands, + Sdk sdk) : IInitializable, ITarget> { public Task InitializeAsync() => commands.Register( @@ -19,12 +20,10 @@ public Task InitializeAsync() => commands.Register( "Builds and tests libraries", "libs", "l"); - + [SuppressMessage("Performance", "CA1861:Avoid constant arrays as arguments")] - public async Task> RunAsync(CancellationToken cancellationToken) + public Task> RunAsync(CancellationToken cancellationToken) { - Info("Building libraries"); - // Libraries List libraries = [ @@ -46,18 +45,17 @@ public async Task> RunAsync(CancellationToken cance ("version", settings.Version.ToString()) }; - var libraryPackResult = await new DotNetPack() + new DotNetPack() .WithProps(props) .WithConfiguration(settings.Configuration) .WithNoBuild(true) .WithNoLogo(true) .WithProject(Path.Combine(Path.GetFullPath(Path.Combine("src", library.Name)), $"{library.Name}.csproj")) - .BuildAsync(cancellationToken: cancellationToken); - - libraryPackResult.Succeed(); + .Build() + .Succeed(); } - return libraries; + return Task.FromResult>(libraries); } private string GetPackagePath(string library, NuGetVersion version) diff --git a/build/Targets/Library.cs b/build/Library.cs similarity index 80% rename from build/Targets/Library.cs rename to build/Library.cs index b6287eab4..c5ce04939 100644 --- a/build/Targets/Library.cs +++ b/build/Library.cs @@ -1,4 +1,4 @@ -namespace Build.Targets; +namespace Build; internal record Library( string Name, diff --git a/build/Targets/PackTarget.cs b/build/PackTarget.cs similarity index 93% rename from build/Targets/PackTarget.cs rename to build/PackTarget.cs index cd735afab..8a98b212a 100644 --- a/build/Targets/PackTarget.cs +++ b/build/PackTarget.cs @@ -5,10 +5,10 @@ // ReSharper disable ReturnTypeCanBeEnumerable.Local // ReSharper disable InvertIf -namespace Build.Targets; +namespace Build; internal class PackTarget( - ICommands commands, + Commands commands, ITeamCityArtifactsWriter artifactsWriter, [Tag(typeof(CompatibilityCheckTarget))] ITarget> compatibilityCheckTarget) : IInitializable, ITarget> @@ -22,7 +22,6 @@ public Task InitializeAsync() => commands.Register( [SuppressMessage("Performance", "CA1861:Avoid constant arrays as arguments")] public async Task> RunAsync(CancellationToken cancellationToken) { - Info("Packing"); var packages = await compatibilityCheckTarget.RunAsync(cancellationToken); foreach (var package in packages) { diff --git a/build/Targets/Package.cs b/build/Package.cs similarity index 64% rename from build/Targets/Package.cs rename to build/Package.cs index 9235d0eb4..d84baa462 100644 --- a/build/Targets/Package.cs +++ b/build/Package.cs @@ -1,3 +1,3 @@ -namespace Build.Targets; +namespace Build; internal record Package(string Path, bool Deploy); \ No newline at end of file diff --git a/build/Program.cs b/build/Program.cs index 5f88a2c49..e37959403 100644 --- a/build/Program.cs +++ b/build/Program.cs @@ -1,21 +1,13 @@ using Build; -using IProperties = Build.Tools.IProperties; DI.Setup(nameof(Composition)) - .Root>("RootTarget") + .Root("RootTarget") .DefaultLifetime(Lifetime.PerBlock) - .Bind().To() .Bind().To() + .Bind().To() .Bind().To(_ => GetService()) .Bind().To(_ => GetService()) - // Tools - .Bind().To() - .Bind().To() - .Bind().To() - .Bind().To() - .Bind().To() // Targets - .Bind>().To() .Bind>(typeof(GeneratorTarget)).To() .Bind>>(typeof(LibrariesTarget)).To() .Bind>>(typeof(CompatibilityCheckTarget)).To() diff --git a/build/Targets/ReadmeTarget.cs b/build/ReadmeTarget.cs similarity index 95% rename from build/Targets/ReadmeTarget.cs rename to build/ReadmeTarget.cs index b7f5aaa18..d4a564663 100644 --- a/build/Targets/ReadmeTarget.cs +++ b/build/ReadmeTarget.cs @@ -1,14 +1,15 @@ // ReSharper disable InvertIf // ReSharper disable ConvertIfStatementToSwitchStatement // ReSharper disable ClassNeverInstantiated.Global -namespace Build.Targets; + +namespace Build; using Pure.DI.Benchmarks.Benchmarks; internal class ReadmeTarget( - ICommands commands, - IPaths paths, - IVersions versions, + Commands commands, + Paths paths, + Versions versions, [Tag(typeof(BenchmarksTarget))] ITarget benchmarksTarget) : IInitializable, ITarget { @@ -43,16 +44,15 @@ public Task InitializeAsync() => commands.Register( $"Generates {ReadmeHeaderFile}", "readme", "r"); - + public async Task RunAsync(CancellationToken cancellationToken) { - Info($"Generating {ReadmeFile}"); var solutionDirectory = paths.SolutionDirectory; var logsDirectory = Path.Combine(solutionDirectory, ".logs"); - + // Run benchmarks await benchmarksTarget.RunAsync(cancellationToken); - + // Delete generated files var generatedFiles = Path.Combine(logsDirectory, "Pure.DI", "Pure.DI.SourceGenerator"); if (Directory.Exists(generatedFiles)) @@ -69,27 +69,30 @@ public async Task RunAsync(CancellationToken cancellationToken) foreach (var project in projects) { - var buildResult = await new MSBuild().WithProject(project).WithTarget("clean;rebuild").BuildAsync(cancellationToken: cancellationToken); - buildResult.Succeed(); + new MSBuild() + .WithProject(project) + .WithTarget("clean;rebuild") + .Build() + .Succeed(); } new DotNetTest(usageTestsProjects).Run(); await using var readmeWriter = File.CreateText(ReadmeFile); - + await AddContent(ReadmeHeaderFile, readmeWriter, "docs"); - + await AddContent(ReadmeTemplateFile, readmeWriter); - + await readmeWriter.WriteLineAsync(""); - + var examples = await CreateExamples(cancellationToken); await GenerateExamples(examples, readmeWriter, logsDirectory); await AddContent(FooterTemplateFile, readmeWriter); - + await readmeWriter.WriteLineAsync(""); - + await AddBenchmarks(logsDirectory, readmeWriter); await readmeWriter.FlushAsync(cancellationToken); @@ -219,7 +222,7 @@ private static async Task AddContent(string sourceFile, TextWriter readmeWriter, .GroupBy(i => i[TitleKey]) .OrderBy(i => groups.TryGetValue(i.Key, out var index) ? index : int.MaxValue) .Select(i => (GroupName: i.Key, SampleItems: i.OrderBy(j => int.Parse(j[PriorityKey])).ThenBy(j => j[DescriptionKey]).ToArray())); - + return examples; } @@ -240,10 +243,10 @@ private async Task GenerateExamples(IEnumerable<(string GroupName, Dictionary FormatTitle(string title) } } - private static string CreateExampleFileName(string text) => + private static string CreateExampleFileName(string text) => text.Replace(" ", "-") - .Replace("_", string.Empty) - .Replace("'", string.Empty) - .Replace("/", string.Empty) - .Replace("`", string.Empty) - .Replace("\\", string.Empty) - .ToLowerInvariant(); - + .Replace("_", string.Empty) + .Replace("'", string.Empty) + .Replace("/", string.Empty) + .Replace("`", string.Empty) + .Replace("\\", string.Empty) + .ToLowerInvariant(); + private enum Part { Comment, diff --git a/build/Targets/RootTarget.cs b/build/RootTarget.cs similarity index 92% rename from build/Targets/RootTarget.cs rename to build/RootTarget.cs index b531a6410..786fc452d 100644 --- a/build/Targets/RootTarget.cs +++ b/build/RootTarget.cs @@ -1,11 +1,12 @@ // ReSharper disable SuggestBaseTypeForParameterInConstructor // ReSharper disable ClassNeverInstantiated.Global -namespace Build.Targets; + +namespace Build; internal class RootTarget( RootCommand rootCommand, IEnumerable initializables, - IPaths paths) + Paths paths) : ITarget { public async Task RunAsync(CancellationToken cancellationToken) @@ -16,7 +17,7 @@ public async Task RunAsync(CancellationToken cancellationToken) { await initializable.InitializeAsync(); } - + return await rootCommand.InvokeAsync(Args.ToArray()); } } \ No newline at end of file diff --git a/build/Settings.cs b/build/Settings.cs index 6b79a2ad4..93d53825b 100644 --- a/build/Settings.cs +++ b/build/Settings.cs @@ -1,20 +1,20 @@ // ReSharper disable MemberCanBeMadeStatic.Global // ReSharper disable ClassNeverInstantiated.Global + namespace Build; using System.Collections.Immutable; using NuGet.Versioning; -using IProperties = Tools.IProperties; [SuppressMessage("Performance", "CA1822:Mark members as static")] internal class Settings( - IProperties properties, - IVersions versions) + Properties properties, + Versions versions) { public static readonly VersionRange VersionRange = VersionRange.Parse("2.1.*"); - + private readonly Lazy _version = new(() => GetVersion(properties, versions)); - + public bool BuildServer { get; } = Environment.GetEnvironmentVariable("TEAMCITY_VERSION") is not null; public string Configuration => "Release"; @@ -28,7 +28,7 @@ internal class Settings( new CodeAnalysis(new Version(4, 3, 1)) ]; - private static NuGetVersion GetVersion(IProperties properties, IVersions versions) + private static NuGetVersion GetVersion(Properties properties, Versions versions) { if (!NuGetVersion.TryParse(properties["version"], out var version)) { diff --git a/build/Targets/DeployTarget.cs b/build/Targets/DeployTarget.cs deleted file mode 100644 index e7a5bdab6..000000000 --- a/build/Targets/DeployTarget.cs +++ /dev/null @@ -1,39 +0,0 @@ -// ReSharper disable ClassNeverInstantiated.Global -namespace Build.Targets; - -internal class DeployTarget( - Settings settings, - ICommands commands, - [Tag(typeof(PackTarget))] ITarget> packTarget) - : IInitializable, ITarget -{ - public Task InitializeAsync() => commands.Register( - this, - "Deploys packages", - "deploy", - "dp"); - - public async Task RunAsync(CancellationToken cancellationToken) - { - Info("Deployment"); - if (!string.IsNullOrWhiteSpace(settings.NuGetKey)) - { - var packages = await packTarget.RunAsync(cancellationToken); - foreach (var package in packages.Where(i => i.Deploy)) - { - var push = new DotNetNuGetPush() - .WithPackage(package.Path) - .WithSources("https://api.nuget.org/v3/index.json") - .WithApiKey(settings.NuGetKey); - - push.Build().Succeed(); - } - } - else - { - Warning("The NuGet key was not specified, the packages will not be pushed."); - } - - return 0; - } -} \ No newline at end of file diff --git a/build/Targets/TemplateTarget.cs b/build/TemplateTarget.cs similarity index 71% rename from build/Targets/TemplateTarget.cs rename to build/TemplateTarget.cs index fd5a2b033..0ae2148b8 100644 --- a/build/Targets/TemplateTarget.cs +++ b/build/TemplateTarget.cs @@ -1,35 +1,37 @@ // ReSharper disable StringLiteralTypo // ReSharper disable ClassNeverInstantiated.Global -namespace Build.Targets; + +namespace Build; internal class TemplateTarget( Settings settings, - ICommands commands, - IVersions versions, + Commands commands, + Versions versions, ITeamCityArtifactsWriter artifactsWriter) : IInitializable, ITarget { private const string ProjectName = "Pure.DI.Templates"; - + public Task InitializeAsync() => commands.Register( this, "Creates and deploys templates", "template", "t"); - + public async Task RunAsync(CancellationToken cancellationToken) { - Info("Creating templates"); var packageVersion = versions.GetNext(new NuGetRestoreSettings("Pure.DI"), Settings.VersionRange, 0).ToString(); - foreach (var jsonFile in new [] { + foreach (var jsonFile in new[] + { "src/Pure.DI.Templates/Templates/Pure.DI.Template.ClassLibrary/.template.config/template.json", - "src/Pure.DI.Templates/Templates/Pure.DI.Template.ConsoleApp/.template.config/template.json"}) + "src/Pure.DI.Templates/Templates/Pure.DI.Template.ConsoleApp/.template.config/template.json" + }) { var content = await File.ReadAllTextAsync(jsonFile, cancellationToken); content = content.Replace("$(version)", packageVersion); await File.WriteAllTextAsync(jsonFile, content, cancellationToken); } - + var props = new[] { ("configuration", settings.Configuration), @@ -37,29 +39,28 @@ public async Task RunAsync(CancellationToken cancellationToken) }; var projectDirectory = Path.Combine("src", ProjectName); - var pack = new DotNetPack() + new DotNetPack() .WithProject(Path.Combine(projectDirectory, $"{ProjectName}.csproj")) - .WithProps(props); + .WithProps(props) + .Build() + .Succeed(); - pack.Build().Succeed(); - var targetPackage = Path.Combine(projectDirectory, "bin", $"{ProjectName}.{packageVersion}.nupkg"); artifactsWriter.PublishArtifact($"{targetPackage} => ."); - if (!string.IsNullOrWhiteSpace(settings.NuGetKey)) - { - var push = new DotNetNuGetPush() - .WithPackage(targetPackage) - .WithSources("https://api.nuget.org/v3/index.json") - .WithApiKey(settings.NuGetKey); - - push.Build().Succeed(); - } - else + if (string.IsNullOrWhiteSpace(settings.NuGetKey)) { Warning($"The NuGet key was not specified, the package {targetPackage} will not be pushed."); + return targetPackage; } + new DotNetNuGetPush() + .WithPackage(targetPackage) + .WithSources("https://api.nuget.org/v3/index.json") + .WithApiKey(settings.NuGetKey) + .Build() + .Succeed(); + return targetPackage; } } \ No newline at end of file diff --git a/build/Tools/Commands.cs b/build/Tools/Commands.cs index b67e41f34..b803b4082 100644 --- a/build/Tools/Commands.cs +++ b/build/Tools/Commands.cs @@ -3,15 +3,21 @@ namespace Build.Tools; [SuppressMessage("Reliability", "CA2012:Use ValueTasks correctly")] -internal class Commands(RootCommand rootCommand) : ICommands +internal class Commands(RootCommand rootCommand) { - public Task Register(ITarget target, + public Task Register( + ITarget target, string description, string name, params string[] aliases) { var command = new Command(name, description); - command.SetHandler(ctx => target.RunAsync(ctx.GetCancellationToken())); + command.SetHandler(ctx => + { + WriteLine($"---------- {description} ----------", Color.Highlighted); + return target.RunAsync(ctx.GetCancellationToken()); + }); + foreach (var alias in aliases) { command.AddAlias(alias); diff --git a/build/Tools/ICommands.cs b/build/Tools/ICommands.cs deleted file mode 100644 index 7b8fe39c9..000000000 --- a/build/Tools/ICommands.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Build.Tools; - -internal interface ICommands -{ - Task Register(ITarget target, - string description, - string name, - params string[] aliases); -} \ No newline at end of file diff --git a/build/Tools/IPaths.cs b/build/Tools/IPaths.cs deleted file mode 100644 index bb87d7004..000000000 --- a/build/Tools/IPaths.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Build.Tools; - -internal interface IPaths -{ - string SolutionDirectory { get; } - - string TempDirectory { get; } -} \ No newline at end of file diff --git a/build/Tools/IProperties.cs b/build/Tools/IProperties.cs deleted file mode 100644 index d3b970c56..000000000 --- a/build/Tools/IProperties.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Build.Tools; - -internal interface IProperties -{ - string this[string name] { get; } -} \ No newline at end of file diff --git a/build/Tools/ISdk.cs b/build/Tools/ISdk.cs deleted file mode 100644 index 26e351d72..000000000 --- a/build/Tools/ISdk.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Build.Tools; - -using NuGet.Versioning; - -internal interface ISdk -{ - IEnumerable Versions { get; } -} \ No newline at end of file diff --git a/build/Tools/IVersions.cs b/build/Tools/IVersions.cs deleted file mode 100644 index f43908176..000000000 --- a/build/Tools/IVersions.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Build.Tools; - -using NuGet.Versioning; - -internal interface IVersions -{ - NuGetVersion GetNext(NuGetRestoreSettings restoreSettings, VersionRange versionRange, int patchIncrement = 1); -} \ No newline at end of file diff --git a/build/Tools/Paths.cs b/build/Tools/Paths.cs index 92650f58a..323794292 100644 --- a/build/Tools/Paths.cs +++ b/build/Tools/Paths.cs @@ -4,7 +4,7 @@ namespace Build.Tools; [SuppressMessage("Performance", "CA1822:Mark members as static")] -internal class Paths : IPaths +internal class Paths { public string SolutionDirectory => Path.GetDirectoryName(TryFindFile(Environment.CurrentDirectory, "Pure.DI.sln")) diff --git a/build/Tools/Properties.cs b/build/Tools/Properties.cs index 2c063fe3a..772aa8792 100644 --- a/build/Tools/Properties.cs +++ b/build/Tools/Properties.cs @@ -2,7 +2,7 @@ // ReSharper disable ClassNeverInstantiated.Global namespace Build.Tools; -internal class Properties : IProperties +internal class Properties { public string this[string name] { diff --git a/build/Tools/Sdk.cs b/build/Tools/Sdk.cs index 687afc4c7..528107310 100644 --- a/build/Tools/Sdk.cs +++ b/build/Tools/Sdk.cs @@ -6,7 +6,7 @@ namespace Build.Tools; using NuGet.Versioning; [SuppressMessage("Performance", "CA1822:Mark members as static")] -internal class Sdk : ISdk +internal class Sdk { private readonly Lazy> _versions = new(GetVersions); diff --git a/build/Tools/Versions.cs b/build/Tools/Versions.cs index 3c7d155e0..3ee34f835 100644 --- a/build/Tools/Versions.cs +++ b/build/Tools/Versions.cs @@ -5,7 +5,7 @@ namespace Build.Tools; using System.Text.RegularExpressions; using NuGet.Versioning; -internal partial class Versions(INuGet nuGet) : IVersions +internal partial class Versions(INuGet nuGet) { private static readonly Regex ReleaseRegex = CreateReleaseRegex(); diff --git a/build/Targets/UpdateTarget.cs b/build/UpdateTarget.cs similarity index 96% rename from build/Targets/UpdateTarget.cs rename to build/UpdateTarget.cs index 4d794ea83..ebaf56969 100644 --- a/build/Targets/UpdateTarget.cs +++ b/build/UpdateTarget.cs @@ -2,14 +2,14 @@ // ReSharper disable HeapView.DelegateAllocation // ReSharper disable HeapView.ClosureAllocation // ReSharper disable ClassNeverInstantiated.Global -namespace Build.Targets; +namespace Build; using NuGet.Versioning; internal class UpdateTarget( Settings settings, - ICommands commands, - IPaths paths) + Commands commands, + Paths paths) : IInitializable, ITarget { private const string VersionPrefix = "PUREDI_API_V"; @@ -23,7 +23,6 @@ public Task InitializeAsync() => commands.Register( [SuppressMessage("Performance", "CA1861:Avoid constant arrays as arguments")] public Task RunAsync(CancellationToken cancellationToken) { - Info("Updating internal DI version"); var solutionDirectory = paths.SolutionDirectory; var currentVersion = settings.Version; var propsFile = Path.Combine(solutionDirectory, "Directory.Build.props");