From 1a1879e93348d91bd06370075fe0e8628c4fa278 Mon Sep 17 00:00:00 2001 From: Cyrille NDOUMBE Date: Sat, 24 Dec 2022 01:35:34 +0100 Subject: [PATCH] Changed Configuration from class to a real enum (#34) --- .nuke/build.schema.json | 5 ++- build/Candoumbe.Pipelines.Build.csproj | 33 ------------------- build/Pipeline.cs | 2 +- .../Candoumbe.Pipelines.csproj | 1 - .../Components/Configuration.cs | 25 ++++---------- .../Components/IBenchmark.cs | 4 +-- .../Components/ICompile.cs | 2 +- .../Components/IHaveConfiguration.cs | 3 +- src/Candoumbe.Pipelines/Components/IPack.cs | 2 +- .../Components/IUnitTest.cs | 2 +- 10 files changed, 18 insertions(+), 61 deletions(-) diff --git a/.nuke/build.schema.json b/.nuke/build.schema.json index b53c8e5..f77e410 100644 --- a/.nuke/build.schema.json +++ b/.nuke/build.schema.json @@ -12,7 +12,10 @@ }, "Configuration": { "type": "string", - "enum": [] + "enum": [ + "Debug", + "Release" + ] }, "Continue": { "type": "boolean", diff --git a/build/Candoumbe.Pipelines.Build.csproj b/build/Candoumbe.Pipelines.Build.csproj index 943cc10..6cfee3f 100644 --- a/build/Candoumbe.Pipelines.Build.csproj +++ b/build/Candoumbe.Pipelines.Build.csproj @@ -60,37 +60,4 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/build/Pipeline.cs b/build/Pipeline.cs index f9dc2fb..f20bbd1 100644 --- a/build/Pipeline.cs +++ b/build/Pipeline.cs @@ -73,7 +73,7 @@ public class Pipeline : NukeBuild, IHaveSecret { /// - IEnumerable IClean.DirectoriesToDelete => RootDirectory.GlobDirectories("**/bin", "**/obj"); + IEnumerable IClean.DirectoriesToDelete => this.Get().SourceDirectory.GlobDirectories("**/bin", "**/obj"); /// IEnumerable IClean.DirectoriesToEnsureExistance => new[] diff --git a/src/Candoumbe.Pipelines/Candoumbe.Pipelines.csproj b/src/Candoumbe.Pipelines/Candoumbe.Pipelines.csproj index 3374431..6bd3d7a 100644 --- a/src/Candoumbe.Pipelines/Candoumbe.Pipelines.csproj +++ b/src/Candoumbe.Pipelines/Candoumbe.Pipelines.csproj @@ -8,7 +8,6 @@ - diff --git a/src/Candoumbe.Pipelines/Components/Configuration.cs b/src/Candoumbe.Pipelines/Components/Configuration.cs index eb5ff83..be2e0dc 100644 --- a/src/Candoumbe.Pipelines/Components/Configuration.cs +++ b/src/Candoumbe.Pipelines/Components/Configuration.cs @@ -1,29 +1,18 @@ -using JetBrains.Annotations; - -using Nuke.Common.Tooling; - -using System.ComponentModel; - -namespace Candoumbe.Pipelines.Components +namespace Candoumbe.Pipelines.Components { /// - /// Configuration that can be used throughout CI/CD pipelines + /// Configuration that can be used to compile an application /// - [PublicAPI] - [TypeConverter(typeof(TypeConverter))] - public class Configuration : Enumeration + public enum Configuration { /// - /// The "Debug" mode + /// Debug mode /// - public static Configuration Debug => new() { Value = nameof(Debug) }; + Debug, /// - /// The "release" mode + /// Release mode /// - public static Configuration Release => new() { Value = nameof(Release) }; - - /// - public static implicit operator string(Configuration configuration) => configuration.Value; + Release } } diff --git a/src/Candoumbe.Pipelines/Components/IBenchmark.cs b/src/Candoumbe.Pipelines/Components/IBenchmark.cs index 26e51a4..670bf08 100644 --- a/src/Candoumbe.Pipelines/Components/IBenchmark.cs +++ b/src/Candoumbe.Pipelines/Components/IBenchmark.cs @@ -37,7 +37,7 @@ public interface IBenchmark : ICompile, IHaveArtifacts { BenchmarkProjects.ForEach(csproj => { - DotNetRun(s => s.SetConfiguration(Configuration.Release) + DotNetRun(s => s.SetConfiguration(nameof(Configuration.Release)) .SetProjectFile(csproj) .CombineWith(csproj.GetTargetFrameworks(), (setting, framework) => setting.SetFramework(framework)) @@ -50,7 +50,7 @@ public interface IBenchmark : ICompile, IHaveArtifacts /// Configures the way performance tests are run. /// public sealed Configure BenchmarksSettingsBase => _ => _ - .SetConfiguration(Configuration.Release) + .SetConfiguration(nameof(Configuration.Release)) .SetProcessArgumentConfigurator(args => args.Add("-- --filter {0}", "*", customValue: true) .Add("--artifacts {0}", BenchmarkResultDirectory) .Add("--join")); diff --git a/src/Candoumbe.Pipelines/Components/ICompile.cs b/src/Candoumbe.Pipelines/Components/ICompile.cs index 8150cbf..bc21585 100644 --- a/src/Candoumbe.Pipelines/Components/ICompile.cs +++ b/src/Candoumbe.Pipelines/Components/ICompile.cs @@ -42,7 +42,7 @@ public interface ICompile : IRestore, IHaveConfiguration public sealed Configure CompileSettingsBase => _ => _ .SetNoRestore(SucceededTargets.Contains(Restore) || SkippedTargets.Contains(Restore)) .SetProjectFile(Solution) - .SetConfiguration(Configuration) + .SetConfiguration(Configuration.ToString()) .SetContinuousIntegrationBuild(IsServerBuild) .WhenNotNull(this as IHaveGitVersion, (settings, gitVersion) => settings.SetAssemblyVersion(gitVersion.GitVersion.AssemblySemVer) diff --git a/src/Candoumbe.Pipelines/Components/IHaveConfiguration.cs b/src/Candoumbe.Pipelines/Components/IHaveConfiguration.cs index 9724a48..130ffb2 100644 --- a/src/Candoumbe.Pipelines/Components/IHaveConfiguration.cs +++ b/src/Candoumbe.Pipelines/Components/IHaveConfiguration.cs @@ -14,6 +14,5 @@ public interface IHaveConfiguration : INukeBuild /// Configuration currently supported by the pipeline /// [Parameter] - public Configuration Configuration => TryGetValue(() => Configuration) ?? - (IsLocalBuild ? Configuration.Debug : Configuration.Release); + public Configuration Configuration => IsLocalBuild ? Configuration.Debug : Configuration.Release; } \ No newline at end of file diff --git a/src/Candoumbe.Pipelines/Components/IPack.cs b/src/Candoumbe.Pipelines/Components/IPack.cs index 4641927..b59c0fb 100644 --- a/src/Candoumbe.Pipelines/Components/IPack.cs +++ b/src/Candoumbe.Pipelines/Components/IPack.cs @@ -61,7 +61,7 @@ public interface IPack : IHaveArtifacts, ICompile .SetOutputDirectory(PackagesDirectory) .SetNoBuild(SucceededTargets.Contains(Compile) || SkippedTargets.Contains(Compile)) .SetNoRestore(SucceededTargets.Contains(Restore) || SucceededTargets.Contains(Compile)) - .SetConfiguration(Configuration) + .SetConfiguration(Configuration.ToString()) .SetSymbolPackageFormat(DotNetSymbolPackageFormat.snupkg) .WhenNotNull(this as IHaveGitVersion, (_, versioning) => _.SetAssemblyVersion(versioning.GitVersion.AssemblySemVer) diff --git a/src/Candoumbe.Pipelines/Components/IUnitTest.cs b/src/Candoumbe.Pipelines/Components/IUnitTest.cs index 64c5ab0..445694e 100644 --- a/src/Candoumbe.Pipelines/Components/IUnitTest.cs +++ b/src/Candoumbe.Pipelines/Components/IUnitTest.cs @@ -65,7 +65,7 @@ public interface IUnitTest : ICompile, IHaveTests, IHaveCoverage }); internal sealed Configure UnitTestSettingsBase => _ => _ - .SetConfiguration(Configuration) + .SetConfiguration(Configuration.ToString()) .ResetVerbosity() .EnableCollectCoverage() .EnableUseSourceLink()