feat: print build info at startup; version placeholders filled in by CI [CI SKIP]

This commit is contained in:
justme committed 2026-10-09 13:20:30 +08:00
1 parent a9f78f99df
commit 7ff0d0f4e6
14 files changed
+42 -14

No files matched your search

+1 -1
View File
@@ -13,7 +13,7 @@
<UseArtifactsOutput>true</UseArtifactsOutput>
<ArtifactsPath>$(MSBuildThisFileDirectory)artifacts</ArtifactsPath>
<Deterministic>true</Deterministic>
<Version>0.4.0</Version>
<Version>0.0.0-dev</Version>
<NuGetAudit>false</NuGetAudit>
</PropertyGroup>
<ItemGroup>
@@ -143,6 +143,7 @@ public sealed class AgentApp : IDisposable
public async Task RunAsync(CancellationToken ct)
{
_log.Info("moshiro agent starting", MoShiro.Protocol.BuildInfo.Fields);
using CancellationTokenSource linked = CancellationTokenSource.CreateLinkedTokenSource(ct);
// 数据面和控制端口先开始监听,再连接 Backend:hello 里上报的是实际端口
_udp.Bind();
@@ -103,6 +103,7 @@ public sealed class ProbeApp : IDisposable
public async Task RunAsync(CancellationToken ct)
{
_log.Info("moshiro probe starting", MoShiro.Protocol.BuildInfo.Fields);
if (_env.Directory.Agents.Count == 0)
{
_log.Info("no agents known yet, waiting for the panel to send the list");
@@ -0,0 +1,19 @@
namespace MoShiro.Protocol;
/// <summary>构建信息的人能读的形式(启动时打进日志);常量部分由 MoShiro.Protocol.csproj 的 WriteBuildInfo 在构建时生成。</summary>
public static partial class BuildInfo
{
/// <summary>版本、tag、提交、构建时间的字段,没有的(本地构建不设环境变量)写 unknown。</summary>
public static (string Key, object? Value)[] Fields { get; } =
[
("version", Or(Version)),
("tag", Or(Tag)),
("commit", Or(Commit)),
("built_at", Or(BuiltAt)),
];
/// <summary>一行摘要,例如:0.4.1-dev.2-a3338e1 (tag v0.4.1-dev.2-a3338e1, commit a3338e1b2c, built 2026-10-09T03:00:00Z)。</summary>
public static string Summary => $"{Or(Version)} (tag {Or(Tag)}, commit {Or(Commit)}, built {Or(BuiltAt)})";
private static string Or(string value) => string.IsNullOrWhiteSpace(value) ? "unknown" : value;
}
@@ -18,7 +18,7 @@
<ItemGroup>
<BuildInfoLine Include="namespace MoShiro.Protocol%3B" />
<BuildInfoLine Include="/// &lt;summary&gt;这个程序是什么时候、从哪个版本构建出来的(构建时生成)。&lt;/summary&gt;" />
<BuildInfoLine Include="public static class BuildInfo" />
<BuildInfoLine Include="public static partial class BuildInfo" />
<BuildInfoLine Include="{" />
<BuildInfoLine Include=" public const string Version = &quot;$(Version)&quot;%3B" />
<BuildInfoLine Include=" public const string Tag = &quot;$(MOSHIRO_TAG)&quot;%3B" />
+8 -1
View File
@@ -1,3 +1,10 @@
using MoShiro.Backend;
await BackendHost.Build(args).RunAsync();
WebApplication app = BackendHost.Build(args);
// 启动时打一行构建信息:版本、tag、提交、构建时间(和 Agent、Probe 启动时打的是同一组)
if (app.Logger.IsEnabled(LogLevel.Information))
{
app.Logger.LogInformation("moshiro backend starting: version {BuildInfo}", MoShiro.Protocol.BuildInfo.Summary);
}
await app.RunAsync();