Skip to content

Commit 02dd590

Browse files
committed
The build tool will now get the current version from the build config and automatically update the minor version by default, or the major or patch version if the argument is given; Improved the doxygen log output while building the docs; Smaller improvements
1 parent 36b22fe commit 02dd590

7 files changed

Lines changed: 221 additions & 22 deletions

File tree

.nuke/build.schema.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
},
1313
"DoxygenBin": {
1414
"type": "string",
15-
"description": "The path of the doxygen bin directory (Default: C:\\Program Files\\doxygen\\bin)"
15+
"description": "[Optional] The path of the doxygen bin directory (Default: C:\\Program Files\\doxygen\\bin)"
1616
},
1717
"Help": {
1818
"type": "boolean",
@@ -39,9 +39,13 @@
3939
"VSCode"
4040
]
4141
},
42+
"Major": {
43+
"type": "boolean",
44+
"description": "[Optional] Update the major version (Default: Minor version will be updated)"
45+
},
4246
"NoDocs": {
4347
"type": "boolean",
44-
"description": "Sets that no docs should be created"
48+
"description": "[Optional] Sets that no docs should be created"
4549
},
4650
"NoLogo": {
4751
"type": "boolean",
@@ -51,6 +55,10 @@
5155
"type": "string",
5256
"description": "Partition to use on CI"
5357
},
58+
"Patch": {
59+
"type": "boolean",
60+
"description": "[Optional] Update the patch version (Default: Minor version will be updated)"
61+
},
5462
"Plan": {
5563
"type": "boolean",
5664
"description": "Shows the execution plan (HTML)"
@@ -75,6 +83,7 @@
7583
"Compile",
7684
"Docs",
7785
"Info",
86+
"LoadConfig",
7887
"Pack",
7988
"Restore"
8089
]
@@ -93,6 +102,7 @@
93102
"Compile",
94103
"Docs",
95104
"Info",
105+
"LoadConfig",
96106
"Pack",
97107
"Restore"
98108
]
@@ -110,7 +120,7 @@
110120
},
111121
"Version": {
112122
"type": "string",
113-
"description": "Version of the package"
123+
"description": "[Optional] Provide a new version for the package"
114124
}
115125
}
116126
}

src/build.config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"currentVersion": "3.2.0"
3+
}

src/build/Build.cs

Lines changed: 146 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//--------------------------------------------------//
2+
// Created by basicx-StrgV //
3+
// https://github.com/basicx-StrgV/ //
4+
//--------------------------------------------------//
15
using System.IO;
26
using Serilog;
37
using Nuke.Common;
@@ -7,81 +11,207 @@
711

812
namespace BuildTool
913
{
10-
class Build : NukeBuild
14+
internal class Build : NukeBuild
1115
{
1216
public static int Main() => Execute<Build>(x => x.Pack);
1317

14-
[Parameter("Version of the package")]
15-
public readonly string Version = "0.0.0";
18+
[Parameter("[Optional] Update the major version (Default: Minor version will be updated)")]
19+
public bool Major = false;
1620

17-
[Parameter("The path of the doxygen bin directory (Default: C:\\Program Files\\doxygen\\bin)")]
21+
[Parameter("[Optional] Update the patch version (Default: Minor version will be updated)")]
22+
public bool Patch = false;
23+
24+
[Parameter("[Optional] Provide a new version for the package")]
25+
public readonly string? Version = null;
26+
27+
[Parameter("[Optional] The path of the doxygen bin directory (Default: C:\\Program Files\\doxygen\\bin)")]
1828
public readonly string DoxygenBin = "C:\\Program Files\\doxygen\\bin";
1929

20-
[Parameter("Sets that no docs should be created")]
30+
[Parameter("[Optional] Sets that no docs should be created")]
2131
public readonly bool NoDocs = false;
2232

2333
[Solution]
24-
public readonly Solution Solution;
34+
public readonly Solution? Solution;
2535

2636
// Allways set config to release, because build is intended for creating ready to ship packages
2737
private readonly Configuration _configuration = Configuration.Release;
2838

39+
private string? _workingVersion = null;
40+
2941
private static AbsolutePath _packages => RootDirectory / "nuget" / "packages";
3042
private static AbsolutePath _doxygenWorkingDir => RootDirectory / "doxygen";
3143
private static AbsolutePath _doxyfile => _doxygenWorkingDir / "Doxyfile";
44+
private static AbsolutePath _srcDirectory => RootDirectory / "src";
45+
private static AbsolutePath _configFile => _srcDirectory / "build.config.json";
46+
47+
Target LoadConfig => _ => _
48+
.Unlisted()
49+
.Before(Info, Restore, Compile, Pack)
50+
.Executes(() =>
51+
{
52+
Log.Information("Loading the build config");
53+
54+
// Check if config exist
55+
if (!File.Exists(_configFile))
56+
{
57+
if (Version != null)
58+
{
59+
Log.Warning("Config file not found. The provided version ({version}) will still be used", Version);
60+
_workingVersion = Version;
61+
}
62+
else
63+
{
64+
Log.Warning("Config file not found. The version \"1.0.0\" will be used as a fallback");
65+
_workingVersion = "1.0.0";
66+
}
67+
68+
// Proceed with next target
69+
return;
70+
}
71+
72+
// Try to load data from config
73+
ConfigHandler.BuildConfig? buildConfig = ConfigHandler.LoadConfig(_configFile);
74+
if (buildConfig == null)
75+
{
76+
if (Version != null)
77+
{
78+
Log.Warning("Failed to load the config file. The provided version ({version}) will still be used", Version);
79+
_workingVersion = Version;
80+
}
81+
else
82+
{
83+
Log.Warning("Failed to load the config file. The version \"1.0.0\" will be used as a fallback");
84+
_workingVersion = "1.0.0";
85+
}
86+
87+
// Proceed with next target
88+
return;
89+
}
90+
91+
// Try to parse the configured version
92+
bool parsingResult = System.Version.TryParse(buildConfig.CurrentVersion, out System.Version? version);
93+
if (version == null || !parsingResult)
94+
{
95+
if (Version != null)
96+
{
97+
Log.Warning("The version provided by the config file ({configVersion}) is invalid. The provided version ({version}) will still be used", version, Version);
98+
_workingVersion = Version;
99+
}
100+
else
101+
{
102+
Log.Warning("The version provided by the config file ({configVersion}) is invalid. The version \"1.0.0\" will be used as a fallback", version);
103+
_workingVersion = "1.0.0";
104+
}
105+
106+
// Proceed with next target
107+
return;
108+
}
109+
110+
if (Major && Patch)
111+
{
112+
// Cancel the build process
113+
Assert.Fail("Can't update major and patch at the same time");
114+
}
115+
116+
if (Major || Patch)
117+
{
118+
if (Major)
119+
{
120+
_workingVersion =
121+
new System.Version(version.Major + 1, 0, 0)
122+
.ToString();
123+
}
124+
else
125+
{
126+
_workingVersion =
127+
new System.Version(version.Major, version.Minor, version.Build + 1)
128+
.ToString();
129+
}
130+
131+
return;
132+
}
133+
134+
_workingVersion =
135+
new System.Version(version.Major, version.Minor + 1, version.Build)
136+
.ToString();
137+
});
32138

33139
Target Info => _ => _
34140
.Unlisted()
35141
.Before(Restore, Compile, Pack)
36142
.Executes(() =>
37143
{
38144
Log.Information("Creating \"WGet.NET\" nuget package");
39-
Log.Information("Version: {version}", Version);
145+
Log.Information("Version: {version}", _workingVersion);
40146
Log.Information("Output directory: {dir}", _packages);
41147
});
42148

43149
Target Restore => _ => _
44150
.Unlisted()
45151
.Executes(() =>
46152
{
153+
if (Solution == null)
154+
{
155+
Assert.Fail("The solution was not loaded correctly");
156+
return; // Normaly not needed but the compiler does not know that.
157+
}
158+
47159
DotNetTasks.DotNetRestore(s => s
48160
.SetProjectFile(Solution.GetProject("WGet.NET")));
49161
});
50162

51163
Target Compile => _ => _
52-
.DependsOn(Restore)
164+
.DependsOn(LoadConfig, Restore)
53165
.Executes(() =>
54166
{
167+
if (Solution == null)
168+
{
169+
Assert.Fail("The solution was not loaded correctly");
170+
return; // Normaly not needed but the compiler does not know that.
171+
}
172+
55173
DotNetTasks.DotNetBuild(s => s
56174
.SetProjectFile(Solution.GetProject("WGet.NET"))
57175
.SetConfiguration(_configuration)
58176
.EnableNoRestore()
59-
.SetVersion(Version)
60-
.SetFileVersion(Version)
61-
.SetAssemblyVersion(Version));
177+
.SetVersion(_workingVersion)
178+
.SetFileVersion(_workingVersion)
179+
.SetAssemblyVersion(_workingVersion));
62180
});
63181

64182
Target Pack => _ => _
65183
.DependsOn(Info, Compile)
66184
.Triggers(Docs)
67185
.Executes(() =>
68186
{
187+
if (Solution == null)
188+
{
189+
Assert.Fail("The solution was not loaded correctly");
190+
return; // Normaly not needed but the compiler does not know that.
191+
}
192+
69193
DotNetTasks.DotNetPack(s => s
70194
.SetProject(Solution.GetProject("WGet.NET"))
71195
.SetConfiguration(_configuration)
72196
.SetNoBuild(true)
73197
.SetOutputDirectory(_packages)
74-
.SetVersion(Version)
75-
.SetFileVersion(Version)
76-
.SetAssemblyVersion(Version)
77-
.SetProperty("PackageReleaseNotes", $"https://github.com/basicx-StrgV/WGet.NET/releases/tag/{Version}"));
198+
.SetVersion(_workingVersion)
199+
.SetFileVersion(_workingVersion)
200+
.SetAssemblyVersion(_workingVersion)
201+
.SetProperty("PackageReleaseNotes", $"https://github.com/basicx-StrgV/WGet.NET/releases/tag/{_workingVersion}"));
78202
});
79203

80204
Target Docs => _ => _
81205
.Unlisted()
82206
.OnlyWhenDynamic(() => !NoDocs)
83207
.Executes(() =>
84208
{
209+
if (_workingVersion == null)
210+
{
211+
Assert.Fail($"No version for the package is defined");
212+
return; // Normaly not needed but the compiler does not know that.
213+
}
214+
85215
if (!Directory.Exists(DoxygenBin))
86216
{
87217
Assert.Fail($"The doxygen bin directory does not exist ({DoxygenBin})");
@@ -106,7 +236,7 @@ class Build : NukeBuild
106236

107237
DoxygenHandler doxygen = new(_doxyfile, doxygenExe, _doxygenWorkingDir);
108238

109-
bool result = doxygen.GenerateDocs(Version);
239+
bool result = doxygen.GenerateDocs(_workingVersion);
110240

111241
if (!result)
112242
{

src/build/ConfigHandler.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//--------------------------------------------------//
2+
// Created by basicx-StrgV //
3+
// https://github.com/basicx-StrgV/ //
4+
//--------------------------------------------------//
5+
using System.IO;
6+
using System.Text.Json;
7+
using System.Text.Json.Serialization;
8+
9+
namespace BuildTool
10+
{
11+
internal static class ConfigHandler
12+
{
13+
public class BuildConfig
14+
{
15+
[JsonPropertyName("currentVersion")]
16+
public string? CurrentVersion { get; set; }
17+
}
18+
19+
public static BuildConfig? LoadConfig(string configFile)
20+
{
21+
try
22+
{
23+
string configContent = File.ReadAllText(configFile);
24+
25+
return JsonSerializer.Deserialize<BuildConfig>(configContent);
26+
}
27+
catch
28+
{
29+
return null;
30+
}
31+
}
32+
}
33+
}

src/build/DoxygenHandler.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
using Serilog;
1+
//--------------------------------------------------//
2+
// Created by basicx-StrgV //
3+
// https://github.com/basicx-StrgV/ //
4+
//--------------------------------------------------//
5+
using Serilog;
26
using System;
37
using System.IO;
48
using System.Diagnostics;
59

610
namespace BuildTool
711
{
8-
public class DoxygenHandler
12+
internal class DoxygenHandler
913
{
1014
private readonly string _doxyfile;
1115
private readonly string _doxygen;
@@ -91,7 +95,17 @@ private int ExecuteDoxygen()
9195
using (StreamReader output = doxygenProc.StandardOutput)
9296
{
9397
// Log the doxygen output
94-
Log.Information(output.ReadLine());
98+
while (!output.EndOfStream)
99+
{
100+
string? line = output.ReadLine();
101+
102+
if (line == null)
103+
{
104+
continue;
105+
}
106+
107+
Log.Information(line);
108+
}
95109
}
96110

97111
// Wait for process exit with a timeout of 10 min
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"profiles": {
3+
"_build": {
4+
"commandName": "Project",
5+
"commandLineArgs": "--no-docs"
6+
}
7+
}
8+
}

src/build/_build.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<NukeScriptDirectory>..</NukeScriptDirectory>
1010
<NukeTelemetryVersion>1</NukeTelemetryVersion>
1111
<IsPackable>false</IsPackable>
12+
<Nullable>enable</Nullable>
1213
</PropertyGroup>
1314

1415
<ItemGroup>

0 commit comments

Comments
 (0)