From 2b96f2187c915e7c674fce04073e7897a87a5c44 Mon Sep 17 00:00:00 2001 From: Kaz Wolfe Date: Sun, 14 Jul 2024 11:07:36 -0700 Subject: [PATCH] feat: Use new versioning strategy - Rename BuildHash to SCMVersion - Expose the actual commit hash as a new `commit_hash.txt` - Update GetGitHash() to actually return the git hash --- .github/workflows/main.yml | 3 +- Dalamud/Dalamud.csproj | 76 ++++++++----------- Dalamud/EntryPoint.cs | 2 +- Dalamud/Interface/Internal/DalamudCommands.cs | 2 +- .../Interface/Internal/DalamudInterface.cs | 4 +- .../PluginInstaller/PluginInstallerWindow.cs | 4 +- Dalamud/Support/BugBait.cs | 2 +- Dalamud/Support/Troubleshooting.cs | 4 +- Dalamud/Utility/Util.cs | 31 ++++++-- 9 files changed, 67 insertions(+), 61 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d78c87d68..a8d27140d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -137,6 +137,7 @@ jobs: $newVersion = [System.IO.File]::ReadAllText("$(Get-Location)\scratch\TEMP_gitver.txt") $revision = [System.IO.File]::ReadAllText("$(Get-Location)\scratch\revision.txt") + $commitHash = [System.IO.File]::ReadAllText("$(Get-Location)\scratch\commit_hash.txt") Remove-Item -Force -Recurse .\scratch if (Test-Path -Path $branchName) { @@ -147,7 +148,7 @@ jobs: } else { Move-Item -Force ".\canary.zip" ".\${branchName}\latest.zip" $versionData.AssemblyVersion = $newVersion - $versionData | add-member -Force -Name "GitSha" $newVersion -MemberType NoteProperty + $versionData | add-member -Force -Name "GitSha" $commitHash -MemberType NoteProperty $versionData | add-member -Force -Name "Revision" $revision -MemberType NoteProperty $versionData | ConvertTo-Json -Compress | Out-File ".\${branchName}\version" } diff --git a/Dalamud/Dalamud.csproj b/Dalamud/Dalamud.csproj index 2b575f617..a5391631a 100644 --- a/Dalamud/Dalamud.csproj +++ b/Dalamud/Dalamud.csproj @@ -124,57 +124,45 @@ $(OutputPath)TEMP_gitver.txt + $(OutputPath)commit_hash.txt $(OutputPath)revision.txt - + - - - - $([System.Text.RegularExpressions.Regex]::Replace($(DalamudGitCommitCount), @"\t|\n|\r", "")) - - - - - - - - - + + - - + + - - + - $([System.Text.RegularExpressions.Regex]::Replace($(DalamudGitDescribeOutput), @"\t|\n|\r", "")) - $([System.Text.RegularExpressions.Regex]::Replace($(ClientStructsGitDescribeOutput), @"\t|\n|\r", "")) + $([System.Text.RegularExpressions.Regex]::Replace($(DalamudGitCommitCount), @"\t|\n|\r", "")) + $([System.Text.RegularExpressions.Regex]::Replace($(DalamudGitCommitHash), @"\t|\n|\r", "")) + $([System.Text.RegularExpressions.Regex]::Replace($(DalamudGitDescribeOutput), @"\t|\n|\r", "")) + $([System.Text.RegularExpressions.Regex]::Replace($(ClientStructsGitDescribeOutput), @"\t|\n|\r", "")) - - - - - - - - Local build at $([System.DateTime]::Now.ToString(yyyy-MM-dd HH:mm:ss)) - $(LocalBuildText) - ??? - - - - + + + - + + + + Local build at $([System.DateTime]::Now.ToString(yyyy-MM-dd HH:mm:ss)) + ??? + + + + $(IntermediateOutputPath)CustomAssemblyInfo.cs @@ -185,21 +173,21 @@ - - <_Parameter1>GitHash - <_Parameter2>$(BuildHash) + + <_Parameter1>SCMVersion + <_Parameter2>$(SCMVersion) - + <_Parameter1>GitCommitCount <_Parameter2>$(CommitCount) - + <_Parameter1>GitHashClientStructs - <_Parameter2>$(BuildHashClientStructs) + <_Parameter2>$(CommitHashClientStructs) - - <_Parameter1>FullGitHash - <_Parameter2>$(DalamudFullGitCommitHash) + + <_Parameter1>GitHash + <_Parameter2>$(CommitHash) diff --git a/Dalamud/EntryPoint.cs b/Dalamud/EntryPoint.cs index 4b0adc9d8..d2bf69e16 100644 --- a/Dalamud/EntryPoint.cs +++ b/Dalamud/EntryPoint.cs @@ -185,7 +185,7 @@ public sealed class EntryPoint var dalamud = new Dalamud(info, fs, configuration, mainThreadContinueEvent); Log.Information("This is Dalamud - Core: {GitHash}, CS: {CsGitHash} [{CsVersion}]", - Util.GetGitHash(), + Util.GetScmVersion(), Util.GetGitHashClientStructs(), FFXIVClientStructs.ThisAssembly.Git.Commits); diff --git a/Dalamud/Interface/Internal/DalamudCommands.cs b/Dalamud/Interface/Internal/DalamudCommands.cs index cc63d887f..c19e4d120 100644 --- a/Dalamud/Interface/Internal/DalamudCommands.cs +++ b/Dalamud/Interface/Internal/DalamudCommands.cs @@ -329,7 +329,7 @@ internal class DalamudCommands : IServiceType chatGui.Print(new SeStringBuilder() .AddItalics("Dalamud:") - .AddText($" D{Util.AssemblyVersion}({Util.GetGitHash()}") + .AddText($" D{Util.AssemblyVersion}({Util.GetScmVersion()}") .Build()); chatGui.Print(new SeStringBuilder() diff --git a/Dalamud/Interface/Internal/DalamudInterface.cs b/Dalamud/Interface/Internal/DalamudInterface.cs index 71ba2b071..9eac68c9b 100644 --- a/Dalamud/Interface/Internal/DalamudInterface.cs +++ b/Dalamud/Interface/Internal/DalamudInterface.cs @@ -821,7 +821,7 @@ internal class DalamudInterface : IInternalDisposableService ImGui.MenuItem(Util.AssemblyVersion, false); ImGui.MenuItem(this.dalamud.StartInfo.GameVersion?.ToString() ?? "Unknown version", false); - ImGui.MenuItem($"D: {Util.GetGitHash()}[{Util.GetGitCommitCount()}] CS: {Util.GetGitHashClientStructs()}[{FFXIVClientStructs.ThisAssembly.Git.Commits}]", false); + ImGui.MenuItem($"D: {Util.GetScmVersion()} CS: {Util.GetGitHashClientStructs()}[{FFXIVClientStructs.ThisAssembly.Git.Commits}]", false); ImGui.MenuItem($"CLR: {Environment.Version}", false); ImGui.EndMenu(); @@ -1020,7 +1020,7 @@ internal class DalamudInterface : IInternalDisposableService { ImGui.PushFont(InterfaceManager.MonoFont); - ImGui.BeginMenu($"{Util.GetGitHash()}({Util.GetGitCommitCount()})", false); + ImGui.BeginMenu(Util.GetScmVersion(), false); ImGui.BeginMenu(this.FrameCount.ToString("000000"), false); ImGui.BeginMenu(ImGui.GetIO().Framerate.ToString("000"), false); ImGui.BeginMenu($"W:{Util.FormatBytes(GC.GetTotalMemory(false))}", false); diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs index d4700ddb5..cb8a2da87 100644 --- a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs +++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs @@ -304,7 +304,7 @@ internal class PluginInstallerWindow : Window, IDisposable return; var versionInfo = t.Result; - if (versionInfo.AssemblyVersion != Util.GetGitHash() && + if (versionInfo.AssemblyVersion != Util.GetScmVersion() && versionInfo.Track != "release" && string.Equals(versionInfo.Key, config.DalamudBetaKey, StringComparison.OrdinalIgnoreCase)) this.staleDalamudNewVersion = versionInfo.AssemblyVersion; @@ -1540,7 +1540,7 @@ internal class PluginInstallerWindow : Window, IDisposable DrawWarningIcon(); DrawLinesCentered("A new version of Dalamud is available.\n" + "Please restart the game to ensure compatibility with updated plugins.\n" + - $"old: {Util.GetGitHash()} new: {this.staleDalamudNewVersion}"); + $"old: {Util.GetScmVersion()} new: {this.staleDalamudNewVersion}"); ImGuiHelpers.ScaledDummy(10); } diff --git a/Dalamud/Support/BugBait.cs b/Dalamud/Support/BugBait.cs index 22628303e..c82e5e652 100644 --- a/Dalamud/Support/BugBait.cs +++ b/Dalamud/Support/BugBait.cs @@ -36,7 +36,7 @@ internal static class BugBait Reporter = reporter, Name = plugin.InternalName, Version = isTesting ? plugin.TestingAssemblyVersion?.ToString() : plugin.AssemblyVersion.ToString(), - DalamudHash = Util.GetGitHash(), + DalamudHash = Util.GetScmVersion(), }; if (includeException) diff --git a/Dalamud/Support/Troubleshooting.cs b/Dalamud/Support/Troubleshooting.cs index 3ba088c66..4af8d5ffc 100644 --- a/Dalamud/Support/Troubleshooting.cs +++ b/Dalamud/Support/Troubleshooting.cs @@ -69,8 +69,8 @@ public static class Troubleshooting LoadedPlugins = pluginManager?.InstalledPlugins?.Select(x => x.Manifest as LocalPluginManifest)?.OrderByDescending(x => x.InternalName).ToArray(), PluginStates = pluginManager?.InstalledPlugins?.Where(x => !x.IsDev).ToDictionary(x => x.Manifest.InternalName, x => x.IsBanned ? "Banned" : x.State.ToString()), EverStartedLoadingPlugins = pluginManager?.InstalledPlugins.Where(x => x.HasEverStartedLoad).Select(x => x.InternalName).ToList(), - DalamudVersion = Util.AssemblyVersion, - DalamudGitHash = Util.GetGitHash(), + DalamudVersion = Util.GetScmVersion(), + DalamudGitHash = Util.GetGitHash() ?? "Unknown", GameVersion = startInfo.GameVersion?.ToString() ?? "Unknown", Language = startInfo.Language.ToString(), BetaKey = configuration.DalamudBetaKey, diff --git a/Dalamud/Utility/Util.cs b/Dalamud/Utility/Util.cs index 927f7b310..745df597e 100644 --- a/Dalamud/Utility/Util.cs +++ b/Dalamud/Utility/Util.cs @@ -61,6 +61,7 @@ public static class Util ]; private static readonly Type GenericSpanType = typeof(Span<>); + private static string? scmVersionInternal; private static string? gitHashInternal; private static int? gitCommitCountInternal; private static string? gitHashClientStructsInternal; @@ -127,11 +128,28 @@ public static class Util } /// - /// Gets the git hash value from the assembly - /// or null if it cannot be found. + /// Gets the SCM Version from the assembly, or null if it cannot be found. This method will generally return + /// the git describe output for this build, which will be a raw version if this is a stable build or an + /// appropriately-annotated version if this is *not* stable. Local builds will return a `Local Build` text string. + /// + /// The SCM version of the assembly. + public static string GetScmVersion() + { + if (scmVersionInternal != null) return scmVersionInternal; + + var asm = typeof(Util).Assembly; + var attrs = asm.GetCustomAttributes(); + + return scmVersionInternal = attrs.First(a => a.Key == "SCMVersion").Value + ?? asm.GetName().Version!.ToString(); + } + + /// + /// Gets the git commit hash value from the assembly or null if it cannot be found. Will be null for Debug builds, + /// and will be suffixed with `-dirty` if in release with pending changes. /// /// The git hash of the assembly. - public static string GetGitHash() + public static string? GetGitHash() { if (gitHashInternal != null) return gitHashInternal; @@ -139,15 +157,14 @@ public static class Util var asm = typeof(Util).Assembly; var attrs = asm.GetCustomAttributes(); - gitHashInternal = attrs.First(a => a.Key == "GitHash").Value; - - return gitHashInternal; + return gitHashInternal = attrs.First(a => a.Key == "GitHash").Value; } /// /// Gets the amount of commits in the current branch, or null if undetermined. /// /// The amount of commits in the current branch. + [Obsolete($"Planned for removal in API 11. Use {nameof(GetScmVersion)} for version tracking.")] public static int? GetGitCommitCount() { if (gitCommitCountInternal != null) @@ -169,7 +186,7 @@ public static class Util /// or null if it cannot be found. /// /// The git hash of the assembly. - public static string GetGitHashClientStructs() + public static string? GetGitHashClientStructs() { if (gitHashClientStructsInternal != null) return gitHashClientStructsInternal;