refactor(build): move BuildContext to file, add BuildSuffix and CommitHash configuration options
This commit is contained in:
parent
1491a26a3e
commit
fa0531f2c5
3 changed files with 72 additions and 49 deletions
50
build/BuildContext.cs
Normal file
50
build/BuildContext.cs
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
using Cake.Common.IO;
|
||||||
|
using Cake.Common.IO.Paths;
|
||||||
|
using Cake.Core;
|
||||||
|
using Cake.Frosting;
|
||||||
|
|
||||||
|
namespace Build;
|
||||||
|
|
||||||
|
public class BuildContext : FrostingContext
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Base source directory
|
||||||
|
/// </summary>
|
||||||
|
public ConvertableDirectoryPath BaseSourceLocation { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Powershell module project folder
|
||||||
|
/// </summary>
|
||||||
|
public ConvertableDirectoryPath PowershellModuleProjectDirectory { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Powershell module csproj location
|
||||||
|
/// </summary>
|
||||||
|
public ConvertableFilePath PowershellModuleCsproj { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Output directory for built DLLs and powershell module manifest files
|
||||||
|
/// </summary>
|
||||||
|
public ConvertableDirectoryPath PowershellModuleOutputDir { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Path to powershell script that creates the module manifest files
|
||||||
|
/// </summary>
|
||||||
|
public ConvertableFilePath CreateModuleManifestScript { get; set; }
|
||||||
|
|
||||||
|
public string BuildSuffix { get; set; }
|
||||||
|
public bool DisableCommitHash { get; set; }
|
||||||
|
|
||||||
|
public BuildContext(ICakeContext context)
|
||||||
|
: base(context)
|
||||||
|
{
|
||||||
|
BaseSourceLocation = context.Directory("../src");
|
||||||
|
PowershellModuleProjectDirectory = BaseSourceLocation + context.Directory("PowershellModule");
|
||||||
|
PowershellModuleCsproj = PowershellModuleProjectDirectory + context.File("PowershellModule.csproj");
|
||||||
|
PowershellModuleOutputDir = context.Directory("../") + context.Directory("output") + context.Directory("PowershellModule");
|
||||||
|
var buildScriptDirectory = context.Directory("./Scripts");
|
||||||
|
CreateModuleManifestScript = buildScriptDirectory + context.File("CreateModuleManifest.ps1");
|
||||||
|
BuildSuffix = context.Configuration.GetValue(nameof(BuildSuffix));
|
||||||
|
DisableCommitHash = context.Configuration.GetBoolValue(nameof(DisableCommitHash));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,9 +1,6 @@
|
||||||
using Cake.Common;
|
|
||||||
using Cake.Common.IO;
|
|
||||||
using Cake.Common.IO.Paths;
|
|
||||||
using Cake.Core;
|
|
||||||
using Cake.Frosting;
|
using Cake.Frosting;
|
||||||
using Cake.Powershell;
|
|
||||||
|
namespace Build;
|
||||||
|
|
||||||
public static class Program
|
public static class Program
|
||||||
{
|
{
|
||||||
|
|
@ -11,45 +8,8 @@ public static class Program
|
||||||
{
|
{
|
||||||
return new CakeHost()
|
return new CakeHost()
|
||||||
.UseContext<BuildContext>()
|
.UseContext<BuildContext>()
|
||||||
|
// Uncomment this if you don't want to set the suffix via the run profile program arguments
|
||||||
|
//.UseCakeSetting(nameof(BuildContext.BuildSuffix), "<your suffix here>")
|
||||||
.Run(args);
|
.Run(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BuildContext : FrostingContext
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Base source directory
|
|
||||||
/// </summary>
|
|
||||||
public ConvertableDirectoryPath BaseSourceLocation { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Powershell module project folder
|
|
||||||
/// </summary>
|
|
||||||
public ConvertableDirectoryPath PowershellModuleProjectDirectory { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Powershell module csproj location
|
|
||||||
/// </summary>
|
|
||||||
public ConvertableFilePath PowershellModuleCsproj { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Output directory for built DLLs and powershell module manifest files
|
|
||||||
/// </summary>
|
|
||||||
public ConvertableDirectoryPath PowershellModuleOutputDir { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Path to powershell script that creates the module manifest files
|
|
||||||
/// </summary>
|
|
||||||
public ConvertableFilePath CreateModuleManifestScript { get; set; }
|
|
||||||
|
|
||||||
public BuildContext(ICakeContext context)
|
|
||||||
: base(context)
|
|
||||||
{
|
|
||||||
BaseSourceLocation = context.Directory("../src");
|
|
||||||
PowershellModuleProjectDirectory = BaseSourceLocation + context.Directory("PowershellModule");
|
|
||||||
PowershellModuleCsproj = PowershellModuleProjectDirectory + context.File("PowershellModule.csproj");
|
|
||||||
PowershellModuleOutputDir = context.Directory("../") + context.Directory("output") + context.Directory("PowershellModule");
|
|
||||||
var buildScriptDirectory = context.Directory("./Scripts");
|
|
||||||
CreateModuleManifestScript = buildScriptDirectory + context.File("CreateModuleManifest.ps1");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -17,14 +17,27 @@ public class BuildTask : FrostingTask<BuildContext>
|
||||||
|
|
||||||
var buildSettings = new DotNetBuildSettings()
|
var buildSettings = new DotNetBuildSettings()
|
||||||
{
|
{
|
||||||
MSBuildSettings = new DotNetMSBuildSettings()
|
MSBuildSettings = new DotNetMSBuildSettings(),
|
||||||
{
|
|
||||||
VersionSuffix = "cake"
|
|
||||||
},
|
|
||||||
OutputDirectory = context.PowershellModuleOutputDir,
|
OutputDirectory = context.PowershellModuleOutputDir,
|
||||||
DiagnosticOutput = true
|
DiagnosticOutput = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// If a build suffix is provided, use it, otherwise whatever comes from Directory.Build.props will be used.
|
||||||
|
// It's not possible to set the actual version number for a build in this project as that is purely controlled
|
||||||
|
// from individual Directory.Build.props files
|
||||||
|
if (!string.IsNullOrEmpty(context.BuildSuffix))
|
||||||
|
{
|
||||||
|
buildSettings.MSBuildSettings.VersionSuffix = context.BuildSuffix;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Disable SourceLink automatic commit hash addition. Documentation about how that package work is garbage and
|
||||||
|
// this property is only mentioned in breaking changes https://learn.microsoft.com/en-us/dotnet/core/compatibility/sdk/8.0/source-link
|
||||||
|
// which is pretty on par for shit like this.
|
||||||
|
if (context.DisableCommitHash)
|
||||||
|
{
|
||||||
|
buildSettings.MSBuildSettings.Properties.Add("IncludeSourceRevisionInInformationalVersion", ["false"]);
|
||||||
|
}
|
||||||
|
|
||||||
// /p:DebugSymbols=false
|
// /p:DebugSymbols=false
|
||||||
buildSettings.MSBuildSettings.Properties.Add("DebugSymbols", ["false"]);
|
buildSettings.MSBuildSettings.Properties.Add("DebugSymbols", ["false"]);
|
||||||
// /p:DebugType=None
|
// /p:DebugType=None
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue