From 87eda41001b339e030b57824fd399c990c444881 Mon Sep 17 00:00:00 2001
From: ConfusedPolarBear <33811686+ConfusedPolarBear@users.noreply.github.com>
Date: Sun, 12 Jun 2022 16:57:15 -0500
Subject: [PATCH] Embed commit hash into unstable builds
---
.github/workflows/build.yml | 3 ++
.../Configuration/version.txt | 1 +
...nfusedPolarBear.Plugin.IntroSkipper.csproj | 1 +
.../Entrypoint.cs | 39 +++++++++++++++++++
4 files changed, 44 insertions(+)
create mode 100644 ConfusedPolarBear.Plugin.IntroSkipper/Configuration/version.txt
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index a5385ed..5257d0e 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -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
diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/version.txt b/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/version.txt
new file mode 100644
index 0000000..3546645
--- /dev/null
+++ b/ConfusedPolarBear.Plugin.IntroSkipper/Configuration/version.txt
@@ -0,0 +1 @@
+unknown
diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/ConfusedPolarBear.Plugin.IntroSkipper.csproj b/ConfusedPolarBear.Plugin.IntroSkipper/ConfusedPolarBear.Plugin.IntroSkipper.csproj
index 16990a2..0fe5248 100644
--- a/ConfusedPolarBear.Plugin.IntroSkipper/ConfusedPolarBear.Plugin.IntroSkipper.csproj
+++ b/ConfusedPolarBear.Plugin.IntroSkipper/ConfusedPolarBear.Plugin.IntroSkipper.csproj
@@ -23,6 +23,7 @@
+
diff --git a/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs b/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs
index 3aac306..5be6297 100644
--- a/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs
+++ b/ConfusedPolarBear.Plugin.IntroSkipper/Entrypoint.cs
@@ -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
+ ///
+ /// Logs the exact commit that created this version of the plugin. Only used in unstable builds.
+ ///
+ 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
+
///
/// Dispose.
///