Skip to content

Commit

Permalink
Simplified assembly versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
flyingpie committed Apr 28, 2024
1 parent fae3c9c commit 31c697b
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 40 deletions.
8 changes: 4 additions & 4 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@
"PublishRelease",
"PublishWin64FrameworkDependent",
"PublishWin64SelfContained",
"Restore",
"SetVersion"
"ReportInfo",
"Restore"
]
}
},
Expand All @@ -107,8 +107,8 @@
"PublishRelease",
"PublishWin64FrameworkDependent",
"PublishWin64SelfContained",
"Restore",
"SetVersion"
"ReportInfo",
"Restore"
]
}
},
Expand Down
46 changes: 30 additions & 16 deletions src/01-Build/NukeBuild/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.GitHub;
using Nuke.Common.Tools.GitVersion;
using Nuke.Common.Tools.MinVer;
using Nuke.Common.Tools.MSBuild;
using Nuke.Common.Tools.NerdbankGitVersioning;
using Octokit;
Expand Down Expand Up @@ -39,9 +38,6 @@ public sealed class Build : NukeBuild
[GitRepository]
private readonly GitRepository GitRepository;

[MinVer]
private readonly MinVer MinVer;

[Nuke.Common.Parameter("GitHub Token")]
private readonly string GitHubToken;

Expand All @@ -65,19 +61,33 @@ public sealed class Build : NukeBuild
private GitHubActions GitHubActions => GitHubActions.Instance;

/// <summary>
/// Manual versioning for now.
/// Returns the version as defined by VERSION (eg. "2.3.4").
/// </summary>
private string SemVerVersion => File.ReadAllText(VersionFile).Trim();

/// <summary>
/// Returns the version for use in assembly versioning.
/// </summary>
private Target SetVersion => _ => _
private string AssemblyVersion => $"{SemVerVersion}";

/// <summary>
/// Returns the version for use in assembly versioning.
/// </summary>
private string InformationalVersion => $"{SemVerVersion}.{DateTimeOffset.UtcNow:yyyyMMdd}+{GitRepository.Commit}";

private Target ReportInfo => _ => _
.Executes(() =>
{
Environment.SetEnvironmentVariable("MINVERVERSIONOVERRIDE", File.ReadAllText(VersionFile).Trim());
Log.Information("SemVerVersion:{SemVerVersion}", SemVerVersion);
Log.Information("AssemblyVersion:{AssemblyVersion}", AssemblyVersion);
Log.Information("InformationalVersion:{InformationalVersion}", InformationalVersion);
});

/// <summary>
/// Clean output directories.
/// </summary>
private Target Clean => _ => _
.DependsOn(SetVersion)
.DependsOn(ReportInfo)
.Executes(() =>
{
OutputDirectory.CreateOrCleanDirectory();
Expand Down Expand Up @@ -105,6 +115,8 @@ public sealed class Build : NukeBuild
var st = StagingDirectory / "win-x64_framework-dependent";

DotNetPublish(_ => _
.SetAssemblyVersion(AssemblyVersion)
.SetInformationalVersion(InformationalVersion)
.SetConfiguration(Configuration)
.SetFramework("net8.0-windows")
.SetProject(Solution._0_Host.Wtq_Host_Windows)
Expand All @@ -131,6 +143,8 @@ public sealed class Build : NukeBuild
var staging = StagingDirectory / "win-x64_self-contained";

DotNetPublish(_ => _
.SetAssemblyVersion(AssemblyVersion)
.SetInformationalVersion(InformationalVersion)
.SetConfiguration(Configuration)
.SetFramework("net8.0-windows")
.SetProject(Solution._0_Host.Wtq_Host_Windows)
Expand All @@ -156,13 +170,13 @@ public sealed class Build : NukeBuild
var sha256 = Convert.ToHexString(await SHA256.HashDataAsync(File.OpenRead(PathToWin64SelfContainedZip))).ToLowerInvariant();

var manifest = tpl
.Replace("$PACKAGE_VERSION$", MinVer.MinVerVersion, StringComparison.OrdinalIgnoreCase)
.Replace("$GH_RELEASE_VERSION$", $"v{MinVer.MinVerVersion}", StringComparison.OrdinalIgnoreCase)
.Replace("$PACKAGE_VERSION$", SemVerVersion, StringComparison.OrdinalIgnoreCase)
.Replace("$GH_RELEASE_VERSION$", $"v{SemVerVersion}", StringComparison.OrdinalIgnoreCase)
.Replace("$SELF_CONTAINED_SHA256$", sha256, StringComparison.OrdinalIgnoreCase);

await File.WriteAllTextAsync(RootDirectory / "scoop" / "wtq-latest.json", manifest);
await File.WriteAllTextAsync(RootDirectory / "scoop" / "wtq-nightly.json", manifest);
await File.WriteAllTextAsync(RootDirectory / "scoop" / $"wtq-{MinVer.MinVerVersion}.json", manifest);
await File.WriteAllTextAsync(RootDirectory / "scoop" / $"wtq-{SemVerVersion}.json", manifest);
});

/// <summary>
Expand All @@ -172,7 +186,7 @@ public sealed class Build : NukeBuild
.Executes(async () =>
{
var templateRoot = RootDirectory / "winget" / "_template";
var manifestRoot = RootDirectory / "winget" / MinVer.MinVerVersion;
var manifestRoot = RootDirectory / "winget" / SemVerVersion;
var prefix = "flyingpie.windows-terminal-quake";
var sha256 = Convert.ToHexString(await SHA256.HashDataAsync(File.OpenRead(PathToWin64SelfContainedZip))).ToLowerInvariant();

Expand All @@ -192,8 +206,8 @@ public sealed class Build : NukeBuild
var target = manifestRoot / fn;

var manifest = tpl
.Replace("$PACKAGE_VERSION$", MinVer.MinVerVersion, StringComparison.OrdinalIgnoreCase)
.Replace("$GH_RELEASE_VERSION$", $"v{MinVer.MinVerVersion}", StringComparison.OrdinalIgnoreCase)
.Replace("$PACKAGE_VERSION$", SemVerVersion, StringComparison.OrdinalIgnoreCase)
.Replace("$GH_RELEASE_VERSION$", $"v{SemVerVersion}", StringComparison.OrdinalIgnoreCase)
.Replace("$SELF_CONTAINED_SHA256$", sha256, StringComparison.OrdinalIgnoreCase);

await File.WriteAllTextAsync(target, manifest);
Expand All @@ -217,10 +231,10 @@ public sealed class Build : NukeBuild

var (owner, name) = (GitRepository.GetGitHubOwner(), GitRepository.GetGitHubName());

var ghRelease = await GitHubTasks.GitHubClient.GetOrCreateGitHubReleaseAsync(owner, name, MinVer.MinVerVersion);
var ghRelease = await GitHubTasks.GitHubClient.GetOrCreateGitHubReleaseAsync(owner, name, SemVerVersion);

// Update release notes.
var latestChangeLog = await NukeExtensions.GetChangeLogEntryAsync(ChangeLogFile, MinVer);
var latestChangeLog = await NukeExtensions.GetChangeLogEntryAsync(ChangeLogFile, SemVerVersion);

await GitHubTasks
.GitHubClient
Expand Down
4 changes: 0 additions & 4 deletions src/01-Build/NukeBuild/NukeBuild.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,4 @@
<ItemGroup>
<PackageReference Include="Nuke.Common" />
</ItemGroup>

<ItemGroup>
<PackageDownload Include="minver-cli" Version="[5.0.0]" />
</ItemGroup>
</Project>
11 changes: 4 additions & 7 deletions src/01-Build/NukeBuild/NukeExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Nuke.Common.Tools.MinVer;
using Octokit;
using Octokit;
using Serilog;
using System.Diagnostics.CodeAnalysis;
using System.IO;
Expand All @@ -14,7 +13,7 @@ public static partial class NukeExtensions

public static async Task<string> GetChangeLogEntryAsync(
string path,
MinVer ver)
string ver)
{
var inCurr = false;
var headerRegex = ChangeLogVersionHeaderRegex();
Expand All @@ -29,9 +28,7 @@ public static async Task<string> GetChangeLogEntryAsync(
{
// See if this version header matches the one we're publishing.
// If it is, we need to start reading the contents.
if (match.Groups["major"].Value == ver.MinVerMajor &&
match.Groups["minor"].Value == ver.MinVerMinor &&
match.Groups["patch"].Value == ver.MinVerPatch)
if (match.Groups["semver"].Value == ver)
{
inCurr = true;
continue;
Expand Down Expand Up @@ -111,6 +108,6 @@ public static async Task UploadReleaseAssetToGithub(
await client.Repository.Release.UploadAsset(release, assetUpload);
}

[GeneratedRegex(@"^## \[(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)\]")]
[GeneratedRegex(@"^## \[(?<semver>\d+\.?\d+\.?\d+)\]")]
private static partial Regex ChangeLogVersionHeaderRegex();
}
8 changes: 0 additions & 8 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@

<!-- Analyzers (non-test projects only -->
<ItemGroup Condition="!$(MSBuildProjectName.EndsWith('Test'))">
<PackageReference Include="MinVer" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand All @@ -51,11 +50,4 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<!-- Assembly versioning -->
<Target Name="SetAssemblyVersion" AfterTargets="MinVer">
<PropertyGroup>
<AssemblyVersion>$(MinVerMajor).$(MinVerMinor).$(MinVerPatch).0</AssemblyVersion>
</PropertyGroup>
</Target>
</Project>
1 change: 0 additions & 1 deletion src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<PackageVersion Include="Ardalis.GuardClauses" Version="4.5.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageVersion Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.9.28" />
<PackageVersion Include="MinVer" Version="5.0.0" />
<PackageVersion Include="MSTest.TestFramework" Version="3.2.2" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="Nuke.Common" Version="8.0.0" />
Expand Down
1 change: 1 addition & 0 deletions src/Wtq.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "00-Sln", "00-Sln", "{79182C
build.cmd = build.cmd
build.ps1 = build.ps1
build.sh = build.sh
..\CHANGELOG.md = ..\CHANGELOG.md
Directory.Build.props = Directory.Build.props
Directory.Packages.props = Directory.Packages.props
global.json = global.json
Expand Down

0 comments on commit 31c697b

Please sign in to comment.