From a1f112e62f6e99be12ea5a49005c6bba24d077f9 Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Wed, 4 Jan 2017 12:41:50 -0800 Subject: [PATCH] Added branch name to Assembly Info --- .../EnvironmentInfo/BuildInfoFixture.cs | 23 +++++++++++++++++ .../NzbDrone.Common.Test.csproj | 1 + .../EnvironmentInfo/BuildInfo.cs | 25 ++++++++++++++++++- .../Instrumentation/Sentry/SentryTarget.cs | 4 ++- .../Properties/SharedAssemblyInfo.cs | 4 ++- 5 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 src/NzbDrone.Common.Test/EnvironmentInfo/BuildInfoFixture.cs diff --git a/src/NzbDrone.Common.Test/EnvironmentInfo/BuildInfoFixture.cs b/src/NzbDrone.Common.Test/EnvironmentInfo/BuildInfoFixture.cs new file mode 100644 index 000000000..dca0b292e --- /dev/null +++ b/src/NzbDrone.Common.Test/EnvironmentInfo/BuildInfoFixture.cs @@ -0,0 +1,23 @@ +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Common.EnvironmentInfo; + +namespace NzbDrone.Common.Test.EnvironmentInfo +{ + [TestFixture] + public class BuildInfoFixture + { + [Test] + public void should_return_version() + { + BuildInfo.Version.Major.Should().BeOneOf(2, 10); + } + + [Test] + public void should_get_branch() + { + BuildInfo.Branch.Should().NotBe("unknow"); + BuildInfo.Branch.Should().NotBeNullOrWhiteSpace(); + } + } +} \ No newline at end of file diff --git a/src/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj b/src/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj index d33a221d1..3f501c00c 100644 --- a/src/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj +++ b/src/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj @@ -76,6 +76,7 @@ + diff --git a/src/NzbDrone.Common/EnvironmentInfo/BuildInfo.cs b/src/NzbDrone.Common/EnvironmentInfo/BuildInfo.cs index 03f0cd7c9..84a1d3435 100644 --- a/src/NzbDrone.Common/EnvironmentInfo/BuildInfo.cs +++ b/src/NzbDrone.Common/EnvironmentInfo/BuildInfo.cs @@ -1,12 +1,35 @@ using System; +using System.Diagnostics; using System.IO; +using System.Linq; using System.Reflection; namespace NzbDrone.Common.EnvironmentInfo { public static class BuildInfo { - public static Version Version => Assembly.GetExecutingAssembly().GetName().Version; + static BuildInfo() + { + var assembly = Assembly.GetExecutingAssembly(); + + Version = assembly.GetName().Version; + + var attributes = assembly.GetCustomAttributes(true); + + Branch = "unknow"; + + var config = attributes.OfType().FirstOrDefault(); + if (config != null) + { + Branch = config.Configuration; + } + + Release = $"{Version}-{Branch}"; + } + + public static Version Version { get; } + public static String Branch { get; } + public static string Release { get; } public static DateTime BuildDateTime { diff --git a/src/NzbDrone.Common/Instrumentation/Sentry/SentryTarget.cs b/src/NzbDrone.Common/Instrumentation/Sentry/SentryTarget.cs index 8d236ddbd..bf722e673 100644 --- a/src/NzbDrone.Common/Instrumentation/Sentry/SentryTarget.cs +++ b/src/NzbDrone.Common/Instrumentation/Sentry/SentryTarget.cs @@ -44,12 +44,14 @@ namespace NzbDrone.Common.Instrumentation.Sentry { Compression = true, Environment = RuntimeInfo.IsProduction ? "production" : "development", - Release = BuildInfo.Version.ToString(), + Release = BuildInfo.Release }; _client.Tags.Add("osfamily", OsInfo.Os.ToString()); _client.Tags.Add("runtime", PlatformInfo.Platform.ToString().ToLower()); _client.Tags.Add("culture", Thread.CurrentThread.CurrentCulture.Name); + _client.Tags.Add("branch", BuildInfo.Branch); + _client.Tags.Add("version", BuildInfo.Version.ToString()); } protected override void Write(LogEventInfo logEvent) diff --git a/src/NzbDrone.Common/Properties/SharedAssemblyInfo.cs b/src/NzbDrone.Common/Properties/SharedAssemblyInfo.cs index 9c8e66406..1e622af2c 100644 --- a/src/NzbDrone.Common/Properties/SharedAssemblyInfo.cs +++ b/src/NzbDrone.Common/Properties/SharedAssemblyInfo.cs @@ -1,7 +1,9 @@ using System.Reflection; using System.Runtime.InteropServices; -[assembly: AssemblyConfiguration("")] +// Gets updated at build time by TeamCity to branch name +[assembly: AssemblyConfiguration("debug")] + [assembly: AssemblyCompany("sonarr.tv")] [assembly: AssemblyProduct("NzbDrone")] [assembly: AssemblyCopyright("GNU General Public v3")]