Skip to content

Commit 5582829

Browse files
author
András Kurai
committed
build docfx with nuke
1 parent 6ea2c2f commit 5582829

File tree

9 files changed

+336
-16
lines changed

9 files changed

+336
-16
lines changed

.nuke/build.schema.json

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"title": "Build Schema",
4+
"$ref": "#/definitions/build",
5+
"definitions": {
6+
"build": {
7+
"type": "object",
8+
"properties": {
9+
"Configuration": {
10+
"type": "string",
11+
"description": "Configuration to build - Default is 'Debug' (local) or 'Release' (server)",
12+
"enum": [
13+
"Debug",
14+
"Release"
15+
]
16+
},
17+
"Continue": {
18+
"type": "boolean",
19+
"description": "Indicates to continue a previously failed build attempt"
20+
},
21+
"Help": {
22+
"type": "boolean",
23+
"description": "Shows the help text for this build assembly"
24+
},
25+
"Host": {
26+
"type": "string",
27+
"description": "Host for execution. Default is 'automatic'",
28+
"enum": [
29+
"AppVeyor",
30+
"AzurePipelines",
31+
"Bamboo",
32+
"Bitrise",
33+
"GitHubActions",
34+
"GitLab",
35+
"Jenkins",
36+
"Rider",
37+
"SpaceAutomation",
38+
"TeamCity",
39+
"Terminal",
40+
"TravisCI",
41+
"VisualStudio",
42+
"VSCode"
43+
]
44+
},
45+
"IsCi": {
46+
"type": "boolean",
47+
"description": "Are we running in CI"
48+
},
49+
"NoLogo": {
50+
"type": "boolean",
51+
"description": "Disables displaying the NUKE logo"
52+
},
53+
"Partition": {
54+
"type": "string",
55+
"description": "Partition to use on CI"
56+
},
57+
"Plan": {
58+
"type": "boolean",
59+
"description": "Shows the execution plan (HTML)"
60+
},
61+
"Profile": {
62+
"type": "array",
63+
"description": "Defines the profiles to load",
64+
"items": {
65+
"type": "string"
66+
}
67+
},
68+
"Root": {
69+
"type": "string",
70+
"description": "Root directory during build execution"
71+
},
72+
"Skip": {
73+
"type": "array",
74+
"description": "List of targets to be skipped. Empty list skips all dependencies",
75+
"items": {
76+
"type": "string",
77+
"enum": [
78+
"BuildDocs",
79+
"Compile",
80+
"CreateMetadata",
81+
"GenerateUnitySolution",
82+
"Restore",
83+
"ReturnLicense",
84+
"ServeDocs"
85+
]
86+
}
87+
},
88+
"Solution": {
89+
"type": "string",
90+
"description": "Path to a solution file that is automatically loaded"
91+
},
92+
"Target": {
93+
"type": "array",
94+
"description": "List of targets to be invoked. Default is '{default_target}'",
95+
"items": {
96+
"type": "string",
97+
"enum": [
98+
"BuildDocs",
99+
"Compile",
100+
"CreateMetadata",
101+
"GenerateUnitySolution",
102+
"Restore",
103+
"ReturnLicense",
104+
"ServeDocs"
105+
]
106+
}
107+
},
108+
"UnityEmail": {
109+
"type": "string",
110+
"description": "Email for Unity license"
111+
},
112+
"UnityPassword": {
113+
"type": "string",
114+
"description": "Password for Unity license"
115+
},
116+
"UnitySerial": {
117+
"type": "string",
118+
"description": "Serial for Unity license"
119+
},
120+
"Verbosity": {
121+
"type": "string",
122+
"description": "Logging verbosity during build execution. Default is 'Normal'",
123+
"enum": [
124+
"Minimal",
125+
"Normal",
126+
"Quiet",
127+
"Verbose"
128+
]
129+
}
130+
}
131+
}
132+
}
133+
}

.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": "UnityResourceGenerator/UnityResourceGenerator.sln"
3+
"Solution": "UnityResourceGenerator.sln"
44
}

UnityResourceGenerator.Build/.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ csharp_style_expression_bodied_accessors = true:warning
1414

1515
# CA1050: Declare types in namespaces
1616
dotnet_diagnostic.CA1050.severity = none
17+
18+
# IDE0044: Add readonly modifier
19+
dotnet_diagnostic.IDE0044.severity = none
Lines changed: 89 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,119 @@
11
using Nuke.Common;
2-
using Nuke.Common.Execution;
2+
using Nuke.Common.IO;
33
using Nuke.Common.ProjectModel;
4+
using Nuke.Common.Tooling;
45
using Nuke.Common.Tools.MSBuild;
56
using System;
7+
using System.IO;
8+
using System.Text.RegularExpressions;
9+
using System.Threading.Tasks;
10+
using static Nuke.Common.Tools.DocFX.DocFXTasks;
611
using static Nuke.Common.Tools.MSBuild.MSBuildTasks;
12+
using static Nuke.Common.Tools.Unity.UnityTasks;
13+
using static UnityHelper;
714

8-
[CheckBuildProjectConfigurations]
915
class Build : NukeBuild
1016
{
17+
const string DocFxJsonPath = "Documentation/docfx.json";
18+
1119
public static int Main() => Execute<Build>(x => x.Compile);
1220

1321
[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
1422
readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;
1523

1624
[Solution] readonly Solution Solution = default!;
1725

18-
Target Clean => _ => _
19-
.Before(Restore)
20-
.Executes(() =>
21-
{
22-
});
26+
[Parameter("Password for Unity license")] string? UnityPassword;
27+
[Parameter("Email for Unity license")] string? UnityEmail;
28+
[Parameter("Serial for Unity license")] string? UnitySerial;
29+
30+
[Parameter("Are we running in CI")] bool IsCi = false;
31+
32+
AbsolutePath UnityProjectPath => Solution.Directory / "UnityResourceGenerator";
33+
AbsolutePath UnitySolution => UnityProjectPath / "UnityResourceGenerator.sln";
34+
35+
string UnityVersion =>
36+
Regex.Match
37+
(
38+
File.ReadAllLines(Path.Combine(UnityProjectPath, "ProjectSettings", "ProjectVersion.txt"))[0],
39+
@"(\d+.\d+.\d+.*)"
40+
)
41+
.Value;
2342

2443
Target Restore => _ => _
2544
.Executes(() =>
2645
MSBuild(s => s
27-
.SetTargetPath(Solution)
46+
.SetTargetPath(UnitySolution)
2847
.SetTargets("Restore")));
2948

3049
Target Compile => _ => _
3150
.DependsOn(Restore)
51+
.DependsOn(GenerateUnitySolution)
3252
.Executes(() =>
3353
MSBuild(s => s
34-
.SetTargetPath(Solution)
54+
.SetTargetPath(UnitySolution)
3555
.SetTargets("Rebuild")
3656
.SetConfiguration(Configuration)
3757
.SetMaxCpuCount(Environment.ProcessorCount)
3858
.SetNodeReuse(IsLocalBuild)));
59+
60+
Target GenerateUnitySolution => _ => _
61+
.OnlyWhenDynamic(() => IsCi)
62+
.Triggers(ReturnLicense)
63+
.Executes(async () =>
64+
{
65+
async Task GenerateSolution()
66+
{
67+
await StopUnity();
68+
69+
Unity(s => s
70+
.ConfigureCustom
71+
(
72+
UnityProjectPath,
73+
UnityVersion,
74+
UnityPassword,
75+
UnityEmail,
76+
UnitySerial,
77+
IsCi,
78+
"AutSoft.UnityResourceGenerator.Sample.BuildHelper.RegenerateProjectFiles"
79+
));
80+
}
81+
82+
await GenerateSolution();
83+
84+
// Changing editor preferences are only applied after restart
85+
if (IsCi) await GenerateSolution();
86+
});
87+
88+
Target ReturnLicense => _ => _
89+
.OnlyWhenDynamic(() => IsCi)
90+
.AssuredAfterFailure()
91+
.Executes(async () =>
92+
{
93+
await StopUnity();
94+
95+
Unity(s => s
96+
.ConfigureCustom
97+
(
98+
UnityProjectPath,
99+
UnityVersion,
100+
UnityPassword,
101+
UnityEmail,
102+
UnitySerial,
103+
IsCi
104+
)
105+
.SetProcessArgumentConfigurator(a => a.Add("-returnlicense")));
106+
});
107+
108+
Target CreateMetadata => _ => _
109+
.DependsOn(Compile)
110+
.Executes(() => DocFX($"metadata {DocFxJsonPath}"));
111+
112+
Target BuildDocs => _ => _
113+
.DependsOn(CreateMetadata)
114+
.Executes(() => DocFX($"build {DocFxJsonPath}"));
115+
116+
Target ServeDocs => _ => _
117+
.DependsOn(BuildDocs)
118+
.Executes(() => DocFX($"{DocFxJsonPath} --serve"));
39119
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
using Nuke.Common;
2+
using Nuke.Common.Tooling;
3+
using Nuke.Common.Tools.Unity;
4+
using Nuke.Common.Utilities.Collections;
5+
using System;
6+
using System.Diagnostics;
7+
using System.Runtime.InteropServices;
8+
using System.Threading.Tasks;
9+
10+
static class UnityHelper
11+
{
12+
public static UnitySettings ConfigureCustom
13+
(
14+
this UnitySettings s,
15+
string projectPath,
16+
string unityVersion,
17+
string? unityPassword,
18+
string? unityEmail,
19+
string? unitySerial,
20+
bool isCi,
21+
string? buildMethod = null
22+
)
23+
{
24+
if (isCi)
25+
{
26+
if (string.IsNullOrWhiteSpace(unityPassword)
27+
|| string.IsNullOrWhiteSpace(unityEmail)
28+
|| string.IsNullOrWhiteSpace(unitySerial))
29+
{
30+
throw new InvalidOperationException("Unity credentials are not set");
31+
}
32+
33+
s = s
34+
.SetPassword(unityPassword)
35+
.SetUsername(unityEmail)
36+
.SetSerial(unitySerial);
37+
}
38+
39+
s = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
40+
? s.SetHubVersion(unityVersion)
41+
: s.SetProcessToolPath("/opt/unity/Editor/Unity");
42+
43+
s = s
44+
.SetProjectPath(projectPath)
45+
.EnableBatchMode()
46+
.EnableNoGraphics()
47+
.EnableQuit();
48+
49+
if (buildMethod is not null) s = s.SetExecuteMethod(buildMethod);
50+
51+
return s;
52+
}
53+
54+
public static async Task StopUnity()
55+
{
56+
var processes = Process.GetProcessesByName("Unity");
57+
58+
if (processes.Length == 0)
59+
{
60+
Logger.Info("No Unity processes found");
61+
}
62+
63+
processes.ForEach(p =>
64+
{
65+
Logger.Info("Killing process {0}", p.ProcessName);
66+
p.Kill();
67+
});
68+
69+
await Task.Delay(TimeSpan.FromSeconds(5));
70+
}
71+
}

UnityResourceGenerator.Build/UnityResourceGenerator.Build.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
@@ -12,6 +12,7 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15+
<PackageDownload Include="docfx.console" Version="[2.58.4]" />
1516
<PackageReference Include="Nuke.Common" Version="5.3.0" />
1617
</ItemGroup>
1718

UnityResourceGenerator.sln

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 16
44
VisualStudioVersion = 16.0.30114.105
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnityResourceGenerator.Build", "UnityResourceGenerator.Build\UnityResourceGenerator.Build.csproj", "{6DA4AC26-F65B-4014-9CDB-44CB82CC3D00}"
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnityResourceGenerator.Build", "UnityResourceGenerator.Build\UnityResourceGenerator.Build.csproj", "{6DA4AC26-F65B-4014-9CDB-44CB82CC3D00}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -14,12 +14,8 @@ Global
1414
Release|x64 = Release|x64
1515
Release|x86 = Release|x86
1616
EndGlobalSection
17-
GlobalSection(SolutionProperties) = preSolution
18-
HideSolutionNode = FALSE
19-
EndGlobalSection
2017
GlobalSection(ProjectConfigurationPlatforms) = postSolution
2118
{6DA4AC26-F65B-4014-9CDB-44CB82CC3D00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22-
{6DA4AC26-F65B-4014-9CDB-44CB82CC3D00}.Debug|Any CPU.Build.0 = Debug|Any CPU
2319
{6DA4AC26-F65B-4014-9CDB-44CB82CC3D00}.Debug|x64.ActiveCfg = Debug|Any CPU
2420
{6DA4AC26-F65B-4014-9CDB-44CB82CC3D00}.Debug|x64.Build.0 = Debug|Any CPU
2521
{6DA4AC26-F65B-4014-9CDB-44CB82CC3D00}.Debug|x86.ActiveCfg = Debug|Any CPU
@@ -31,4 +27,10 @@ Global
3127
{6DA4AC26-F65B-4014-9CDB-44CB82CC3D00}.Release|x86.ActiveCfg = Release|Any CPU
3228
{6DA4AC26-F65B-4014-9CDB-44CB82CC3D00}.Release|x86.Build.0 = Release|Any CPU
3329
EndGlobalSection
30+
GlobalSection(SolutionProperties) = preSolution
31+
HideSolutionNode = FALSE
32+
EndGlobalSection
33+
GlobalSection(ExtensibilityGlobals) = postSolution
34+
SolutionGuid = {BFEAA7F5-6BAC-4B54-83B5-EA5799C74E35}
35+
EndGlobalSection
3436
EndGlobal

0 commit comments

Comments
 (0)