Skip to content

Commit

Permalink
refactor: reorganize .NET targets
Browse files Browse the repository at this point in the history
  • Loading branch information
Xzelsius committed May 18, 2024
1 parent f820864 commit 1df5ca8
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 137 deletions.
12 changes: 2 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,6 @@ jobs:
run: |
dotnet tool restore
- name: Restore
- name: Nuke
run: |
dotnet nuke Restore --skip
- name: Compile
run: |
dotnet nuke Compile --skip
- name: Test
run: |
dotnet nuke Test --skip
dotnet nuke
22 changes: 15 additions & 7 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
"type": "string",
"description": "The directory where artifacts are to be dropped"
},
"Configuration": {
"Continue": {
"type": "boolean",
"description": "Indicates to continue a previously failed build attempt"
},
"DotNetConfiguration": {
"type": "string",
"description": "The .NET build configuration - Default is 'Debug' (local) or 'Release' (server)",
"enum": [
"Debug",
"Release"
]
},
"Continue": {
"type": "boolean",
"description": "Indicates to continue a previously failed build attempt"
},
"Help": {
"type": "boolean",
"description": "Shows the help text for this build assembly"
Expand Down Expand Up @@ -78,8 +78,12 @@
"enum": [
"Clean",
"Compile",
"Default",
"DotNetBuild",
"DotNetPack",
"DotNetRestore",
"DotNetTest",
"Pack",
"Restore",
"Test"
]
}
Expand All @@ -96,8 +100,12 @@
"enum": [
"Clean",
"Compile",
"Default",
"DotNetBuild",
"DotNetPack",
"DotNetRestore",
"DotNetTest",
"Pack",
"Restore",
"Test"
]
}
Expand Down
33 changes: 27 additions & 6 deletions nukebuild/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,33 @@ class Build
IHaveArtifacts,
IHaveTestArtifacts,
IHavePackageArtifacts,
IHaveConfiguration,
IHaveDotNetConfiguration,
ICanClean,
ICanRestoreDotNet,
ICanCompileDotNet,
ICanTestDotNet,
ICanPackDotNet
ICanDotNetRestore,
ICanDotNetBuild,
ICanDotNetTest,
ICanDotNetPack
{
public static int Main() => Execute<Build>(x => ((ICanPackDotNet)x).Pack);
public static int Main() => Execute<Build>(x => x.Default);

Target Default => target => target
.Description("Compiles, Tests and Packs everything in the Solution")
.DependsOn(Compile)
.DependsOn(Test)
.DependsOn(Pack);

Target Compile => target => target
.Description("Builds all Projects in the Solution")
.DependsOn<IHaveCleanTarget>()
.DependsOn<IHaveDotNetBuildTarget>();

Target Test => target => target
.Description("Runs all Tests in the Solution")
.DependsOn<IHaveCleanTarget>()
.DependsOn<IHaveDotNetTestTarget>();

Target Pack => target => target
.Description("Packs all NuGet packages in the Solution")
.DependsOn<IHaveCleanTarget>()
.DependsOn<IHaveDotNetPackTarget>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,28 @@ namespace Ayaka.Nuke.DotNet;
using global::Nuke.Common.Tooling;
using global::Nuke.Common.Tools.DotNet;
using global::Nuke.Common.Utilities.Collections;
using static global::Nuke.Common.Tools.DotNet.DotNetTasks;

/// <summary>
/// Provides a target for compiling the current solution using .NET CLI to the <see cref="INukeBuild" />.
/// </summary>
public interface ICanCompileDotNet
public interface ICanDotNetBuild
: ICan,
IHaveSolution,
IHaveConfiguration,
IHaveRestoreTarget,
IHaveCompileTarget
IHaveDotNetConfiguration,
IHaveDotNetRestoreTarget,
IHaveDotNetBuildTarget
{
/// <summary>
/// Gets the base settings for compiling the current solution.
/// </summary>
/// <remarks>
/// Applies versioning information if <see cref="IHaveGitVersion" /> is implemented.
/// </remarks>
sealed Configure<DotNetBuildSettings> CompileSettingsBase
sealed Configure<DotNetBuildSettings> DotNetBuildSettingsBase
=> dotnet => dotnet
.SetProjectFile(Solution)
.SetConfiguration(Configuration)
.SetNoRestore(InvokedTargets.Contains(Restore))
.SetConfiguration(DotNetConfiguration)
.SetNoRestore(InvokedTargets.Contains(DotNetRestore))
.When(IsServerBuild, x => x.EnableContinuousIntegrationBuild())
.WhenNotNull(
this as IHaveGitVersion,
Expand All @@ -41,15 +40,16 @@ sealed Configure<DotNetBuildSettings> CompileSettingsBase
/// Gets the additional settings for compiling the current solution.
/// </summary>
/// <remarks>
/// Override this to provide additional settings for the <see cref="IHaveCompileTarget.Compile" /> target.
/// Override this to provide additional settings for the <see cref="IHaveDotNetBuildTarget.DotNetBuild" /> target.
/// </remarks>
Configure<DotNetBuildSettings> CompileSettings
Configure<DotNetBuildSettings> DotNetBuildSettings
=> dotnet => dotnet;

/// <inheritdoc />
Target IHaveCompileTarget.Compile => target => target
Target IHaveDotNetBuildTarget.DotNetBuild => target => target
.Description("Compiles the current solution using .NET CLI")
.DependsOn(Restore)
.Unlisted()
.DependsOn(DotNetRestore)
.WhenSkipped(DependencyBehavior.Skip)
.Executes(() =>
{
Expand All @@ -60,10 +60,10 @@ Configure<DotNetBuildSettings> CompileSettings
(s, o) => s.AddPair("Version", o.Versioning.NuGetVersionV2))
);
_ = DotNetBuild(
_ = DotNetTasks.DotNetBuild(
dotnet => dotnet
.Apply(CompileSettingsBase)
.Apply(CompileSettings)
.Apply(DotNetBuildSettingsBase)
.Apply(DotNetBuildSettings)
);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,31 @@

namespace Ayaka.Nuke.DotNet;

using Ayaka.Nuke;
using global::Nuke.Common;
using global::Nuke.Common.IO;
using global::Nuke.Common.Tooling;
using global::Nuke.Common.Tools.DotNet;
using global::Nuke.Common.Utilities.Collections;
using static global::Nuke.Common.Tools.DotNet.DotNetTasks;

/// <summary>
/// Provides a target for packing the current solution using .NET CLI to the <see cref="INukeBuild" />.
/// Provides a target for packing the current solution using .NET CLI to the <see cref="INukeBuild" />.
/// </summary>
public interface ICanPackDotNet
public interface ICanDotNetPack
: ICan,
IHavePackageArtifacts,
IHaveSolution,
IHaveConfiguration,
IHaveCompileTarget,
IHavePackTarget
IHaveDotNetConfiguration,
IHaveDotNetBuildTarget,
IHaveDotNetPackTarget
{
/// <summary>
/// Gets the base settings for packing the current solution.
/// Gets the base settings for packing the current solution.
/// </summary>
sealed Configure<DotNetPackSettings> PackSettingsBase
sealed Configure<DotNetPackSettings> DotNetPackSettingsBase
=> dotnet => dotnet
.SetProject(Solution)
.SetConfiguration(Configuration)
.SetNoBuild(SucceededTargets.Contains(Compile))
.SetConfiguration(DotNetConfiguration)
.SetNoBuild(SucceededTargets.Contains(DotNetBuild))
.SetOutputDirectory(PackagesDirectory)
.WhenNotNull(
this as IHaveGitRepository,
Expand All @@ -38,25 +36,26 @@ sealed Configure<DotNetPackSettings> PackSettingsBase
(d, o) => d.SetVersion(o.Versioning.NuGetVersionV2));

/// <summary>
/// Gets the additional settings for packing the current solution.
/// Gets the additional settings for packing the current solution.
/// </summary>
/// <remarks>
/// Override this to provide additional settings for the <see cref="IHavePackTarget.Pack" /> target.
/// Override this to provide additional settings for the <see cref="IHaveDotNetPackTarget.DotNetPack" />.
/// </remarks>
Configure<DotNetPackSettings> PackSettings
Configure<DotNetPackSettings> DotNetPackSettings
=> dotnet => dotnet;

/// <inheritdoc />
Target IHavePackTarget.Pack => target => target
Target IHaveDotNetPackTarget.DotNetPack => target => target
.Description("Packs the current solution using .NET CLI")
.DependsOn(Compile)
.Unlisted()
.DependsOn(DotNetBuild)
.Produces(PackagesDirectory / "*.nupkg")
.Executes(() =>
{
_ = DotNetPack(
_ = DotNetTasks.DotNetPack(
dotnet => dotnet
.Apply(PackSettingsBase)
.Apply(PackSettings)
.Apply(DotNetPackSettingsBase)
.Apply(DotNetPackSettings)
);
ReportSummary(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,42 @@ namespace Ayaka.Nuke.DotNet;
using global::Nuke.Common;
using global::Nuke.Common.Tooling;
using global::Nuke.Common.Tools.DotNet;
using static global::Nuke.Common.Tools.DotNet.DotNetTasks;

/// <summary>
/// Provides a target for restoring the current solution using .NET CLI to the <see cref="INukeBuild" />.
/// </summary>
public interface ICanRestoreDotNet
public interface ICanDotNetRestore
: ICan,
IHaveSolution,
IHaveRestoreTarget
IHaveDotNetRestoreTarget
{
/// <summary>
/// Gets the base settings for restoring the current solution.
/// </summary>
sealed Configure<DotNetRestoreSettings> RestoreSettingsBase
sealed Configure<DotNetRestoreSettings> DotNetRestoreSettingsBase
=> dotnet => dotnet
.SetProjectFile(Solution);

/// <summary>
/// Gets the additional settings for restoring the current solution.
/// </summary>
/// <remarks>
/// Override this to provide additional settings for the <see cref="IHaveRestoreTarget.Restore" /> target.
/// Override this to provide additional settings for the <see cref="IHaveDotNetRestoreTarget.DotNetRestore" /> target.
/// </remarks>
Configure<DotNetRestoreSettings> RestoreSettings
Configure<DotNetRestoreSettings> DotNetRestoreSettings
=> dotnet => dotnet;

/// <inheritdoc />
Target IHaveRestoreTarget.Restore => target => target
Target IHaveDotNetRestoreTarget.DotNetRestore => target => target
.Description("Restores the current solution using .NET CLI")
.After<IHaveCleanTarget>()
.Unlisted()
.TryDependsOn<IHaveCleanTarget>()
.Executes(() =>
{
_ = DotNetRestore(
_ = DotNetTasks.DotNetRestore(
dotnet => dotnet
.Apply(RestoreSettingsBase)
.Apply(RestoreSettings)
.Apply(DotNetRestoreSettingsBase)
.Apply(DotNetRestoreSettings)
);
});
}
Loading

0 comments on commit 1df5ca8

Please sign in to comment.