Display commit in version information

This commit is contained in:
ConfusedPolarBear 2022-11-23 01:20:48 -06:00
parent c7b6692436
commit 50e1d15cb9
3 changed files with 46 additions and 39 deletions

View File

@ -1,3 +1,4 @@
using System;
using System.Net.Mime; using System.Net.Mime;
using System.Text; using System.Text;
using MediaBrowser.Common; using MediaBrowser.Common;
@ -47,8 +48,23 @@ public class TroubleshootingController : ControllerBase
bundle.Append(_applicationHost.ApplicationVersionString); bundle.Append(_applicationHost.ApplicationVersionString);
bundle.Append('\n'); bundle.Append('\n');
var version = Plugin.Instance!.Version.ToString(3);
try
{
var commit = Plugin.Instance!.GetCommit();
if (!string.IsNullOrWhiteSpace(commit))
{
version += string.Concat("+", commit.AsSpan(0, 12));
}
}
catch (Exception ex)
{
_logger.LogWarning("Unable to append commit to version: {Exception}", ex);
}
bundle.Append("* Plugin version: "); bundle.Append("* Plugin version: ");
bundle.Append(Plugin.Instance!.Version.ToString(3)); bundle.Append(version);
bundle.Append('\n'); bundle.Append('\n');
bundle.Append("* Queue contents: "); bundle.Append("* Queue contents: ");

View File

@ -48,10 +48,6 @@ public class Entrypoint : IServerEntryPoint
{ {
FFmpegWrapper.Logger = _logger; FFmpegWrapper.Logger = _logger;
#if DEBUG
LogVersion();
#endif
// TODO: when a new item is added to the server, immediately analyze the season it belongs to // TODO: when a new item is added to the server, immediately analyze the season it belongs to
// instead of waiting for the next task interval. The task start should be debounced by a few seconds. // instead of waiting for the next task interval. The task start should be debounced by a few seconds.
@ -75,40 +71,6 @@ public class Entrypoint : IServerEntryPoint
return Task.CompletedTask; return Task.CompletedTask;
} }
#if DEBUG
/// <summary>
/// Logs the exact commit that created this version of the plugin. Only used in unstable builds.
/// </summary>
private void LogVersion()
{
var assembly = GetType().Assembly;
var path = GetType().Namespace + ".Configuration.version.txt";
using (var stream = assembly.GetManifestResourceStream(path))
{
if (stream is null)
{
_logger.LogWarning("Unable to read embedded version information");
return;
}
var version = string.Empty;
using (var reader = new StreamReader(stream))
{
version = reader.ReadToEnd().TrimEnd();
}
if (version == "unknown")
{
_logger.LogTrace("Embedded version information was not valid, ignoring");
return;
}
_logger.LogInformation("Unstable version built from commit {Version}", version);
}
}
#endif
/// <summary> /// <summary>
/// Dispose. /// Dispose.
/// </summary> /// </summary>

View File

@ -203,6 +203,35 @@ public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
}; };
} }
/// <summary>
/// Gets the commit used to build the plugin.
/// </summary>
/// <returns>Commit.</returns>
public string GetCommit()
{
var commit = string.Empty;
var path = GetType().Namespace + ".Configuration.version.txt";
using var stream = GetType().Assembly.GetManifestResourceStream(path);
if (stream is null)
{
_logger.LogWarning("Unable to read embedded version information");
return commit;
}
using var reader = new StreamReader(stream);
commit = reader.ReadToEnd().TrimEnd();
if (commit == "unknown")
{
_logger.LogTrace("Embedded version information was not valid, ignoring");
return string.Empty;
}
_logger.LogInformation("Unstable plugin version built from commit {Commit}", commit);
return commit;
}
internal BaseItem GetItem(Guid id) internal BaseItem GetItem(Guid id)
{ {
return _libraryManager.GetItemById(id); return _libraryManager.GetItemById(id);