Skip to content

Commit bef7a42

Browse files
committed
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)
1 parent 50b4906 commit bef7a42

File tree

4 files changed

+77
-151
lines changed

4 files changed

+77
-151
lines changed

.nuke/build.schema.json

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
{
22
"$schema": "http://json-schema.org/draft-04/schema#",
3-
"title": "Build Schema",
43
"$ref": "#/definitions/build",
4+
"title": "Build Schema",
55
"definitions": {
66
"build": {
77
"type": "object",
88
"properties": {
9+
"CommonPropsFilePath": {
10+
"type": "string",
11+
"description": "common.props file path - to determine the configured version"
12+
},
913
"Configuration": {
1014
"type": "string",
1115
"description": "Configuration to build - Default is 'Debug' (local) or 'Release' (server)",
@@ -64,7 +68,7 @@
6468
},
6569
"ReleaseNotesFilePath": {
6670
"type": "string",
67-
"description": "ReleaseNotesFilePath - To determine the SemanticVersion"
71+
"description": "ReleaseNotesFilePath - To determine the lates changelog version"
6872
},
6973
"Root": {
7074
"type": "string",
@@ -78,14 +82,8 @@
7882
"enum": [
7983
"Clean",
8084
"Compile",
81-
"CompileSample",
8285
"CreatePackages",
8386
"Default",
84-
"ElectronizeCustomWin7TargetSample",
85-
"ElectronizeGenericTargetSample",
86-
"ElectronizeLinuxTargetSample",
87-
"ElectronizeMacOsTargetSample",
88-
"ElectronizeWindowsTargetSample",
8987
"Package",
9088
"PrePublish",
9189
"Publish",
@@ -109,14 +107,8 @@
109107
"enum": [
110108
"Clean",
111109
"Compile",
112-
"CompileSample",
113110
"CreatePackages",
114111
"Default",
115-
"ElectronizeCustomWin7TargetSample",
116-
"ElectronizeGenericTargetSample",
117-
"ElectronizeLinuxTargetSample",
118-
"ElectronizeMacOsTargetSample",
119-
"ElectronizeWindowsTargetSample",
120112
"Package",
121113
"PrePublish",
122114
"Publish",
@@ -141,4 +133,4 @@
141133
}
142134
}
143135
}
144-
}
136+
}

.nuke/parameters.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"$schema": "./build.schema.json",
3-
"Solution": "src/ElectronNET.sln"
3+
"Solution": "src/ElectronNET.Lean.sln"
44
}

nuke/Build.cs

Lines changed: 36 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using static Nuke.Common.IO.FileSystemTasks;
1919
using static Nuke.Common.IO.PathConstruction;
2020
using static Nuke.Common.Tools.DotNet.DotNetTasks;
21+
// ReSharper disable ArrangeThisQualifier
2122

2223
class Build : NukeBuild
2324
{
@@ -27,25 +28,20 @@ class Build : NukeBuild
2728
/// - Microsoft VisualStudio https://nuke.build/visualstudio
2829
/// - Microsoft VSCode https://nuke.build/vscode
2930

30-
public static int Main () => Execute<Build>(x => x.RunUnitTests);
31+
public static int Main() => Execute<Build>(x => x.RunUnitTests);
3132

3233
[Nuke.Common.Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
3334
readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;
3435

35-
[Nuke.Common.Parameter("ReleaseNotesFilePath - To determine the SemanticVersion")]
36+
[Nuke.Common.Parameter("ReleaseNotesFilePath - To determine the lates changelog version")]
3637
readonly AbsolutePath ReleaseNotesFilePath = RootDirectory / "Changelog.md";
3738

39+
[Nuke.Common.Parameter("common.props file path - to determine the configured version")]
40+
readonly AbsolutePath CommonPropsFilePath = RootDirectory / "src" / "common.props";
41+
3842
[Solution]
3943
readonly Solution Solution;
4044

41-
string TargetProjectName => "ElectronNET";
42-
43-
string ApiTargetLibName => $"{TargetProjectName}.API";
44-
45-
string CliTargetLibName => $"{TargetProjectName}.CLI";
46-
47-
string DemoTargetLibName => $"{TargetProjectName}.WebApp";
48-
4945
AbsolutePath SourceDirectory => RootDirectory / "src";
5046

5147
AbsolutePath ResultDirectory => RootDirectory / "artifacts";
@@ -60,18 +56,7 @@ class Build : NukeBuild
6056

6157
string Version { get; set; }
6258

63-
AbsolutePath[] Projects
64-
{
65-
get
66-
{
67-
var api = SourceDirectory / ApiTargetLibName / $"{ApiTargetLibName}.csproj";
68-
var cli = SourceDirectory / CliTargetLibName / $"{CliTargetLibName}.csproj";
69-
var projects = new[] { api, cli };
70-
return projects;
71-
}
72-
}
73-
74-
string Framework => Solution.GetProject(DemoTargetLibName).GetProperty("TargetFramework");
59+
string VersionPostFix { get; set; }
7560

7661
protected override void OnBuildInitialized()
7762
{
@@ -84,9 +69,19 @@ protected override void OnBuildInitialized()
8469
LatestReleaseNotes = ChangeLog.First();
8570
LatestReleaseNotes.NotNull("LatestVersion could not be read!");
8671

87-
Log.Debug("Using LastestVersion from ChangeLog: {LatestVersion}", LatestReleaseNotes.Version);
72+
var propsParser = new CommonPropsParser();
73+
74+
var propsVersion = propsParser.Parse(CommonPropsFilePath);
75+
76+
propsVersion.NotNull("Version from common.props could not be read!");
77+
78+
Assert.True(propsVersion == LatestReleaseNotes.Version,
79+
$"The version in common.props ({propsVersion}) does not " +
80+
$"equal the latest version in the changelog ({LatestReleaseNotes.Version})");
81+
82+
Log.Debug("Using version: {LatestVersion}", propsVersion);
8883
SemVersion = LatestReleaseNotes.SemVersion;
89-
Version = LatestReleaseNotes.Version.ToString();
84+
Version = propsVersion.ToString();
9085

9186
if (GitHubActions != null)
9287
{
@@ -96,13 +91,17 @@ protected override void OnBuildInitialized()
9691

9792
if (ScheduledTargets.Contains(Default))
9893
{
99-
Version = $"{Version}-ci.{buildNumber}";
94+
VersionPostFix = $"-ci.{buildNumber}";
10095
}
10196
else if (ScheduledTargets.Contains(PrePublish))
10297
{
103-
Version = $"{Version}-alpha.{buildNumber}";
98+
VersionPostFix = $"-pre.{buildNumber}";
10499
}
105100
}
101+
else if (ScheduledTargets.Contains(PrePublish))
102+
{
103+
VersionPostFix = $"-pre";
104+
}
106105

107106
Log.Information("Building version: {Version}", Version);
108107
}
@@ -117,130 +116,32 @@ protected override void OnBuildInitialized()
117116
Target Restore => _ => _
118117
.Executes(() =>
119118
{
120-
Projects.ForEach(project =>
121-
{
122-
DotNetRestore(s => s
123-
.SetProjectFile(project));
124-
});
119+
DotNetRestore(s => s.SetProjectFile(Solution.Path));
125120
});
126121

127122
Target Compile => _ => _
128123
.DependsOn(Restore)
129124
.Executes(() =>
130125
{
131-
Projects.ForEach(project =>
132-
{
133-
DotNetBuild(s => s
134-
.SetProjectFile(project)
135-
.SetVersion(Version)
136-
.SetConfiguration(Configuration)
137-
.EnableNoRestore());
138-
});
126+
DotNetBuild(s => s
127+
.SetProjectFile(Solution.Path)
128+
.SetConfiguration(Configuration)
129+
.SetProperty("GeneratePackageOnBuild", "True")
130+
.SetProperty("VersionPostFix", VersionPostFix ?? string.Empty));
139131
});
140132

141133
Target RunUnitTests => _ => _
142134
.DependsOn(Compile)
143135
.Executes(() =>
144136
{
145-
Projects.ForEach(project =>
146-
{
147-
DotNetTest(s => s
148-
.SetProjectFile(project)
149-
.SetConfiguration(Configuration)
150-
.EnableNoRestore()
151-
.EnableNoBuild());
152-
});
137+
// There aren't any yet
153138
});
154139

155140
Target CreatePackages => _ => _
156141
.DependsOn(Compile)
157142
.Executes(() =>
158143
{
159-
Projects.ForEach(project =>
160-
{
161-
DotNetPack(s => s
162-
.SetProject(project)
163-
.SetVersion(Version)
164-
.SetConfiguration(Configuration)
165-
.SetOutputDirectory(ResultDirectory)
166-
.SetIncludeSymbols(true)
167-
.SetSymbolPackageFormat("snupkg")
168-
.EnableNoRestore()
169-
);
170-
});
171-
});
172-
173-
Target CompileSample => _ => _
174-
.DependsOn(Compile)
175-
.Executes(() =>
176-
{
177-
var sample = SourceDirectory / DemoTargetLibName / $"{DemoTargetLibName}.csproj";
178-
DotNetBuild(s => s.SetProjectFile(sample).SetConfiguration(Configuration));
179-
});
180-
181-
Target ElectronizeGenericTargetSample => _ => _
182-
.DependsOn(CompileSample)
183-
.Executes(() =>
184-
{
185-
var sample = SourceDirectory / DemoTargetLibName;
186-
var cli = SourceDirectory / CliTargetLibName / $"{CliTargetLibName}.csproj";
187-
var args = "build /target custom win7-x86;win /dotnet-configuration Debug /electron-arch ia32 /electron-params \"--publish never\"";
188-
189-
var cmd = $"run --project {cli} --framework {Framework} -- {args}";
190-
Log.Debug(cmd);
191-
DotNet(cmd, sample);
192-
});
193-
194-
Target ElectronizeWindowsTargetSample => _ => _
195-
.DependsOn(CompileSample)
196-
.Executes(() =>
197-
{
198-
var sample = SourceDirectory / DemoTargetLibName;
199-
var cli = SourceDirectory / CliTargetLibName / $"{CliTargetLibName}.csproj";
200-
var args = "build /target win /electron-params \"--publish never\"";
201-
202-
var cmd =$"run --project {cli} --framework {Framework} -- {args}";
203-
Log.Debug(cmd);
204-
DotNet(cmd, sample);
205-
});
206-
207-
Target ElectronizeCustomWin7TargetSample => _ => _
208-
.DependsOn(CompileSample)
209-
.Executes(() =>
210-
{
211-
var sample = SourceDirectory / DemoTargetLibName;
212-
var cli = SourceDirectory / CliTargetLibName / $"{CliTargetLibName}.csproj";
213-
var args = "build /target custom win7-x86;win /electron-params \"--publish never\"";
214-
215-
var cmd =$"run --project {cli} --framework {Framework} -- {args}";
216-
Log.Debug(cmd);
217-
DotNet(cmd, sample);
218-
});
219-
220-
Target ElectronizeMacOsTargetSample => _ => _
221-
.DependsOn(CompileSample)
222-
.Executes(() =>
223-
{
224-
var sample = SourceDirectory / DemoTargetLibName;
225-
var cli = SourceDirectory / CliTargetLibName / $"{CliTargetLibName}.csproj";
226-
var args = "build /target osx /electron-params \"--publish never\"";
227-
228-
var cmd =$"run --project {cli} --framework {Framework} -- {args}";
229-
Log.Debug(cmd);
230-
DotNet(cmd, sample);
231-
});
232-
233-
Target ElectronizeLinuxTargetSample => _ => _
234-
.DependsOn(CompileSample)
235-
.Executes(() =>
236-
{
237-
var sample = SourceDirectory / DemoTargetLibName;
238-
var cli = SourceDirectory / CliTargetLibName / $"{CliTargetLibName}.csproj";
239-
var args = "build /target linux /electron-params \"--publish never\"";
240-
241-
var cmd =$"run --project {cli} --framework {Framework} -- {args}";
242-
Log.Debug(cmd);
243-
DotNet(cmd, sample);
144+
// Packages are created on build
244145
});
245146

246147
Target PublishPackages => _ => _
@@ -292,9 +193,9 @@ protected override void OnBuildInitialized()
292193
new InMemoryCredentialStore(credentials));
293194

294195
GitHubTasks.GitHubClient.Repository.Release
295-
.Create("ElectronNET", "Electron.NET", new NewRelease(Version)
196+
.Create("ElectronNET", "Electron.NET", new NewRelease(Version + VersionPostFix)
296197
{
297-
Name = Version,
198+
Name = "ElectronNET.Core " + Version + VersionPostFix,
298199
Body = String.Join(Environment.NewLine, LatestReleaseNotes.Notes),
299200
Prerelease = true,
300201
TargetCommitish = "develop",
@@ -330,7 +231,7 @@ protected override void OnBuildInitialized()
330231
GitHubTasks.GitHubClient.Repository.Release
331232
.Create("ElectronNET", "Electron.NET", new NewRelease(Version)
332233
{
333-
Name = Version,
234+
Name = "ElectronNET.Core " + Version,
334235
Body = String.Join(Environment.NewLine, LatestReleaseNotes.Notes),
335236
Prerelease = false,
336237
TargetCommitish = "main",

nuke/CommonPropsParser.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using System.Linq;
3+
using System.Xml.Linq;
4+
5+
/// <summary>
6+
/// Parses a version from an MSBuild .props file (XML).
7+
/// </summary>
8+
public sealed class CommonPropsParser
9+
{
10+
/// <summary>
11+
/// Initializes a new instance of the <see cref="ReleaseNotesParser"/> class.
12+
/// </summary>
13+
public CommonPropsParser()
14+
{
15+
}
16+
17+
public Version Parse(string propsPath)
18+
{
19+
var doc = XDocument.Load(propsPath);
20+
21+
var versionElement = doc
22+
.Descendants()
23+
.FirstOrDefault(e => e.Name.LocalName == "Version");
24+
25+
if (Version.TryParse(versionElement?.Value.Trim(), out var version))
26+
{
27+
version = new Version(version.Major, version.Minor, version.Build);
28+
return version;
29+
}
30+
31+
return null;
32+
}
33+
}

0 commit comments

Comments
 (0)