Skip to content

Commit

Permalink
Display commit in version information
Browse files Browse the repository at this point in the history
  • Loading branch information
ConfusedPolarBear committed Nov 23, 2022
1 parent c7b6692 commit 50e1d15
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Net.Mime;
using System.Text;
using MediaBrowser.Common;
Expand Down Expand Up @@ -47,8 +48,23 @@ public ActionResult<string> GetSupportBundle()
bundle.Append(_applicationHost.ApplicationVersionString);
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.Instance!.Version.ToString(3));
bundle.Append(version);
bundle.Append('\n');

bundle.Append("* Queue contents: ");
Expand Down
38 changes: 0 additions & 38 deletions ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ public Task RunAsync()
{
FFmpegWrapper.Logger = _logger;

#if DEBUG
LogVersion();
#endif

// 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.

Expand All @@ -75,40 +71,6 @@ public Task RunAsync()
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>
/// Dispose.
/// </summary>
Expand Down
29 changes: 29 additions & 0 deletions ConfusedPolarBear.Plugin.IntroSkipper/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,35 @@ public IEnumerable<PluginPageInfo> GetPages()
};
}

/// <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)
{
return _libraryManager.GetItemById(id);
Expand Down

0 comments on commit 50e1d15

Please sign in to comment.