Skip to content

Commit

Permalink
Further refinement of the Nuke build class
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidRogersDev committed Nov 19, 2023
1 parent 5319f7a commit 347b795
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 40 deletions.
52 changes: 25 additions & 27 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ class Build : NukeBuild
/// - Microsoft VisualStudio https://nuke.build/visualstudio
/// - Microsoft VSCode https://nuke.build/vscode

public static int Main() => Execute<Build>(x => x.Push);

public static int Main() => Execute<Build>(b => b.Push);

[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;
Expand Down Expand Up @@ -58,21 +57,21 @@ class Build : NukeBuild
static AbsolutePath ArtifactsDirectory => RootDirectory / FileSystem.ArtifactsDirectory;

Target Print => _ => _
.Description(Descriptions.Print)
.Description(Description.Print)
.Executes(() =>
{
Log.Information(LogMessage.ReleaseNotes, ReleaseNotes ?? ProjectValues.NoValue);
Log.Information(LogMessage.ReleaseNotes, ReleaseNotes ?? ProjectValue.NoValue);
Log.Information(LogMessage.RootDirectory, RootDirectory.Name);
Log.Information(LogMessage.MajorMinorPatch, GitVersion.MajorMinorPatch);
Log.Information(LogMessage.NugetVersion, GitVersion.NuGetVersion);
Log.Information(LogMessage.PreReleaseLabel, GitVersion?.PreReleaseLabel ?? ProjectValues.NoValue);
Log.Information(LogMessage.Configuration, Configuration?.ToString() ?? ProjectValues.NoValue);
Log.Information(LogMessage.PreReleaseLabel, GitVersion?.PreReleaseLabel ?? ProjectValue.NoValue);
Log.Information(LogMessage.Configuration, Configuration?.ToString() ?? ProjectValue.NoValue);

IsPublishableBranch = GitVersion.BranchName.StartsWith(Branch.Release, StringComparison.OrdinalIgnoreCase);
});

Target Clean => _ => _
.Description(Descriptions.Clean)
.Description(Description.Clean)
.DependsOn(Print)
.Executes(() =>
{
Expand All @@ -85,7 +84,7 @@ class Build : NukeBuild
});

Target Restore => _ => _
.Description(Descriptions.Restore)
.Description(Description.Restore)
.DependsOn(Clean)
.Executes(() =>
{
Expand All @@ -97,7 +96,7 @@ class Build : NukeBuild
});

Target Compile => _ => _
.Description(Descriptions.Compile)
.Description(Description.Compile)
.DependsOn(Restore)
.Executes(() =>
{
Expand All @@ -110,7 +109,7 @@ from framework in project.GetTargetFrameworks()
_.SetProject(Solution)
.EnableNoRestore()
.SetConfiguration(Configuration)
.SetCopyright(PackageValues.Copyright)
.SetCopyright(PackageValue.Copyright)
.SetAssemblyVersion(GitVersion.AssemblySemFileVer)
.SetFileVersion(GitVersion.MajorMinorPatch)
.SetVersion(GitVersion.NuGetVersion)
Expand All @@ -123,7 +122,7 @@ from framework in project.GetTargetFrameworks()
});

Target Test => _ => _
.Description(Descriptions.Test)
.Description(Description.Test)
.DependsOn(Compile)
.Executes(() =>
{
Expand All @@ -136,43 +135,42 @@ from framework in project.GetTargetFrameworks()
});

Target Pack => _ => _
.Description(Descriptions.Pack)
.Description(Description.Pack)
.DependsOn(Test)
.Executes(() => DotNetPack(s => s
.SetProject(Solution.BusinessValidation)
.SetConfiguration(Configuration)
.EnableNoBuild()
.EnableNoRestore()
.SetNoDependencies(true)
.SetPackageId(ProjectValues.BusinessValidationProject)
.SetTitle(ProjectValues.BusinessValidationProject)
.SetPackageId(Solution.BusinessValidation.Name)
.SetTitle(Solution.BusinessValidation.Name)
.SetVersion(GitVersion.NuGetVersion)
.SetRepositoryType(AzurePipelinesRepositoryType.Git.ToString().ToLowerInvariant())
.SetPackageReleaseNotes(ReleaseNotes)
.SetPackageProjectUrl(PackageValues.ProjectUrl)
.SetAuthors(PackageValues.Author)
.SetProperty(PackageProperties.PackageLicenseExpression, PackageValues.MITLicence)
.SetPackageTags(PackageValues.Tags)
.SetPackageProjectUrl(PackageValue.ProjectUrl)
.SetAuthors(PackageValue.Author)
.SetProperty(PackageProperty.PackageLicenseExpression, PackageValue.MITLicence)
.SetPackageTags(PackageValue.Tags)
.SetPackageRequireLicenseAcceptance(false)
.SetDescription(PackageValues.Description)
.SetRepositoryUrl(PackageValues.RepositoryUrl)
.SetProperty(PackageProperties.RepositoryBranch, GitVersion.BranchName)
.SetProperty(PackageProperties.RepositoryCommit, GitVersion.Sha)
.SetProperty(PackageProperties.Copyright, PackageValues.Copyright)
.SetProperty(PackageProperties.PackageReadmeFile, PackageValues.Readme)
.SetProperty(PackageProperties.PackageIcon, PackageValues.Icon)
.SetDescription(PackageValue.Description)
.SetRepositoryUrl(PackageValue.RepositoryUrl)
.SetProperty(PackageProperty.RepositoryBranch, GitVersion.BranchName)
.SetProperty(PackageProperty.RepositoryCommit, GitVersion.Sha)
.SetProperty(PackageProperty.Copyright, PackageValue.Copyright)
.SetProperty(PackageProperty.PackageReadmeFile, PackageValue.Readme)
.SetProperty(PackageProperty.PackageIcon, PackageValue.Icon)
.SetOutputDirectory(ArtifactsDirectory)
));

Target Push => _ => _
.Description(Descriptions.Push)
.Description(Description.Push)
.OnlyWhenStatic(() => IsServerBuild) // checked before the build steps run.
.OnlyWhenDynamic(() => IsPublishableBranch) // checked during run. This variable is set in the Print task.
.Requires(() => NugetOrgNugetApiKey)
.Requires(() => NugetOrgNugetApiUrl)
.Requires(() => PackagesNugetApiKey)
.Requires(() => PackagesNugetApiUrl)
.Requires(() => Configuration.Equals(Configuration.Release))
.DependsOn(Pack)
.Executes(() =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Invariants
{
public sealed class Descriptions
public sealed class Description
{
public const string Clean = "Cleans the project.";
public const string Compile = "Compiles the project.";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Invariants
{
public sealed class PackageProperties
public sealed class PackageProperty
{
public const string Copyright = "Copyright";
public const string PackageIcon = "PackageIcon";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Invariants
{
public sealed class PackageValues
public sealed class PackageValue
{
public const string Author = "David Rogers";
public static string Copyright = $"{Author} 2022 - {DateTime.Now.Year}";
Expand Down
7 changes: 7 additions & 0 deletions build/Invariants/ProjectValue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Invariants
{
public sealed class ProjectValue
{
public const string NoValue = "No value";
}
}
9 changes: 0 additions & 9 deletions build/Invariants/ProjectValues.cs

This file was deleted.

2 changes: 1 addition & 1 deletion build/_build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</ItemGroup>

<ItemGroup>
<PackageDownload Include="GitVersion.Tool" Version="[5.11.1]" />
<PackageDownload Include="GitVersion.Tool" Version="[5.12.0]" />
</ItemGroup>

</Project>

0 comments on commit 347b795

Please sign in to comment.