Added branch name to Assembly Info

This commit is contained in:
Keivan Beigi 2017-01-04 12:41:50 -08:00
parent 053c730799
commit a1f112e62f
5 changed files with 54 additions and 3 deletions

View File

@ -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();
}
}
}

View File

@ -76,6 +76,7 @@
<Compile Include="DiskTests\IsParentFixtureBase.cs" />
<Compile Include="DiskTests\DiskTransferServiceFixture.cs" />
<Compile Include="EnsureTest\PathExtensionFixture.cs" />
<Compile Include="EnvironmentInfo\BuildInfoFixture.cs" />
<Compile Include="EnvironmentProviderTest.cs" />
<Compile Include="EnvironmentTests\EnvironmentProviderTest.cs" />
<Compile Include="EnvironmentTests\StartupArgumentsFixture.cs" />

View File

@ -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<AssemblyConfigurationAttribute>().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
{

View File

@ -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)

View File

@ -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")]