mirror of
https://github.com/FalloutCollaborationProject/FCP-Mod-Updater.git
synced 2026-07-27 17:04:05 -07:00
Add Release Version Embedding
This commit is contained in:
@@ -0,0 +1,36 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace FCPModUpdater;
|
||||||
|
|
||||||
|
public static class AppVersion
|
||||||
|
{
|
||||||
|
private static readonly Lazy<string> InformationalVersionLazy = new(() =>
|
||||||
|
{
|
||||||
|
var attr = typeof(AppVersion).Assembly
|
||||||
|
.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
|
||||||
|
return attr?.InformationalVersion ?? "0.0.0-unknown";
|
||||||
|
});
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Full version string, e.g. "0.1.1" or "0.1.1-dev.4+g2d7e0c6".
|
||||||
|
/// </summary>
|
||||||
|
public static string InformationalVersion => InformationalVersionLazy.Value;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Semantic version without +metadata suffix, for comparison.
|
||||||
|
/// </summary>
|
||||||
|
public static string SemanticVersion
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
var ver = InformationalVersion;
|
||||||
|
var plusIndex = ver.IndexOf('+');
|
||||||
|
return plusIndex >= 0 ? ver[..plusIndex] : ver;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// True if this is a dev/pre-release build.
|
||||||
|
/// </summary>
|
||||||
|
public static bool IsDevBuild => SemanticVersion.Contains('-');
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
|
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
|
||||||
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
|
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
|
||||||
|
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -21,4 +22,41 @@
|
|||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<!-- Derive version from git tags at build time -->
|
||||||
|
<Target Name="SetVersionFromGit" BeforeTargets="GetAssemblyVersion;GetAssemblyAttributes;GenerateNuGetPackage">
|
||||||
|
<Exec Command="git describe --tags --long --always"
|
||||||
|
ConsoleToMSBuild="true"
|
||||||
|
StandardOutputImportance="low"
|
||||||
|
IgnoreExitCode="true">
|
||||||
|
<Output TaskParameter="ConsoleOutput" PropertyName="GitDescribe" />
|
||||||
|
<Output TaskParameter="ExitCode" PropertyName="GitDescribeExitCode" />
|
||||||
|
</Exec>
|
||||||
|
|
||||||
|
<!-- Parse "v0.1.1-4-g2d7e0c6" into components -->
|
||||||
|
<PropertyGroup Condition="'$(GitDescribeExitCode)' == '0' and '$(GitDescribe)' != ''">
|
||||||
|
<GitDescribeClean>$([System.Text.RegularExpressions.Regex]::Replace('$(GitDescribe)', '^v', ''))</GitDescribeClean>
|
||||||
|
<VersionPrefix>$([System.Text.RegularExpressions.Regex]::Match('$(GitDescribeClean)', '^\d+\.\d+\.\d+').Value)</VersionPrefix>
|
||||||
|
<GitCommitsSinceTag>$([System.Text.RegularExpressions.Regex]::Match('$(GitDescribeClean)', '(?<=\d-)\d+(?=-)').Value)</GitCommitsSinceTag>
|
||||||
|
<GitShortHash>$([System.Text.RegularExpressions.Regex]::Match('$(GitDescribeClean)', 'g[0-9a-f]+$').Value)</GitShortHash>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<!-- On a tag exactly (0 commits since tag) -->
|
||||||
|
<PropertyGroup Condition="'$(VersionPrefix)' != '' and '$(GitCommitsSinceTag)' == '0'">
|
||||||
|
<Version>$(VersionPrefix)</Version>
|
||||||
|
<InformationalVersion>$(VersionPrefix)</InformationalVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<!-- Commits ahead of tag = dev build -->
|
||||||
|
<PropertyGroup Condition="'$(VersionPrefix)' != '' and '$(GitCommitsSinceTag)' != '' and '$(GitCommitsSinceTag)' != '0'">
|
||||||
|
<Version>$(VersionPrefix)</Version>
|
||||||
|
<InformationalVersion>$(VersionPrefix)-dev.$(GitCommitsSinceTag)+$(GitShortHash)</InformationalVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<!-- Fallback if git describe failed or no tags -->
|
||||||
|
<PropertyGroup Condition="'$(VersionPrefix)' == ''">
|
||||||
|
<Version>0.0.0</Version>
|
||||||
|
<InformationalVersion>0.0.0-unknown</InformationalVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Target>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -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
|
||||||
|
);
|
||||||
+2
-1
@@ -1,4 +1,5 @@
|
|||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using FCPModUpdater;
|
||||||
using FCPModUpdater.Commands;
|
using FCPModUpdater.Commands;
|
||||||
using Spectre.Console;
|
using Spectre.Console;
|
||||||
using Spectre.Console.Cli;
|
using Spectre.Console.Cli;
|
||||||
@@ -8,7 +9,7 @@ var app = new CommandApp();
|
|||||||
app.Configure(config =>
|
app.Configure(config =>
|
||||||
{
|
{
|
||||||
config.SetApplicationName("fcp-mod-manager");
|
config.SetApplicationName("fcp-mod-manager");
|
||||||
config.SetApplicationVersion("1.0.0");
|
config.SetApplicationVersion(AppVersion.InformationalVersion);
|
||||||
config.SetInterceptor(new GitRequiredInterceptor());
|
config.SetInterceptor(new GitRequiredInterceptor());
|
||||||
|
|
||||||
config.AddCommand<ScanCommand>("scan")
|
config.AddCommand<ScanCommand>("scan")
|
||||||
|
|||||||
+1
-2
@@ -29,7 +29,6 @@
|
|||||||
"Spectre.Console": "0.53.1"
|
"Spectre.Console": "0.53.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
"net10.0/linux-x64": {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user