From fedc202aee5350836fd70776827cce588da10328 Mon Sep 17 00:00:00 2001 From: Canon Date: Tue, 10 Feb 2026 18:23:28 +0800 Subject: [PATCH] Add Release Version Embedding --- AppVersion.cs | 36 ++++++++++++++++++++++++++++++++++++ FCPModUpdater.csproj | 40 +++++++++++++++++++++++++++++++++++++++- Models/ReleaseInfo.cs | 12 ++++++++++++ Program.cs | 3 ++- packages.lock.json | 3 +-- 5 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 AppVersion.cs create mode 100644 Models/ReleaseInfo.cs diff --git a/AppVersion.cs b/AppVersion.cs new file mode 100644 index 0000000..5d31006 --- /dev/null +++ b/AppVersion.cs @@ -0,0 +1,36 @@ +using System.Reflection; + +namespace FCPModUpdater; + +public static class AppVersion +{ + private static readonly Lazy InformationalVersionLazy = new(() => + { + var attr = typeof(AppVersion).Assembly + .GetCustomAttribute(); + return attr?.InformationalVersion ?? "0.0.0-unknown"; + }); + + /// + /// Full version string, e.g. "0.1.1" or "0.1.1-dev.4+g2d7e0c6". + /// + public static string InformationalVersion => InformationalVersionLazy.Value; + + /// + /// Semantic version without +metadata suffix, for comparison. + /// + public static string SemanticVersion + { + get + { + var ver = InformationalVersion; + var plusIndex = ver.IndexOf('+'); + return plusIndex >= 0 ? ver[..plusIndex] : ver; + } + } + + /// + /// True if this is a dev/pre-release build. + /// + public static bool IsDevBuild => SemanticVersion.Contains('-'); +} diff --git a/FCPModUpdater.csproj b/FCPModUpdater.csproj index 228cc7b..2b58d34 100644 --- a/FCPModUpdater.csproj +++ b/FCPModUpdater.csproj @@ -7,6 +7,7 @@ enable true true + false @@ -20,5 +21,42 @@ embedded true - + + + + + + + + + + + $([System.Text.RegularExpressions.Regex]::Replace('$(GitDescribe)', '^v', '')) + $([System.Text.RegularExpressions.Regex]::Match('$(GitDescribeClean)', '^\d+\.\d+\.\d+').Value) + $([System.Text.RegularExpressions.Regex]::Match('$(GitDescribeClean)', '(?<=\d-)\d+(?=-)').Value) + $([System.Text.RegularExpressions.Regex]::Match('$(GitDescribeClean)', 'g[0-9a-f]+$').Value) + + + + + $(VersionPrefix) + $(VersionPrefix) + + + + + $(VersionPrefix) + $(VersionPrefix)-dev.$(GitCommitsSinceTag)+$(GitShortHash) + + + + + 0.0.0 + 0.0.0-unknown + + + diff --git a/Models/ReleaseInfo.cs b/Models/ReleaseInfo.cs new file mode 100644 index 0000000..07773ac --- /dev/null +++ b/Models/ReleaseInfo.cs @@ -0,0 +1,12 @@ +using System.Text.Json.Serialization; + +namespace FCPModUpdater.Models; + +public record ReleaseInfo( + [property: JsonPropertyName("tag_name")] string TagName, + [property: JsonPropertyName("name")] string Name, + [property: JsonPropertyName("html_url")] string HtmlUrl, + [property: JsonPropertyName("published_at")] DateTimeOffset PublishedAt, + [property: JsonPropertyName("prerelease")] bool Prerelease, + [property: JsonPropertyName("draft")] bool Draft +); diff --git a/Program.cs b/Program.cs index 7aaf867..3bcefd9 100644 --- a/Program.cs +++ b/Program.cs @@ -1,4 +1,5 @@ using System.Runtime.InteropServices; +using FCPModUpdater; using FCPModUpdater.Commands; using Spectre.Console; using Spectre.Console.Cli; @@ -8,7 +9,7 @@ var app = new CommandApp(); app.Configure(config => { config.SetApplicationName("fcp-mod-manager"); - config.SetApplicationVersion("1.0.0"); + config.SetApplicationVersion(AppVersion.InformationalVersion); config.SetInterceptor(new GitRequiredInterceptor()); config.AddCommand("scan") diff --git a/packages.lock.json b/packages.lock.json index 8ab699c..71754a8 100644 --- a/packages.lock.json +++ b/packages.lock.json @@ -29,7 +29,6 @@ "Spectre.Console": "0.53.1" } } - }, - "net10.0/linux-x64": {} + } } } \ No newline at end of file