Update nuke build with the following changes:

- Remove obsolete sample targets
- Restore and build solution (.Lean) instead of projects
- Read version from common.props, compare with latest changelog version
  and fail if not equal
- Keep PostFix separate from version (AssemblyVersion may not have
  a postfix), so the postfix will go into the package version and
  file name as well as the informational version (visible in file
  properties dialog on Windows)
- Add "ElectronNET.Core " as prefix to GitHub release names (to
  disambiguate with earlier versions)
This commit is contained in:
softworkz
2025-10-14 00:17:05 +02:00
parent 50b49068d8
commit bef7a42fbb
4 changed files with 77 additions and 151 deletions

View File

@@ -1,11 +1,15 @@
{ {
"$schema": "http://json-schema.org/draft-04/schema#", "$schema": "http://json-schema.org/draft-04/schema#",
"title": "Build Schema",
"$ref": "#/definitions/build", "$ref": "#/definitions/build",
"title": "Build Schema",
"definitions": { "definitions": {
"build": { "build": {
"type": "object", "type": "object",
"properties": { "properties": {
"CommonPropsFilePath": {
"type": "string",
"description": "common.props file path - to determine the configured version"
},
"Configuration": { "Configuration": {
"type": "string", "type": "string",
"description": "Configuration to build - Default is 'Debug' (local) or 'Release' (server)", "description": "Configuration to build - Default is 'Debug' (local) or 'Release' (server)",
@@ -64,7 +68,7 @@
}, },
"ReleaseNotesFilePath": { "ReleaseNotesFilePath": {
"type": "string", "type": "string",
"description": "ReleaseNotesFilePath - To determine the SemanticVersion" "description": "ReleaseNotesFilePath - To determine the lates changelog version"
}, },
"Root": { "Root": {
"type": "string", "type": "string",
@@ -78,14 +82,8 @@
"enum": [ "enum": [
"Clean", "Clean",
"Compile", "Compile",
"CompileSample",
"CreatePackages", "CreatePackages",
"Default", "Default",
"ElectronizeCustomWin7TargetSample",
"ElectronizeGenericTargetSample",
"ElectronizeLinuxTargetSample",
"ElectronizeMacOsTargetSample",
"ElectronizeWindowsTargetSample",
"Package", "Package",
"PrePublish", "PrePublish",
"Publish", "Publish",
@@ -109,14 +107,8 @@
"enum": [ "enum": [
"Clean", "Clean",
"Compile", "Compile",
"CompileSample",
"CreatePackages", "CreatePackages",
"Default", "Default",
"ElectronizeCustomWin7TargetSample",
"ElectronizeGenericTargetSample",
"ElectronizeLinuxTargetSample",
"ElectronizeMacOsTargetSample",
"ElectronizeWindowsTargetSample",
"Package", "Package",
"PrePublish", "PrePublish",
"Publish", "Publish",
@@ -141,4 +133,4 @@
} }
} }
} }
} }

View File

@@ -1,4 +1,4 @@
{ {
"$schema": "./build.schema.json", "$schema": "./build.schema.json",
"Solution": "src/ElectronNET.sln" "Solution": "src/ElectronNET.Lean.sln"
} }

View File

@@ -18,6 +18,7 @@ using System.Linq;
using static Nuke.Common.IO.FileSystemTasks; using static Nuke.Common.IO.FileSystemTasks;
using static Nuke.Common.IO.PathConstruction; using static Nuke.Common.IO.PathConstruction;
using static Nuke.Common.Tools.DotNet.DotNetTasks; using static Nuke.Common.Tools.DotNet.DotNetTasks;
// ReSharper disable ArrangeThisQualifier
class Build : NukeBuild class Build : NukeBuild
{ {
@@ -27,25 +28,20 @@ class Build : NukeBuild
/// - Microsoft VisualStudio https://nuke.build/visualstudio /// - Microsoft VisualStudio https://nuke.build/visualstudio
/// - Microsoft VSCode https://nuke.build/vscode /// - Microsoft VSCode https://nuke.build/vscode
public static int Main () => Execute<Build>(x => x.RunUnitTests); public static int Main() => Execute<Build>(x => x.RunUnitTests);
[Nuke.Common.Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")] [Nuke.Common.Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release; readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;
[Nuke.Common.Parameter("ReleaseNotesFilePath - To determine the SemanticVersion")] [Nuke.Common.Parameter("ReleaseNotesFilePath - To determine the lates changelog version")]
readonly AbsolutePath ReleaseNotesFilePath = RootDirectory / "Changelog.md"; readonly AbsolutePath ReleaseNotesFilePath = RootDirectory / "Changelog.md";
[Nuke.Common.Parameter("common.props file path - to determine the configured version")]
readonly AbsolutePath CommonPropsFilePath = RootDirectory / "src" / "common.props";
[Solution] [Solution]
readonly Solution Solution; readonly Solution Solution;
string TargetProjectName => "ElectronNET";
string ApiTargetLibName => $"{TargetProjectName}.API";
string CliTargetLibName => $"{TargetProjectName}.CLI";
string DemoTargetLibName => $"{TargetProjectName}.WebApp";
AbsolutePath SourceDirectory => RootDirectory / "src"; AbsolutePath SourceDirectory => RootDirectory / "src";
AbsolutePath ResultDirectory => RootDirectory / "artifacts"; AbsolutePath ResultDirectory => RootDirectory / "artifacts";
@@ -60,18 +56,7 @@ class Build : NukeBuild
string Version { get; set; } string Version { get; set; }
AbsolutePath[] Projects string VersionPostFix { get; set; }
{
get
{
var api = SourceDirectory / ApiTargetLibName / $"{ApiTargetLibName}.csproj";
var cli = SourceDirectory / CliTargetLibName / $"{CliTargetLibName}.csproj";
var projects = new[] { api, cli };
return projects;
}
}
string Framework => Solution.GetProject(DemoTargetLibName).GetProperty("TargetFramework");
protected override void OnBuildInitialized() protected override void OnBuildInitialized()
{ {
@@ -84,9 +69,19 @@ class Build : NukeBuild
LatestReleaseNotes = ChangeLog.First(); LatestReleaseNotes = ChangeLog.First();
LatestReleaseNotes.NotNull("LatestVersion could not be read!"); LatestReleaseNotes.NotNull("LatestVersion could not be read!");
Log.Debug("Using LastestVersion from ChangeLog: {LatestVersion}", LatestReleaseNotes.Version); var propsParser = new CommonPropsParser();
var propsVersion = propsParser.Parse(CommonPropsFilePath);
propsVersion.NotNull("Version from common.props could not be read!");
Assert.True(propsVersion == LatestReleaseNotes.Version,
$"The version in common.props ({propsVersion}) does not " +
$"equal the latest version in the changelog ({LatestReleaseNotes.Version})");
Log.Debug("Using version: {LatestVersion}", propsVersion);
SemVersion = LatestReleaseNotes.SemVersion; SemVersion = LatestReleaseNotes.SemVersion;
Version = LatestReleaseNotes.Version.ToString(); Version = propsVersion.ToString();
if (GitHubActions != null) if (GitHubActions != null)
{ {
@@ -96,13 +91,17 @@ class Build : NukeBuild
if (ScheduledTargets.Contains(Default)) if (ScheduledTargets.Contains(Default))
{ {
Version = $"{Version}-ci.{buildNumber}"; VersionPostFix = $"-ci.{buildNumber}";
} }
else if (ScheduledTargets.Contains(PrePublish)) else if (ScheduledTargets.Contains(PrePublish))
{ {
Version = $"{Version}-alpha.{buildNumber}"; VersionPostFix = $"-pre.{buildNumber}";
} }
} }
else if (ScheduledTargets.Contains(PrePublish))
{
VersionPostFix = $"-pre";
}
Log.Information("Building version: {Version}", Version); Log.Information("Building version: {Version}", Version);
} }
@@ -117,130 +116,32 @@ class Build : NukeBuild
Target Restore => _ => _ Target Restore => _ => _
.Executes(() => .Executes(() =>
{ {
Projects.ForEach(project => DotNetRestore(s => s.SetProjectFile(Solution.Path));
{
DotNetRestore(s => s
.SetProjectFile(project));
});
}); });
Target Compile => _ => _ Target Compile => _ => _
.DependsOn(Restore) .DependsOn(Restore)
.Executes(() => .Executes(() =>
{ {
Projects.ForEach(project => DotNetBuild(s => s
{ .SetProjectFile(Solution.Path)
DotNetBuild(s => s .SetConfiguration(Configuration)
.SetProjectFile(project) .SetProperty("GeneratePackageOnBuild", "True")
.SetVersion(Version) .SetProperty("VersionPostFix", VersionPostFix ?? string.Empty));
.SetConfiguration(Configuration)
.EnableNoRestore());
});
}); });
Target RunUnitTests => _ => _ Target RunUnitTests => _ => _
.DependsOn(Compile) .DependsOn(Compile)
.Executes(() => .Executes(() =>
{ {
Projects.ForEach(project => // There aren't any yet
{
DotNetTest(s => s
.SetProjectFile(project)
.SetConfiguration(Configuration)
.EnableNoRestore()
.EnableNoBuild());
});
}); });
Target CreatePackages => _ => _ Target CreatePackages => _ => _
.DependsOn(Compile) .DependsOn(Compile)
.Executes(() => .Executes(() =>
{ {
Projects.ForEach(project => // Packages are created on build
{
DotNetPack(s => s
.SetProject(project)
.SetVersion(Version)
.SetConfiguration(Configuration)
.SetOutputDirectory(ResultDirectory)
.SetIncludeSymbols(true)
.SetSymbolPackageFormat("snupkg")
.EnableNoRestore()
);
});
});
Target CompileSample => _ => _
.DependsOn(Compile)
.Executes(() =>
{
var sample = SourceDirectory / DemoTargetLibName / $"{DemoTargetLibName}.csproj";
DotNetBuild(s => s.SetProjectFile(sample).SetConfiguration(Configuration));
});
Target ElectronizeGenericTargetSample => _ => _
.DependsOn(CompileSample)
.Executes(() =>
{
var sample = SourceDirectory / DemoTargetLibName;
var cli = SourceDirectory / CliTargetLibName / $"{CliTargetLibName}.csproj";
var args = "build /target custom win7-x86;win /dotnet-configuration Debug /electron-arch ia32 /electron-params \"--publish never\"";
var cmd = $"run --project {cli} --framework {Framework} -- {args}";
Log.Debug(cmd);
DotNet(cmd, sample);
});
Target ElectronizeWindowsTargetSample => _ => _
.DependsOn(CompileSample)
.Executes(() =>
{
var sample = SourceDirectory / DemoTargetLibName;
var cli = SourceDirectory / CliTargetLibName / $"{CliTargetLibName}.csproj";
var args = "build /target win /electron-params \"--publish never\"";
var cmd =$"run --project {cli} --framework {Framework} -- {args}";
Log.Debug(cmd);
DotNet(cmd, sample);
});
Target ElectronizeCustomWin7TargetSample => _ => _
.DependsOn(CompileSample)
.Executes(() =>
{
var sample = SourceDirectory / DemoTargetLibName;
var cli = SourceDirectory / CliTargetLibName / $"{CliTargetLibName}.csproj";
var args = "build /target custom win7-x86;win /electron-params \"--publish never\"";
var cmd =$"run --project {cli} --framework {Framework} -- {args}";
Log.Debug(cmd);
DotNet(cmd, sample);
});
Target ElectronizeMacOsTargetSample => _ => _
.DependsOn(CompileSample)
.Executes(() =>
{
var sample = SourceDirectory / DemoTargetLibName;
var cli = SourceDirectory / CliTargetLibName / $"{CliTargetLibName}.csproj";
var args = "build /target osx /electron-params \"--publish never\"";
var cmd =$"run --project {cli} --framework {Framework} -- {args}";
Log.Debug(cmd);
DotNet(cmd, sample);
});
Target ElectronizeLinuxTargetSample => _ => _
.DependsOn(CompileSample)
.Executes(() =>
{
var sample = SourceDirectory / DemoTargetLibName;
var cli = SourceDirectory / CliTargetLibName / $"{CliTargetLibName}.csproj";
var args = "build /target linux /electron-params \"--publish never\"";
var cmd =$"run --project {cli} --framework {Framework} -- {args}";
Log.Debug(cmd);
DotNet(cmd, sample);
}); });
Target PublishPackages => _ => _ Target PublishPackages => _ => _
@@ -292,9 +193,9 @@ class Build : NukeBuild
new InMemoryCredentialStore(credentials)); new InMemoryCredentialStore(credentials));
GitHubTasks.GitHubClient.Repository.Release GitHubTasks.GitHubClient.Repository.Release
.Create("ElectronNET", "Electron.NET", new NewRelease(Version) .Create("ElectronNET", "Electron.NET", new NewRelease(Version + VersionPostFix)
{ {
Name = Version, Name = "ElectronNET.Core " + Version + VersionPostFix,
Body = String.Join(Environment.NewLine, LatestReleaseNotes.Notes), Body = String.Join(Environment.NewLine, LatestReleaseNotes.Notes),
Prerelease = true, Prerelease = true,
TargetCommitish = "develop", TargetCommitish = "develop",
@@ -330,7 +231,7 @@ class Build : NukeBuild
GitHubTasks.GitHubClient.Repository.Release GitHubTasks.GitHubClient.Repository.Release
.Create("ElectronNET", "Electron.NET", new NewRelease(Version) .Create("ElectronNET", "Electron.NET", new NewRelease(Version)
{ {
Name = Version, Name = "ElectronNET.Core " + Version,
Body = String.Join(Environment.NewLine, LatestReleaseNotes.Notes), Body = String.Join(Environment.NewLine, LatestReleaseNotes.Notes),
Prerelease = false, Prerelease = false,
TargetCommitish = "main", TargetCommitish = "main",

33
nuke/CommonPropsParser.cs Normal file
View File

@@ -0,0 +1,33 @@
using System;
using System.Linq;
using System.Xml.Linq;
/// <summary>
/// Parses a version from an MSBuild .props file (XML).
/// </summary>
public sealed class CommonPropsParser
{
/// <summary>
/// Initializes a new instance of the <see cref="ReleaseNotesParser"/> class.
/// </summary>
public CommonPropsParser()
{
}
public Version Parse(string propsPath)
{
var doc = XDocument.Load(propsPath);
var versionElement = doc
.Descendants()
.FirstOrDefault(e => e.Name.LocalName == "Version");
if (Version.TryParse(versionElement?.Value.Trim(), out var version))
{
version = new Version(version.Major, version.Minor, version.Build);
return version;
}
return null;
}
}