|
1 | 1 | using Nuke.Common; |
2 | | -using Nuke.Common.Execution; |
| 2 | +using Nuke.Common.IO; |
3 | 3 | using Nuke.Common.ProjectModel; |
| 4 | +using Nuke.Common.Tooling; |
4 | 5 | using Nuke.Common.Tools.MSBuild; |
5 | 6 | using System; |
| 7 | +using System.IO; |
| 8 | +using System.Text.RegularExpressions; |
| 9 | +using System.Threading.Tasks; |
| 10 | +using static Nuke.Common.Tools.DocFX.DocFXTasks; |
6 | 11 | using static Nuke.Common.Tools.MSBuild.MSBuildTasks; |
| 12 | +using static Nuke.Common.Tools.Unity.UnityTasks; |
| 13 | +using static UnityHelper; |
7 | 14 |
|
8 | | -[CheckBuildProjectConfigurations] |
9 | 15 | class Build : NukeBuild |
10 | 16 | { |
| 17 | + const string DocFxJsonPath = "Documentation/docfx.json"; |
| 18 | + |
11 | 19 | public static int Main() => Execute<Build>(x => x.Compile); |
12 | 20 |
|
13 | 21 | [Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")] |
14 | 22 | readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release; |
15 | 23 |
|
16 | 24 | [Solution] readonly Solution Solution = default!; |
17 | 25 |
|
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; |
23 | 42 |
|
24 | 43 | Target Restore => _ => _ |
25 | 44 | .Executes(() => |
26 | 45 | MSBuild(s => s |
27 | | - .SetTargetPath(Solution) |
| 46 | + .SetTargetPath(UnitySolution) |
28 | 47 | .SetTargets("Restore"))); |
29 | 48 |
|
30 | 49 | Target Compile => _ => _ |
31 | 50 | .DependsOn(Restore) |
| 51 | + .DependsOn(GenerateUnitySolution) |
32 | 52 | .Executes(() => |
33 | 53 | MSBuild(s => s |
34 | | - .SetTargetPath(Solution) |
| 54 | + .SetTargetPath(UnitySolution) |
35 | 55 | .SetTargets("Rebuild") |
36 | 56 | .SetConfiguration(Configuration) |
37 | 57 | .SetMaxCpuCount(Environment.ProcessorCount) |
38 | 58 | .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")); |
39 | 119 | } |
0 commit comments