|
| 1 | +using System.Text.Json.Serialization; |
| 2 | +using PCL.Core.Utils.OS; |
| 3 | + |
| 4 | +namespace PCL.Core.App; |
| 5 | + |
| 6 | +/// <summary> |
| 7 | +/// 启动器版本信息模型 |
| 8 | +/// </summary> |
| 9 | +/// <param name="BaseVersion">基本版本号, 如 <c>2.14.1</c></param> |
| 10 | +/// <param name="Suffix">后缀, 如 <c>beta.1</c></param> |
| 11 | +/// <param name="Code">内部版本代号, 如 <c>712</c></param> |
| 12 | +/// <param name="UpstreamVersion">上游版本, 如 <c>2.12.0</c></param> |
| 13 | +public sealed record LauncherVersionModel( |
| 14 | + [property: JsonPropertyName("base")] string BaseVersion, |
| 15 | + [property: JsonPropertyName("suffix")] string Suffix, |
| 16 | + [property: JsonPropertyName("code")] int Code, |
| 17 | + [property: JsonPropertyName("upstream")] string UpstreamVersion |
| 18 | +) { |
| 19 | + private static readonly (string Name, int Code) _CompilationBranchInfo = |
| 20 | +#if DEBUG |
| 21 | + ("Debug", 100); |
| 22 | +#elif CI |
| 23 | + ("CI", 50); |
| 24 | +#else |
| 25 | + ("Publish", 0); |
| 26 | +#endif |
| 27 | + |
| 28 | + private static readonly string? _SecretCommitInfo = EnvironmentInterop.GetSecret("GITHUB_SHA", false); |
| 29 | + |
| 30 | + /// <summary> |
| 31 | + /// 基本版本名, 若 <see cref="Suffix"/> 存在实际值会附加后缀, 否则与 <see cref="BaseVersion"/> 相同 |
| 32 | + /// </summary> |
| 33 | + public string BaseName { get; } = BaseVersion + (string.IsNullOrWhiteSpace(Suffix) ? "" : "-" + Suffix); |
| 34 | + |
| 35 | + /// <summary> |
| 36 | + /// 发行分支名 |
| 37 | + /// </summary> |
| 38 | + public string BranchName { get; } = _CompilationBranchInfo.Name; |
| 39 | + |
| 40 | + /// <summary> |
| 41 | + /// 发行分支代号 |
| 42 | + /// </summary> |
| 43 | + public int BranchCode { get; } = _CompilationBranchInfo.Code; |
| 44 | + |
| 45 | + /// <summary> |
| 46 | + /// 标准版本号 |
| 47 | + /// </summary> |
| 48 | + public string StandardVersion { get; } = BaseVersion + "." + _CompilationBranchInfo.Code; |
| 49 | + |
| 50 | + /// <summary> |
| 51 | + /// 代码提交版本 hash, 若不存在 (非 CI 构建) 则为 <c>native</c> |
| 52 | + /// </summary> |
| 53 | + public string Commit { get; } = _SecretCommitInfo ?? "native"; |
| 54 | + |
| 55 | + /// <summary> |
| 56 | + /// 代码提交版本 hash 的摘要 (取前 7 位), 若不存在 (非 CI 构建) 则为 <c>native</c> |
| 57 | + /// </summary> |
| 58 | + public string CommitDigest { get; } = _SecretCommitInfo?[..7] ?? "native"; |
| 59 | +} |
| 60 | + |
| 61 | +/// <summary> |
| 62 | +/// 启动器元数据模型 |
| 63 | +/// </summary> |
| 64 | +/// <param name="Name">程序名称</param> |
| 65 | +/// <param name="Version">版本信息</param> |
| 66 | +public sealed record MetadataModel( |
| 67 | + [property: JsonPropertyName("name")] string Name, |
| 68 | + [property: JsonPropertyName("version")] LauncherVersionModel Version |
| 69 | +); |
0 commit comments