|
1 |
| -using System.Reflection; |
| 1 | +using System; |
| 2 | +using System.IO; |
| 3 | +using System.Collections.Generic; |
2 | 4 |
|
3 | 5 | namespace EventStore.Common.Utils {
|
4 | 6 | public static class VersionInfo {
|
5 |
| - public const string DefaultVersion = "0.0.0.0"; |
6 |
| - public const string UnknownVersion = "unknown_version"; |
| 7 | + public const string DefaultVersion = "0.0.0-prerelease"; |
7 | 8 | public const string OldVersion = "old_version";
|
8 |
| - public static string Version => typeof(VersionInfo).Assembly |
9 |
| - .GetCustomAttribute<AssemblyFileVersionAttribute>()?.Version ?? DefaultVersion; |
| 9 | + public const string UnknownVersion = "unknown_version"; |
| 10 | + |
| 11 | + public static string BuildId { get; private set; } = ""; |
| 12 | + public static string Edition { get; private set; } = ""; |
| 13 | + public static string Version { get; private set; } = DefaultVersion; |
| 14 | + |
| 15 | + public static string CommitSha { get; private set; } = ThisAssembly.Git.Commit; |
| 16 | + public static string Timestamp { get; private set; } = ThisAssembly.Git.CommitDate; |
| 17 | + |
| 18 | + public static string Text => $"EventStoreDB version {Version} {Edition} ({BuildId}/{CommitSha})"; |
| 19 | + |
| 20 | + static VersionInfo() { |
| 21 | + var versionFilePath = Path.Join( |
| 22 | + Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory), |
| 23 | + "version.properties"); |
| 24 | + var properties = LoadProperties(versionFilePath); |
| 25 | + |
| 26 | + if (properties.TryGetValue("version", out var version)) |
| 27 | + Version = version; |
| 28 | + |
| 29 | + if (properties.TryGetValue("commit_sha", out var commitSha)) |
| 30 | + CommitSha = commitSha; |
| 31 | + |
| 32 | + if (properties.TryGetValue("timestamp", out var timestamp)) |
| 33 | + Timestamp = timestamp; |
| 34 | + |
| 35 | + if (properties.TryGetValue("build_id", out var buildId)) |
| 36 | + BuildId = buildId; |
| 37 | + |
| 38 | + if (properties.TryGetValue("edition", out var edition)) |
| 39 | + Edition = edition; |
| 40 | + } |
| 41 | + |
| 42 | + private static Dictionary<string, string> LoadProperties(string file) { |
| 43 | + using var reader = new StreamReader(file); |
10 | 44 |
|
11 |
| - public static string Tag => ThisAssembly.Git.Tag; |
12 |
| - public static string Hashtag => ThisAssembly.Git.Commit; |
13 |
| - public static readonly string Timestamp = ThisAssembly.Git.CommitDate; |
| 45 | + var properties = new Dictionary<string, string>(); |
| 46 | + string line; |
| 47 | + while ((line = reader.ReadLine()) != null) { |
| 48 | + var parts = line.Split('=', 2); |
| 49 | + if (parts.Length == 2) |
| 50 | + properties[parts[0]] = parts[1]; |
| 51 | + } |
14 | 52 |
|
15 |
| - public static string Text => $"EventStoreDB version {Version} ({Tag}/{Hashtag}, {Timestamp})"; |
| 53 | + return properties; |
| 54 | + } |
16 | 55 | }
|
17 | 56 | }
|
0 commit comments