Skip to content

Commit f301746

Browse files
committed
Update publish logic
1 parent 571febb commit f301746

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

build-support/nuke-build/Build.Publish.cs

+1-5
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,8 @@ public partial class Build
1313
[Parameter] string NuGetSource => "https://api.nuget.org/v3/index.json";
1414
[Parameter] [Secret] string NuGetApiKey;
1515

16-
string TagVersion => GitRepository.Tags.SingleOrDefault(x => x.StartsWith("v"))?[1..];
17-
18-
bool IsTaggedBuild => !string.IsNullOrWhiteSpace(TagVersion);
19-
2016
Target Publish => _ => _
21-
.OnlyWhenDynamic(() => GitRepository.IsOnMainBranch() && IsTaggedBuild)
17+
.OnlyWhenDynamic(() => IsRunningOnWindows && IsTaggedBuild)
2218
.DependsOn(Pack)
2319
.Requires(() => NuGetApiKey)
2420
.Executes(() =>

build-support/nuke-build/Build.cs

+28-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Linq;
5+
using System.Runtime.InteropServices;
56
using Nuke.Common;
67
using Nuke.Common.CI;
78
using Nuke.Common.CI.AppVeyor;
@@ -12,7 +13,7 @@
1213
using Nuke.Common.Tools.DotNet;
1314
using Nuke.Common.Tools.MSBuild;
1415
using Nuke.Common.Utilities.Collections;
15-
16+
using Serilog;
1617
using static Nuke.Common.IO.FileSystemTasks;
1718
using static Nuke.Common.Tooling.ProcessTasks;
1819
using static Nuke.Common.Tools.DotNet.DotNetTasks;
@@ -50,6 +51,31 @@ partial class Build : NukeBuild
5051
AbsolutePath ExamplesDirectory => RootDirectory / "examples";
5152
AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts";
5253

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+
5379
Target Clean => _ => _
5480
.Before(Restore)
5581
.Executes(() =>
@@ -129,19 +155,17 @@ partial class Build : NukeBuild
129155
.Where(x => !x.Name.EndsWith(".Tests"));
130156

131157
var version = TagVersion;
132-
var suffix = "";
133158
if (string.IsNullOrWhiteSpace(version))
134159
{
135160
version = ProjectVersion;
136-
suffix = "develop-" + DateTime.UtcNow.ToString("yyyyMMddHHmm");
137161
}
138162

139163
foreach (var project in packTargets)
140164
{
141165
DotNetPack(s => s
142166
.SetProject(project.Path)
143167
.SetVersion(version)
144-
.SetVersionSuffix(suffix)
168+
.SetVersionSuffix(VersionSuffix)
145169
.SetConfiguration(Configuration.Release)
146170
.EnableNoRestore()
147171
.SetOutputDirectory(ArtifactsDirectory)

0 commit comments

Comments
 (0)