Skip to content

Commit f5350cb

Browse files
Drive Versioninfo from a version.properties file at runtime
- Allows packages to be promoted without recompilation. - The build pipeline will populate the version.properties file - A default version.properties file is included for local builds, we will update this when we create new release branches since the version will be driven from this file rather than from a git tag. - Tag is removed as no longer relevant. Tier is added instead (EE/CE)
1 parent 6c85618 commit f5350cb

File tree

11 files changed

+75
-16
lines changed

11 files changed

+75
-16
lines changed

src/EventStore.ClusterNode/EventStore.ClusterNode.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
<ProjectReference Include="..\EventStore.Projections.Core\EventStore.Projections.Core.csproj" />
1818
</ItemGroup>
1919
<ItemGroup>
20+
<None Include="..\EventStore.Common\Utils\version.properties">
21+
<Link>version.properties</Link>
22+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
23+
</None>
2024
<None Include="..\EventStore.Common\Log\logconfig.json">
2125
<Link>logconfig.json</Link>
2226
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

src/EventStore.ClusterNode/Program.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ public static async Task<int> Main(string[] args) {
6363
return 0;
6464
}
6565

66-
Log.Information("\n{description,-25} {version} ({branch}/{hashtag}, {timestamp})", "ES VERSION:",
67-
VersionInfo.Version, VersionInfo.Tag, VersionInfo.Hashtag, VersionInfo.Timestamp);
66+
Log.Information("\n{description,-25} {version} {edition} ({buildId}/{commitSha}, {timestamp})", "ES VERSION:",
67+
VersionInfo.Version, VersionInfo.Edition, VersionInfo.BuildId, VersionInfo.CommitSha, VersionInfo.Timestamp);
6868
Log.Information("{description,-25} {osArchitecture} ", "OS ARCHITECTURE:",
6969
RuntimeInformation.OSArchitecture);
7070
Log.Information("{description,-25} {osFlavor} ({osVersion})", "OS:", OS.OsFlavor,

src/EventStore.Common/EventStore.Common.csproj

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
44
</PropertyGroup>
@@ -29,5 +29,10 @@
2929
<ItemGroup>
3030
<ProjectReference Include="..\EventStore.Common.Utils\EventStore.Common.Utils.csproj" />
3131
</ItemGroup>
32+
<ItemGroup>
33+
<None Update="Utils\version.properties">
34+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
35+
</None>
36+
</ItemGroup>
3237

3338
</Project>
+48-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,56 @@
1-
using System.Reflection;
1+
using System;
2+
using System.IO;
3+
using System.Collections.Generic;
24

35
namespace EventStore.Common.Utils {
46
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";
78
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);
1044

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+
}
1452

15-
public static string Text => $"EventStoreDB version {Version} ({Tag}/{Hashtag}, {Timestamp})";
53+
return properties;
54+
}
1655
}
1756
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
version=24.4.0-prerelease

src/EventStore.Core.Tests/EventStore.Core.Tests.csproj

+6
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@
5353
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
5454
</None>
5555
</ItemGroup>
56+
<ItemGroup>
57+
<None Include="..\EventStore.Common\Utils\version.properties">
58+
<Link>version.properties</Link>
59+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
60+
</None>
61+
</ItemGroup>
5662
<ItemGroup>
5763
<None Remove="FakePlugin\**" />
5864
<Compile Remove="FakePlugin\**" />

src/EventStore.Core.Tests/Helpers/MiniClusterNode.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public MiniClusterNode(string pathname, int debugIndex, IPEndPoint internalTcp,
157157
Log.Information(
158158
"\n{0,-25} {1} ({2}/{3}, {4})\n" + "{5,-25} {6} ({7})\n" + "{8,-25} {9} ({10}-bit)\n"
159159
+ "{11,-25} {12}\n" + "{13,-25} {14}\n" + "{15,-25} {16}\n" + "{17,-25} {18}\n\n",
160-
"ES VERSION:", VersionInfo.Version, VersionInfo.Tag, VersionInfo.Hashtag, VersionInfo.Timestamp,
160+
"ES VERSION:", VersionInfo.Version, VersionInfo.Edition, VersionInfo.CommitSha, VersionInfo.Timestamp,
161161
"OS:", OS.OsFlavor, Environment.OSVersion, "RUNTIME:", OS.GetRuntimeVersion(),
162162
Marshal.SizeOf(typeof(IntPtr)) * 8, "GC:",
163163
GC.MaxGeneration == 0

src/EventStore.Core.Tests/Helpers/MiniNode.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public MiniNode(string pathname,
151151
+ "{13,-25} {14}\n"
152152
+ "{15,-25} {16}\n"
153153
+ "{17,-25} {18}\n\n",
154-
"ES VERSION:", VersionInfo.Version, VersionInfo.Tag, VersionInfo.Hashtag, VersionInfo.Timestamp,
154+
"ES VERSION:", VersionInfo.Version, VersionInfo.Edition, VersionInfo.CommitSha, VersionInfo.Timestamp,
155155
"OS:", OS.OsFlavor, Environment.OSVersion,
156156
"RUNTIME:", OS.GetRuntimeVersion(), Marshal.SizeOf(typeof(IntPtr)) * 8,
157157
"GC:",

src/EventStore.Core.Tests/TestsInitFixture.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ private void LogEnvironmentInfo() {
2121
+ "{5,-25} {6} ({7})\n"
2222
+ "{8,-25} {9} ({10}-bit)\n"
2323
+ "{11,-25} {12}\n\n",
24-
"ES VERSION:", VersionInfo.Version, VersionInfo.Tag, VersionInfo.Hashtag, VersionInfo.Timestamp,
24+
"ES VERSION:", VersionInfo.Version, VersionInfo.Edition, VersionInfo.CommitSha, VersionInfo.Timestamp,
2525
"OS:", OS.OsFlavor, Environment.OSVersion,
2626
"RUNTIME:", OS.GetRuntimeVersion(), Marshal.SizeOf(typeof(IntPtr)) * 8,
2727
"GC:",

src/EventStore.Core.XUnit.Tests/EventStore.Core.XUnit.Tests.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,9 @@
2626
<None Update="xunit.runner.json">
2727
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
2828
</None>
29+
<None Include="..\EventStore.Common\Utils\version.properties">
30+
<Link>version.properties</Link>
31+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
32+
</None>
2933
</ItemGroup>
3034
</Project>

src/EventStore.Core/Telemetry/TelemetryService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private void Handle(TelemetryMessage.Request message) {
120120
"version", JsonValue.Create(VersionInfo.Version)));
121121

122122
message.Envelope.ReplyWith(new TelemetryMessage.Response(
123-
"tag", JsonValue.Create(VersionInfo.Tag)));
123+
"edition", JsonValue.Create(VersionInfo.Edition)));
124124

125125
message.Envelope.ReplyWith(new TelemetryMessage.Response(
126126
"uptime", JsonValue.Create(DateTime.UtcNow - _startTime)));

0 commit comments

Comments
 (0)