Embed commit hash into unstable builds

This commit is contained in:
ConfusedPolarBear 2022-06-12 16:57:15 -05:00
parent 01d7f570fa
commit 87eda41001
4 changed files with 44 additions and 0 deletions

View File

@ -22,6 +22,9 @@ jobs:
- name: Restore dependencies
run: dotnet restore
- name: Embed version info
run: echo "${{ github.sha }}" > ConfusedPolarBear.Plugin.IntroSkipper/Configuration/version.txt
- name: Build
run: dotnet build --no-restore

View File

@ -0,0 +1 @@
unknown

View File

@ -23,6 +23,7 @@
<ItemGroup>
<None Remove="Configuration\configPage.html" />
<EmbeddedResource Include="Configuration\configPage.html" />
<EmbeddedResource Include="Configuration\version.txt" />
</ItemGroup>
</Project>

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Jellyfin.Data.Enums;
using MediaBrowser.Controller.Entities;
@ -51,6 +52,10 @@ public class Entrypoint : IServerEntryPoint
{
Chromaprint.Logger = _logger;
#if DEBUG
LogVersion();
#endif
// Assert that ffmpeg with chromaprint is installed
if (!Chromaprint.CheckFFmpegVersion())
{
@ -195,6 +200,40 @@ public class Entrypoint : IServerEntryPoint
throw new FingerprintException("Unable to find an administrator on this server.");
}
#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>