Merge pull request #1945 from KazWolfe/fixed-versioning

feat: Use new versioning strategy
This commit is contained in:
goat 2024-07-25 01:01:50 +02:00 committed by GitHub
commit bd170ee74a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 71 additions and 66 deletions

View file

@ -62,6 +62,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;
@ -128,11 +129,28 @@ public static class Util
}
/// <summary>
/// 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 <c>git describe</c> 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.
/// </summary>
/// <returns>The SCM version of the assembly.</returns>
public static string GetScmVersion()
{
if (scmVersionInternal != null) return scmVersionInternal;
var asm = typeof(Util).Assembly;
var attrs = asm.GetCustomAttributes<AssemblyMetadataAttribute>();
return scmVersionInternal = attrs.First(a => a.Key == "SCMVersion").Value
?? asm.GetName().Version!.ToString();
}
/// <summary>
/// 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.
/// </summary>
/// <returns>The git hash of the assembly.</returns>
public static string GetGitHash()
public static string? GetGitHash()
{
if (gitHashInternal != null)
return gitHashInternal;
@ -140,15 +158,14 @@ public static class Util
var asm = typeof(Util).Assembly;
var attrs = asm.GetCustomAttributes<AssemblyMetadataAttribute>();
gitHashInternal = attrs.First(a => a.Key == "GitHash").Value;
return gitHashInternal;
return gitHashInternal = attrs.First(a => a.Key == "GitHash").Value;
}
/// <summary>
/// Gets the amount of commits in the current branch, or null if undetermined.
/// </summary>
/// <returns>The amount of commits in the current branch.</returns>
[Obsolete($"Planned for removal in API 11. Use {nameof(GetScmVersion)} for version tracking.")]
public static int? GetGitCommitCount()
{
if (gitCommitCountInternal != null)
@ -170,7 +187,7 @@ public static class Util
/// or null if it cannot be found.
/// </summary>
/// <returns>The git hash of the assembly.</returns>
public static string GetGitHashClientStructs()
public static string? GetGitHashClientStructs()
{
if (gitHashClientStructsInternal != null)
return gitHashClientStructsInternal;