|
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.IO; |
4 | 4 | using System.Linq; |
| 5 | +using System.Runtime.InteropServices; |
5 | 6 | using Nuke.Common; |
6 | 7 | using Nuke.Common.CI; |
7 | 8 | using Nuke.Common.CI.AppVeyor; |
|
12 | 13 | using Nuke.Common.Tools.DotNet; |
13 | 14 | using Nuke.Common.Tools.MSBuild; |
14 | 15 | using Nuke.Common.Utilities.Collections; |
15 | | - |
| 16 | +using Serilog; |
16 | 17 | using static Nuke.Common.IO.FileSystemTasks; |
17 | 18 | using static Nuke.Common.Tooling.ProcessTasks; |
18 | 19 | using static Nuke.Common.Tools.DotNet.DotNetTasks; |
@@ -50,6 +51,31 @@ partial class Build : NukeBuild |
50 | 51 | AbsolutePath ExamplesDirectory => RootDirectory / "examples"; |
51 | 52 | AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts"; |
52 | 53 |
|
| 54 | + string TagVersion => GitRepository.Tags.SingleOrDefault(x => x.StartsWith("v"))?[1..]; |
| 55 | + |
| 56 | + bool IsTaggedBuild => !string.IsNullOrWhiteSpace(TagVersion); |
| 57 | + |
| 58 | + string VersionSuffix; |
| 59 | + |
| 60 | + static bool IsRunningOnWindows => RuntimeInformation.IsOSPlatform(OSPlatform.Windows); |
| 61 | + |
| 62 | + protected override void OnBuildInitialized() |
| 63 | + { |
| 64 | + VersionSuffix = !IsTaggedBuild |
| 65 | + ? $"preview-{DateTime.UtcNow:yyyyMMdd-HHmm}" |
| 66 | + : ""; |
| 67 | + |
| 68 | + if (IsLocalBuild) |
| 69 | + { |
| 70 | + VersionSuffix = $"dev-{DateTime.UtcNow:yyyyMMdd-HHmm}"; |
| 71 | + } |
| 72 | + |
| 73 | + Log.Information("BUILD SETUP"); |
| 74 | + Log.Information("Configuration:\t{Configuration}", Configuration); |
| 75 | + Log.Information("Version suffix:\t{VersionSuffix}", VersionSuffix); |
| 76 | + Log.Information("Tagged build:\t{IsTaggedBuild}", IsTaggedBuild); |
| 77 | + } |
| 78 | + |
53 | 79 | Target Clean => _ => _ |
54 | 80 | .Before(Restore) |
55 | 81 | .Executes(() => |
@@ -129,19 +155,17 @@ partial class Build : NukeBuild |
129 | 155 | .Where(x => !x.Name.EndsWith(".Tests")); |
130 | 156 |
|
131 | 157 | var version = TagVersion; |
132 | | - var suffix = ""; |
133 | 158 | if (string.IsNullOrWhiteSpace(version)) |
134 | 159 | { |
135 | 160 | version = ProjectVersion; |
136 | | - suffix = "develop-" + DateTime.UtcNow.ToString("yyyyMMddHHmm"); |
137 | 161 | } |
138 | 162 |
|
139 | 163 | foreach (var project in packTargets) |
140 | 164 | { |
141 | 165 | DotNetPack(s => s |
142 | 166 | .SetProject(project.Path) |
143 | 167 | .SetVersion(version) |
144 | | - .SetVersionSuffix(suffix) |
| 168 | + .SetVersionSuffix(VersionSuffix) |
145 | 169 | .SetConfiguration(Configuration.Release) |
146 | 170 | .EnableNoRestore() |
147 | 171 | .SetOutputDirectory(ArtifactsDirectory) |
|
0 commit comments