Skip to content

Commit 1c22342

Browse files
committed
The build config will now be updated automatically after the build process; Smaller improvements to the build tool
1 parent 0aa9b62 commit 1c22342

3 files changed

Lines changed: 59 additions & 8 deletions

File tree

.nuke/build.schema.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@
8585
"Info",
8686
"LoadConfig",
8787
"Pack",
88-
"Restore"
88+
"Restore",
89+
"UpdateConfig"
8990
]
9091
}
9192
},
@@ -104,7 +105,8 @@
104105
"Info",
105106
"LoadConfig",
106107
"Pack",
107-
"Restore"
108+
"Restore",
109+
"UpdateConfig"
108110
]
109111
}
110112
},

src/build/Build.cs

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ internal class Build : NukeBuild
1515
{
1616
public static int Main() => Execute<Build>(x => x.Pack);
1717

18-
[Parameter("[Optional] Update the major version (Default: Minor version will be updated)")]
18+
[Parameter("Update the major version (Default: Minor version will be updated)")]
1919
public bool Major = false;
2020

21-
[Parameter("[Optional] Update the patch version (Default: Minor version will be updated)")]
21+
[Parameter("Update the patch version (Default: Minor version will be updated)")]
2222
public bool Patch = false;
2323

24-
[Parameter("[Optional] Provide a new version for the package")]
24+
[Parameter("Provide a new version for the package")]
2525
public readonly string? Version = null;
2626

27-
[Parameter("[Optional] The path of the doxygen bin directory (Default: C:\\Program Files\\doxygen\\bin)")]
27+
[Parameter("The path of the doxygen bin directory (Default: C:\\Program Files\\doxygen\\bin)")]
2828
public readonly string DoxygenBin = "C:\\Program Files\\doxygen\\bin";
2929

30-
[Parameter("[Optional] Sets that no docs should be created")]
30+
[Parameter("Sets that no docs should be created (Default: Automaticly updating the version from the build config)")]
3131
public readonly bool NoDocs = false;
3232

3333
[Solution]
@@ -50,6 +50,7 @@ internal class Build : NukeBuild
5050
.Executes(() =>
5151
{
5252
Log.Information("Loading the build config");
53+
Log.Information("File: {configFile}", _configFile);
5354

5455
// Check if config exist
5556
if (!File.Exists(_configFile))
@@ -181,7 +182,7 @@ internal class Build : NukeBuild
181182

182183
Target Pack => _ => _
183184
.DependsOn(Info, Compile)
184-
.Triggers(Docs)
185+
.Triggers(Docs, UpdateConfig)
185186
.Executes(() =>
186187
{
187188
if (Solution == null)
@@ -204,6 +205,7 @@ internal class Build : NukeBuild
204205
Target Docs => _ => _
205206
.Unlisted()
206207
.OnlyWhenDynamic(() => !NoDocs)
208+
.ProceedAfterFailure()
207209
.Executes(() =>
208210
{
209211
if (_workingVersion == null)
@@ -243,5 +245,33 @@ internal class Build : NukeBuild
243245
Assert.Fail("Failed to generate docs");
244246
}
245247
});
248+
249+
Target UpdateConfig => _ => _
250+
.Unlisted()
251+
.After(Pack, Docs)
252+
.TriggeredBy(Pack)
253+
.ProceedAfterFailure()
254+
.Executes(() =>
255+
{
256+
Log.Information("Updating the build config");
257+
Log.Information("File: {configFile}", _configFile);
258+
259+
if (!File.Exists(_configFile))
260+
{
261+
Log.Information("The config file does not exist, it will be created");
262+
}
263+
264+
bool saveResult = ConfigHandler.SaveConfig(
265+
_configFile,
266+
new ConfigHandler.BuildConfig()
267+
{
268+
CurrentVersion = _workingVersion
269+
});
270+
271+
if (!saveResult)
272+
{
273+
Assert.Fail("Failed to update the build config");
274+
}
275+
});
246276
}
247277
}

src/build/ConfigHandler.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,24 @@ public class BuildConfig
2929
return null;
3030
}
3131
}
32+
33+
public static bool SaveConfig(string configFile, BuildConfig config)
34+
{
35+
try
36+
{
37+
string configJson = JsonSerializer.Serialize(config, new JsonSerializerOptions()
38+
{
39+
WriteIndented = true
40+
});
41+
42+
File.WriteAllText(configFile, configJson);
43+
44+
return true;
45+
}
46+
catch
47+
{
48+
return false;
49+
}
50+
}
3251
}
3352
}

0 commit comments

Comments
 (0)