feat(build): Native AOT publish, versioning with git hash
- PublishAot=true, InvariantGlobalization=true, AssemblyName=noz - Version 0.1.0 baked into binary via AssemblyInformationalVersion - MSBuild target injects git short hash as SourceRevisionId at build time - macOS: LinkerArg for Homebrew OpenSSL path (required for AOT linking) - noz --version / -v exits cleanly without starting the REPL
This commit is contained in:
parent
1865a7ccc2
commit
74bc28bce4
3 changed files with 60 additions and 2 deletions
|
|
@ -13,6 +13,28 @@
|
||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net10.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
|
<AssemblyName>noz</AssemblyName>
|
||||||
|
<RootNamespace>NozCli</RootNamespace>
|
||||||
|
<PublishAot>true</PublishAot>
|
||||||
|
<InvariantGlobalization>true</InvariantGlobalization>
|
||||||
|
<Version>0.1.0</Version>
|
||||||
|
<AssemblyVersion>0.1.0</AssemblyVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<!-- Bake git short hash into InformationalVersion (e.g. 0.1.0+abc1234) -->
|
||||||
|
<Target Name="SetGitHash" BeforeTargets="GetAssemblyVersion">
|
||||||
|
<Exec Command="git rev-parse --short HEAD" ConsoleToMSBuild="true" IgnoreExitCode="true">
|
||||||
|
<Output TaskParameter="ConsoleOutput" PropertyName="GitShortHash" />
|
||||||
|
</Exec>
|
||||||
|
<PropertyGroup>
|
||||||
|
<SourceRevisionId Condition="'$(GitShortHash)' != ''">$(GitShortHash)</SourceRevisionId>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Target>
|
||||||
|
|
||||||
|
<!-- macOS: tell the linker where Homebrew's OpenSSL lives -->
|
||||||
|
<ItemGroup Condition="$([MSBuild]::IsOSPlatform('OSX'))">
|
||||||
|
<LinkerArg Include="-L/opt/homebrew/opt/openssl/lib" />
|
||||||
|
<LinkerArg Include="-L/opt/homebrew/lib" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,23 @@
|
||||||
|
using NozCli;
|
||||||
using NozCli.Core.Config;
|
using NozCli.Core.Config;
|
||||||
using NozCli.Repl;
|
using NozCli.Repl;
|
||||||
using Spectre.Console;
|
using Spectre.Console;
|
||||||
|
|
||||||
|
// ── noz --version / -v ───────────────────────────────────────────────────────
|
||||||
|
if (args is ["--version"] or ["-v"] or ["version"])
|
||||||
|
{
|
||||||
|
Console.WriteLine($"noz {VersionInfo.Full}");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// ── noz init <url> <token> ────────────────────────────────────────────────────
|
// ── noz init <url> <token> ────────────────────────────────────────────────────
|
||||||
if (args is ["init", var url, var token])
|
if (args is ["init", var url, var token])
|
||||||
{
|
{
|
||||||
if (!url.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
|
var isLocalhost = url.StartsWith("http://localhost", StringComparison.OrdinalIgnoreCase)
|
||||||
|
|| url.StartsWith("http://127.", StringComparison.OrdinalIgnoreCase);
|
||||||
|
if (!isLocalhost && !url.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
AnsiConsole.MarkupLine("[red]Error:[/] Only HTTPS servers are allowed.");
|
AnsiConsole.MarkupLine("[red]Error:[/] Only HTTPS servers are allowed (localhost HTTP is ok for dev).");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
26
NozCli/VersionInfo.cs
Normal file
26
NozCli/VersionInfo.cs
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace NozCli;
|
||||||
|
|
||||||
|
public static class VersionInfo
|
||||||
|
{
|
||||||
|
private static readonly string _informational =
|
||||||
|
typeof(VersionInfo).Assembly
|
||||||
|
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
|
||||||
|
?.InformationalVersion ?? "0.0.0";
|
||||||
|
|
||||||
|
// "0.1.0+abc1234" → "0.1.0"
|
||||||
|
public static string Version =>
|
||||||
|
_informational.Contains('+')
|
||||||
|
? _informational[.._informational.IndexOf('+')]
|
||||||
|
: _informational;
|
||||||
|
|
||||||
|
// "0.1.0+abc1234" → "abc1234", or "" if no hash
|
||||||
|
public static string GitHash =>
|
||||||
|
_informational.Contains('+')
|
||||||
|
? _informational[(_informational.IndexOf('+') + 1)..]
|
||||||
|
: "";
|
||||||
|
|
||||||
|
public static string Full =>
|
||||||
|
GitHash.Length > 0 ? $"{Version} ({GitHash})" : Version;
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue