From 2b00a0688eb854d156faaf654675adc8b047e24f Mon Sep 17 00:00:00 2001 From: chodeus <190988615+chodeus@users.noreply.github.com> Date: Wed, 18 Nov 2026 11:43:29 +0800 Subject: [PATCH 1/5] fix(release): ship a net10.0 zip, checked against Lidarr's nightly, so Lidarr 4.0 can install the plugin --- .github/workflows/build.yml | 57 ++++++++--- .github/workflows/ci.yml | 3 + tools/PluginCheck/PluginCheck.csproj | 20 ++++ tools/PluginCheck/Program.cs | 141 +++++++++++++++++++++++++++ tools/PluginCheck/check-nightly.sh | 27 +++++ 5 files changed, 237 insertions(+), 11 deletions(-) create mode 100644 tools/PluginCheck/PluginCheck.csproj create mode 100644 tools/PluginCheck/Program.cs create mode 100644 tools/PluginCheck/check-nightly.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 635e187d..3cece30e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,6 +34,8 @@ env: # renovate: datasource=dotnet-version depName=dotnet-sdk DOTNET_VERSION: '8.0.428' PLUGIN_NAME: 'Sleezer' + # Lidarr installs only a zip named for its own runtime; the build ships a copy under this name once it passes against Lidarr's nightly. + LIDARR_NIGHTLY_FRAMEWORK: 'net10.0' jobs: build: @@ -50,7 +52,7 @@ jobs: branch_repo_url: ${{ steps.git_info.outputs.branch_repo_url }} plugin_input_format: ${{ steps.git_info.outputs.plugin_input_format }} commit_messages: ${{ steps.git_info.outputs.commit_messages }} - package_name: ${{ steps.package.outputs.package_name }} + package_names: ${{ steps.nightly.outputs.package_names }} steps: - name: Checkout with submodules uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 @@ -404,11 +406,34 @@ jobs: dotnet run --project tools/SmokeLoad/SmokeLoad.csproj \ -c Release --no-build -- "$PLUGIN_DLL" "$HOST_DIR" + - name: Check against Lidarr nightly and package for its runtime + # Compiling against ext/Lidarr cannot catch a member Lidarr 4.0 removed (v1.39.11); PluginCheck lists such refs. + id: nightly + env: + PACKAGE_NAME: ${{ steps.package.outputs.package_name }} + VERSION: ${{ steps.meta.outputs.package_version }} + FRAMEWORK: ${{ steps.meta.outputs.framework }} + run: | + set -euo pipefail + if [ "$LIDARR_NIGHTLY_FRAMEWORK" = "$FRAMEWORK" ]; then + echo "::error::The plugin now builds for $FRAMEWORK itself; drop the nightly copy from this workflow" + exit 1 + fi + + STAGE=$(mktemp -d) + unzip -q "$GITHUB_WORKSPACE/$PACKAGE_NAME" -d "$STAGE" + bash tools/PluginCheck/check-nightly.sh "$STAGE/Lidarr.Plugin.$PLUGIN_NAME.dll" "$LIDARR_NIGHTLY_FRAMEWORK" + + NIGHTLY_NAME="${PLUGIN_NAME}-v${VERSION}.${LIDARR_NIGHTLY_FRAMEWORK}.zip" + cp "$GITHUB_WORKSPACE/$PACKAGE_NAME" "$GITHUB_WORKSPACE/$NIGHTLY_NAME" + { echo "package_names<> "$GITHUB_OUTPUT" + - name: Upload plugin package uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7 with: name: plugin-package - path: ${{ steps.package.outputs.package_name }} + path: ${{ steps.nightly.outputs.package_names }} + if-no-files-found: error retention-days: 7 - name: Upload build logs @@ -438,16 +463,26 @@ jobs: - name: Verify artifact id: verify env: - PACKAGE_NAME: ${{ needs.build.outputs.package_name }} + PACKAGE_NAMES: ${{ needs.build.outputs.package_names }} run: | - ARTIFACT_PATH="./artifacts/$PACKAGE_NAME" - if [ ! -s "$ARTIFACT_PATH" ]; then - echo "::error::Artifact missing or empty at $ARTIFACT_PATH" - ls -la ./artifacts/ + set -euo pipefail + PATHS=() + while IFS= read -r NAME; do + [ -n "$NAME" ] || continue + ARTIFACT_PATH="./artifacts/$NAME" + if [ ! -s "$ARTIFACT_PATH" ]; then + echo "::error::Artifact missing or empty at $ARTIFACT_PATH" + ls -la ./artifacts/ + exit 1 + fi + echo "$NAME: $(stat -c%s "$ARTIFACT_PATH") bytes" + PATHS+=("$ARTIFACT_PATH") + done <<< "$PACKAGE_NAMES" + if [ "${#PATHS[@]}" -eq 0 ]; then + echo "::error::The build job named no packages" exit 1 fi - echo "Size: $(stat -c%s "$ARTIFACT_PATH") bytes" - echo "artifact_path=$ARTIFACT_PATH" >> "$GITHUB_OUTPUT" + { echo "artifact_paths<> "$GITHUB_OUTPUT" - name: Generate release notes markdown id: notes @@ -474,7 +509,7 @@ jobs: ## 📦 Package Information **Version:** $VERSION - **.NET Version:** $FRAMEWORK + **.NET Version:** $FRAMEWORK, also as $LIDARR_NIGHTLY_FRAMEWORK (checked against Lidarr's nightly) **Minimum Lidarr Version:** $MIN_LIDARR **Commit:** $COMMIT EOL @@ -489,7 +524,7 @@ jobs: prerelease: ${{ needs.build.outputs.is_prerelease == 'true' }} make_latest: ${{ needs.build.outputs.is_latestrelease == 'true' }} target_commitish: ${{ needs.build.outputs.git_branch }} - files: ${{ steps.verify.outputs.artifact_path }} + files: ${{ steps.verify.outputs.artifact_paths }} fail_on_unmatched_files: true env: GITHUB_TOKEN: ${{ github.token }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d41ac2e5..cab262d4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -83,6 +83,9 @@ jobs: dotnet test tests/${PLUGIN_NAME}.Tests/${PLUGIN_NAME}.Tests.csproj \ -c Release -p:NuGetAudit=false + - name: Check against Lidarr nightly + run: bash tools/PluginCheck/check-nightly.sh "_plugins/net8.0/${PLUGIN_NAME}/Lidarr.Plugin.${PLUGIN_NAME}.dll" + dependency-audit: runs-on: ubuntu-latest steps: diff --git a/tools/PluginCheck/PluginCheck.csproj b/tools/PluginCheck/PluginCheck.csproj new file mode 100644 index 00000000..cacc11b3 --- /dev/null +++ b/tools/PluginCheck/PluginCheck.csproj @@ -0,0 +1,20 @@ + + + + + Exe + net8.0 + disable + enable + Sleezer.PluginCheck + Sleezer.PluginCheck + false + bin/$(Configuration)/ + true + + + + + + + diff --git a/tools/PluginCheck/Program.cs b/tools/PluginCheck/Program.cs new file mode 100644 index 00000000..07f6d485 --- /dev/null +++ b/tools/PluginCheck/Program.cs @@ -0,0 +1,141 @@ +using Mono.Cecil; + +// Usage: Sleezer.PluginCheck . Lists every Lidarr type or member the plugin uses that the build lacks, +// and every Lidarr interface or abstract member a plugin type no longer implements. +if (args.Length < 2) +{ + Console.Error.WriteLine("Usage: Sleezer.PluginCheck "); + return 2; +} + +var plugin = args[0]; +var lib = args[1]; +var resolver = new DefaultAssemblyResolver(); +resolver.AddSearchDirectory(lib); +resolver.AddSearchDirectory(Path.GetDirectoryName(Path.GetFullPath(plugin))); +resolver.AddSearchDirectory(System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory()); +var module = ModuleDefinition.ReadModule(plugin, new ReaderParameters { AssemblyResolver = resolver }); + +var self = module.Assembly.Name.Name; +bool IsLidarr(IMetadataScope scope) => scope is AssemblyNameReference a && a.Name.StartsWith("Lidarr.", StringComparison.Ordinal) && a.Name != self; +static TypeReference Outer(TypeReference t) +{ + while (t.DeclaringType != null) + { + t = t.DeclaringType; + } + + return t; +} + +static TypeReference Element(TypeReference t) => t is TypeSpecification s ? Element(s.ElementType) : t; + +var problems = new SortedSet(StringComparer.Ordinal); +int types = 0, members = 0, impls = 0; + +foreach (var tr in module.GetTypeReferences()) +{ + if (!IsLidarr(Outer(tr).Scope)) + { + continue; + } + + types++; + if (tr.Resolve() == null) + { + problems.Add($"missing type {tr.FullName} ({Outer(tr).Scope.Name})"); + } +} + +foreach (var mr in module.GetMemberReferences()) +{ + if (!IsLidarr(Outer(Element(mr.DeclaringType)).Scope)) + { + continue; + } + + members++; + var resolved = mr switch { MethodReference m => (IMemberDefinition)m.Resolve(), FieldReference f => f.Resolve(), _ => null }; + if (resolved == null) + { + problems.Add($"missing member {mr.FullName}"); + } +} + +IEnumerable All(IEnumerable ts) => ts.SelectMany(t => new[] { t }.Concat(All(t.NestedTypes))); + +bool Implements(TypeDefinition type, MethodDefinition required) +{ + for (var t = type; t != null; t = t.BaseType?.Resolve()) + { + if (t.Methods.Any(m => !m.IsAbstract && (m.Name == required.Name || m.Name.EndsWith("." + required.Name, StringComparison.Ordinal)) && m.Parameters.Count == required.Parameters.Count)) + { + return true; + } + + if (t.Methods.Any(m => m.Overrides.Any(o => o.Name == required.Name && o.Parameters.Count == required.Parameters.Count))) + { + return true; + } + } + + return false; +} + +void CollectInterfaces(TypeDefinition t, List into) +{ + if (t == null) + { + return; + } + + foreach (var i in t.Interfaces) + { + var d = Element(i.InterfaceType).Resolve(); + if (d == null) + { + continue; + } + + if (IsLidarr(Outer(Element(i.InterfaceType)).Scope)) + { + into.Add(d); + } + + CollectInterfaces(d, into); + } + + CollectInterfaces(t.BaseType == null ? null : Element(t.BaseType).Resolve(), into); +} + +foreach (var type in All(module.Types).Where(t => !t.IsInterface && !t.IsAbstract)) +{ + var required = new List(); + for (var b = type.BaseType; b != null && Element(b).Resolve() is TypeDefinition bd; b = bd.BaseType) + { + if (IsLidarr(Outer(Element(b)).Scope)) + { + required.Add(bd); + } + } + + CollectInterfaces(type, required); + + foreach (var method in required.SelectMany(t => t.Methods).Where(m => m.IsAbstract && !m.IsStatic).Distinct()) + { + impls++; + if (!Implements(type, method)) + { + problems.Add($"unimplemented {type.FullName} lacks {method.DeclaringType.FullName}.{method.Name}({method.Parameters.Count})"); + } + } +} + +Console.WriteLine($"checked {types} Lidarr type refs, {members} member refs, {impls} required members against {lib}"); +foreach (var p in problems) +{ + Console.WriteLine(p); +} + +Console.WriteLine(problems.Count == 0 ? "RESULT: compatible" : $"RESULT: {problems.Count} problem(s)"); +return problems.Count == 0 ? 0 : 1; diff --git a/tools/PluginCheck/check-nightly.sh b/tools/PluginCheck/check-nightly.sh new file mode 100644 index 00000000..ab3f2206 --- /dev/null +++ b/tools/PluginCheck/check-nightly.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +# Usage: check-nightly.sh [framework]. Runs PluginCheck against Lidarr's nightly; with a framework, also fails unless the nightly runs it. +set -euo pipefail + +plugin=$1 +framework=${2:-} +host=$(mktemp -d) +trap 'rm -rf "$host"' EXIT + +if ! curl -fsSL --retry 3 -o "$host/lidarr.tar.gz" \ + "https://lidarr.servarr.com/v1/update/nightly/updatefile?os=linux&runtime=netcore&arch=x64"; then + echo "::error::Could not download Lidarr's nightly build" + exit 1 +fi +tar -xzf "$host/lidarr.tar.gz" -C "$host" +nightly=$(jq -r .runtimeOptions.tfm "$host/Lidarr/Lidarr.runtimeconfig.json") +if [ -n "$framework" ] && [ "$nightly" != "$framework" ]; then + echo "::error::Lidarr's nightly runs $nightly, not $framework, so the $framework zip cannot be checked" + exit 1 +fi + +project="$(dirname "$0")/PluginCheck.csproj" +dotnet build "$project" -c Release --nologo +if ! dotnet run --project "$project" -c Release --no-build -- "$plugin" "$host/Lidarr"; then + echo "::error::PluginCheck failed against Lidarr's $nightly nightly (see above)" + exit 1 +fi From 15c1bd83039d5594aa5fe2ffdc432dc5a7e9022f Mon Sep 17 00:00:00 2001 From: chodeus <190988615+chodeus@users.noreply.github.com> Date: Wed, 18 Nov 2026 12:31:33 +0800 Subject: [PATCH 2/5] fix(release): PluginCheck compares member signatures, and each nightly check failure says what failed --- tools/PluginCheck/Checker.cs | 182 +++++++++++++++++++++++++++++ tools/PluginCheck/Program.cs | 132 +-------------------- tools/PluginCheck/check-nightly.sh | 18 ++- 3 files changed, 204 insertions(+), 128 deletions(-) create mode 100644 tools/PluginCheck/Checker.cs diff --git a/tools/PluginCheck/Checker.cs b/tools/PluginCheck/Checker.cs new file mode 100644 index 00000000..c6cb9a8d --- /dev/null +++ b/tools/PluginCheck/Checker.cs @@ -0,0 +1,182 @@ +using Mono.Cecil; + +namespace Sleezer.PluginCheck +{ + public sealed class Checker + { + private readonly ModuleDefinition _module; + private readonly string _self; + private readonly SortedSet _problems = new(StringComparer.Ordinal); + + public Checker(string plugin, string lib) + { + var resolver = new DefaultAssemblyResolver(); + resolver.AddSearchDirectory(lib); + resolver.AddSearchDirectory(Path.GetDirectoryName(Path.GetFullPath(plugin))); + resolver.AddSearchDirectory(System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory()); + _module = ModuleDefinition.ReadModule(plugin, new ReaderParameters { AssemblyResolver = resolver }); + _self = _module.Assembly.Name.Name; + } + + public int TypeRefs { get; private set; } + public int MemberRefs { get; private set; } + public int RequiredMembers { get; private set; } + + public IReadOnlyCollection Run() + { + CheckTypeRefs(); + CheckMemberRefs(); + CheckImplementations(); + return _problems; + } + + private void CheckTypeRefs() + { + foreach (var tr in _module.GetTypeReferences().Where(t => IsLidarr(Outer(t).Scope))) + { + TypeRefs++; + if (tr.Resolve() == null) + { + _problems.Add($"missing type {tr.FullName} ({Outer(tr).Scope.Name})"); + } + } + } + + private void CheckMemberRefs() + { + foreach (var mr in _module.GetMemberReferences().Where(m => IsLidarr(Outer(Element(m.DeclaringType)).Scope))) + { + MemberRefs++; + var resolved = mr switch { MethodReference m => (IMemberDefinition)m.Resolve(), FieldReference f => f.Resolve(), _ => null }; + if (resolved == null) + { + _problems.Add($"missing member {mr.FullName}"); + } + } + } + + private void CheckImplementations() + { + foreach (var type in AllTypes(_module.Types).Where(t => !t.IsInterface && !t.IsAbstract)) + { + foreach (var method in RequiredMethods(type)) + { + RequiredMembers++; + if (!Implements(type, method)) + { + _problems.Add($"unimplemented {type.FullName} lacks {method.FullName}"); + } + } + } + } + + private IEnumerable RequiredMethods(TypeDefinition type) + { + var required = new List(); + for (var b = type.BaseType; b != null && Element(b).Resolve() is TypeDefinition bd; b = bd.BaseType) + { + if (IsLidarr(Outer(Element(b)).Scope)) + { + required.Add(bd); + } + } + + CollectInterfaces(type, required); + return required.SelectMany(t => t.Methods).Where(m => m.IsAbstract && !m.IsStatic).Distinct(); + } + + private void CollectInterfaces(TypeDefinition t, List into) + { + if (t == null) + { + return; + } + + foreach (var i in t.Interfaces) + { + var d = Element(i.InterfaceType).Resolve(); + if (d == null) + { + continue; + } + + if (IsLidarr(Outer(Element(i.InterfaceType)).Scope)) + { + into.Add(d); + } + + CollectInterfaces(d, into); + } + + CollectInterfaces(t.BaseType == null ? null : Element(t.BaseType).Resolve(), into); + } + + private bool IsLidarr(IMetadataScope scope) => + scope is AssemblyNameReference a && a.Name.StartsWith("Lidarr.", StringComparison.Ordinal) && a.Name != _self; + + private static bool Implements(TypeDefinition type, MethodDefinition required) + { + for (var t = type; t != null; t = t.BaseType?.Resolve()) + { + if (t.Methods.Any(m => !m.IsAbstract && (m.Name == required.Name || m.Name.EndsWith("." + required.Name, StringComparison.Ordinal)) && SameSignature(m, required))) + { + return true; + } + + if (t.Methods.Any(m => m.Overrides.Any(o => o.Name == required.Name && SameSignature(o, required)))) + { + return true; + } + } + + return false; + } + + private static bool SameSignature(MethodReference m, MethodReference required) => + m.Parameters.Count == required.Parameters.Count + && SameType(m.ReturnType, required.ReturnType) + && m.Parameters.Zip(required.Parameters).All(p => SameType(p.First.ParameterType, p.Second.ParameterType)); + + // A generic parameter on either side matches any type: substituting them needs every base's arguments + private static bool SameType(TypeReference a, TypeReference b) + { + a = StripModifiers(a); + b = StripModifiers(b); + + if (a is GenericParameter || b is GenericParameter) + { + return true; + } + + if (a is GenericInstanceType ga && b is GenericInstanceType gb) + { + return SameType(ga.ElementType, gb.ElementType) + && ga.GenericArguments.Count == gb.GenericArguments.Count + && ga.GenericArguments.Zip(gb.GenericArguments).All(p => SameType(p.First, p.Second)); + } + + if (a is TypeSpecification sa && b is TypeSpecification sb) + { + return sa.GetType() == sb.GetType() && (sa as ArrayType)?.Rank == (sb as ArrayType)?.Rank && SameType(sa.ElementType, sb.ElementType); + } + + return a.FullName == b.FullName; + } + + private static TypeReference StripModifiers(TypeReference t) => t is IModifierType m ? StripModifiers(m.ElementType) : t; + + private static IEnumerable AllTypes(IEnumerable ts) => ts.SelectMany(t => new[] { t }.Concat(AllTypes(t.NestedTypes))); + + private static TypeReference Outer(TypeReference t) + { + while (t.DeclaringType != null) + { + t = t.DeclaringType; + } + + return t; + } + + private static TypeReference Element(TypeReference t) => t is TypeSpecification s ? Element(s.ElementType) : t; + } +} diff --git a/tools/PluginCheck/Program.cs b/tools/PluginCheck/Program.cs index 07f6d485..771b044f 100644 --- a/tools/PluginCheck/Program.cs +++ b/tools/PluginCheck/Program.cs @@ -1,137 +1,17 @@ -using Mono.Cecil; +using Sleezer.PluginCheck; -// Usage: Sleezer.PluginCheck . Lists every Lidarr type or member the plugin uses that the build lacks, -// and every Lidarr interface or abstract member a plugin type no longer implements. +// Usage: Sleezer.PluginCheck . Lists each Lidarr type or member the plugin uses that the build lacks, +// and each Lidarr interface or abstract member a plugin type no longer implements (Checker.SameType says what a signature match is). if (args.Length < 2) { Console.Error.WriteLine("Usage: Sleezer.PluginCheck "); return 2; } -var plugin = args[0]; -var lib = args[1]; -var resolver = new DefaultAssemblyResolver(); -resolver.AddSearchDirectory(lib); -resolver.AddSearchDirectory(Path.GetDirectoryName(Path.GetFullPath(plugin))); -resolver.AddSearchDirectory(System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory()); -var module = ModuleDefinition.ReadModule(plugin, new ReaderParameters { AssemblyResolver = resolver }); +var checker = new Checker(args[0], args[1]); +var problems = checker.Run(); -var self = module.Assembly.Name.Name; -bool IsLidarr(IMetadataScope scope) => scope is AssemblyNameReference a && a.Name.StartsWith("Lidarr.", StringComparison.Ordinal) && a.Name != self; -static TypeReference Outer(TypeReference t) -{ - while (t.DeclaringType != null) - { - t = t.DeclaringType; - } - - return t; -} - -static TypeReference Element(TypeReference t) => t is TypeSpecification s ? Element(s.ElementType) : t; - -var problems = new SortedSet(StringComparer.Ordinal); -int types = 0, members = 0, impls = 0; - -foreach (var tr in module.GetTypeReferences()) -{ - if (!IsLidarr(Outer(tr).Scope)) - { - continue; - } - - types++; - if (tr.Resolve() == null) - { - problems.Add($"missing type {tr.FullName} ({Outer(tr).Scope.Name})"); - } -} - -foreach (var mr in module.GetMemberReferences()) -{ - if (!IsLidarr(Outer(Element(mr.DeclaringType)).Scope)) - { - continue; - } - - members++; - var resolved = mr switch { MethodReference m => (IMemberDefinition)m.Resolve(), FieldReference f => f.Resolve(), _ => null }; - if (resolved == null) - { - problems.Add($"missing member {mr.FullName}"); - } -} - -IEnumerable All(IEnumerable ts) => ts.SelectMany(t => new[] { t }.Concat(All(t.NestedTypes))); - -bool Implements(TypeDefinition type, MethodDefinition required) -{ - for (var t = type; t != null; t = t.BaseType?.Resolve()) - { - if (t.Methods.Any(m => !m.IsAbstract && (m.Name == required.Name || m.Name.EndsWith("." + required.Name, StringComparison.Ordinal)) && m.Parameters.Count == required.Parameters.Count)) - { - return true; - } - - if (t.Methods.Any(m => m.Overrides.Any(o => o.Name == required.Name && o.Parameters.Count == required.Parameters.Count))) - { - return true; - } - } - - return false; -} - -void CollectInterfaces(TypeDefinition t, List into) -{ - if (t == null) - { - return; - } - - foreach (var i in t.Interfaces) - { - var d = Element(i.InterfaceType).Resolve(); - if (d == null) - { - continue; - } - - if (IsLidarr(Outer(Element(i.InterfaceType)).Scope)) - { - into.Add(d); - } - - CollectInterfaces(d, into); - } - - CollectInterfaces(t.BaseType == null ? null : Element(t.BaseType).Resolve(), into); -} - -foreach (var type in All(module.Types).Where(t => !t.IsInterface && !t.IsAbstract)) -{ - var required = new List(); - for (var b = type.BaseType; b != null && Element(b).Resolve() is TypeDefinition bd; b = bd.BaseType) - { - if (IsLidarr(Outer(Element(b)).Scope)) - { - required.Add(bd); - } - } - - CollectInterfaces(type, required); - - foreach (var method in required.SelectMany(t => t.Methods).Where(m => m.IsAbstract && !m.IsStatic).Distinct()) - { - impls++; - if (!Implements(type, method)) - { - problems.Add($"unimplemented {type.FullName} lacks {method.DeclaringType.FullName}.{method.Name}({method.Parameters.Count})"); - } - } -} - -Console.WriteLine($"checked {types} Lidarr type refs, {members} member refs, {impls} required members against {lib}"); +Console.WriteLine($"checked {checker.TypeRefs} Lidarr type refs, {checker.MemberRefs} member refs, {checker.RequiredMembers} required members against {args[1]}"); foreach (var p in problems) { Console.WriteLine(p); diff --git a/tools/PluginCheck/check-nightly.sh b/tools/PluginCheck/check-nightly.sh index ab3f2206..c757641d 100644 --- a/tools/PluginCheck/check-nightly.sh +++ b/tools/PluginCheck/check-nightly.sh @@ -4,6 +4,10 @@ set -euo pipefail plugin=$1 framework=${2:-} +if [ ! -f "$plugin" ]; then + echo "::error::No plugin at $plugin to check" + exit 1 +fi host=$(mktemp -d) trap 'rm -rf "$host"' EXIT @@ -12,8 +16,18 @@ if ! curl -fsSL --retry 3 -o "$host/lidarr.tar.gz" \ echo "::error::Could not download Lidarr's nightly build" exit 1 fi -tar -xzf "$host/lidarr.tar.gz" -C "$host" -nightly=$(jq -r .runtimeOptions.tfm "$host/Lidarr/Lidarr.runtimeconfig.json") +if ! tar -xzf "$host/lidarr.tar.gz" -C "$host"; then + echo "::error::Lidarr's nightly download is not a readable tarball" + exit 1 +fi +if [ ! -f "$host/Lidarr/Lidarr.runtimeconfig.json" ]; then + echo "::error::Lidarr's nightly download has no Lidarr/Lidarr.runtimeconfig.json" + exit 1 +fi +if ! nightly=$(jq -er .runtimeOptions.tfm "$host/Lidarr/Lidarr.runtimeconfig.json"); then + echo "::error::Lidarr's nightly names no runtime in Lidarr/Lidarr.runtimeconfig.json" + exit 1 +fi if [ -n "$framework" ] && [ "$nightly" != "$framework" ]; then echo "::error::Lidarr's nightly runs $nightly, not $framework, so the $framework zip cannot be checked" exit 1 From 37a64aaa6d11b8f8ad7d2863099964f0617f3333 Mon Sep 17 00:00:00 2001 From: chodeus <190988615+chodeus@users.noreply.github.com> Date: Wed, 18 Nov 2026 12:37:44 +0800 Subject: [PATCH 3/5] fix(release): a failed nightly check ships the net8.0 zip alone, with a warning --- .github/workflows/build.yml | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3cece30e..db2a881e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -53,6 +53,7 @@ jobs: plugin_input_format: ${{ steps.git_info.outputs.plugin_input_format }} commit_messages: ${{ steps.git_info.outputs.commit_messages }} package_names: ${{ steps.nightly.outputs.package_names }} + nightly_framework: ${{ steps.nightly.outputs.nightly_framework }} steps: - name: Checkout with submodules uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 @@ -408,6 +409,7 @@ jobs: - name: Check against Lidarr nightly and package for its runtime # Compiling against ext/Lidarr cannot catch a member Lidarr 4.0 removed (v1.39.11); PluginCheck lists such refs. + # A failed check still ships the $FRAMEWORK zip, so a servarr outage or a nightly break never blocks the plugins branch. id: nightly env: PACKAGE_NAME: ${{ steps.package.outputs.package_name }} @@ -422,11 +424,18 @@ jobs: STAGE=$(mktemp -d) unzip -q "$GITHUB_WORKSPACE/$PACKAGE_NAME" -d "$STAGE" - bash tools/PluginCheck/check-nightly.sh "$STAGE/Lidarr.Plugin.$PLUGIN_NAME.dll" "$LIDARR_NIGHTLY_FRAMEWORK" - - NIGHTLY_NAME="${PLUGIN_NAME}-v${VERSION}.${LIDARR_NIGHTLY_FRAMEWORK}.zip" - cp "$GITHUB_WORKSPACE/$PACKAGE_NAME" "$GITHUB_WORKSPACE/$NIGHTLY_NAME" - { echo "package_names<> "$GITHUB_OUTPUT" + NAMES=("$PACKAGE_NAME") + SHIPPED="" + if bash tools/PluginCheck/check-nightly.sh "$STAGE/Lidarr.Plugin.$PLUGIN_NAME.dll" "$LIDARR_NIGHTLY_FRAMEWORK"; then + NIGHTLY_NAME="${PLUGIN_NAME}-v${VERSION}.${LIDARR_NIGHTLY_FRAMEWORK}.zip" + cp "$GITHUB_WORKSPACE/$PACKAGE_NAME" "$GITHUB_WORKSPACE/$NIGHTLY_NAME" + NAMES+=("$NIGHTLY_NAME") + SHIPPED=$LIDARR_NIGHTLY_FRAMEWORK + else + echo "::warning::The Lidarr nightly check failed (see above), so this release ships only the $FRAMEWORK zip: Lidarr on $LIDARR_NIGHTLY_FRAMEWORK cannot install or update to it" + fi + echo "nightly_framework=$SHIPPED" >> "$GITHUB_OUTPUT" + { echo "package_names<> "$GITHUB_OUTPUT" - name: Upload plugin package uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7 @@ -493,7 +502,13 @@ jobs: COMMIT: ${{ needs.build.outputs.git_commit }} PLUGIN_INPUT: ${{ needs.build.outputs.plugin_input_format }} COMMITS: ${{ needs.build.outputs.commit_messages }} + NIGHTLY: ${{ needs.build.outputs.nightly_framework }} run: | + DOTNET_LINE=$FRAMEWORK + if [ -n "$NIGHTLY" ]; then + DOTNET_LINE="$FRAMEWORK, also as $NIGHTLY (checked against Lidarr's nightly)" + fi + cat > release_notes.md << EOL ## 📝 What's New: @@ -509,7 +524,7 @@ jobs: ## 📦 Package Information **Version:** $VERSION - **.NET Version:** $FRAMEWORK, also as $LIDARR_NIGHTLY_FRAMEWORK (checked against Lidarr's nightly) + **.NET Version:** $DOTNET_LINE **Minimum Lidarr Version:** $MIN_LIDARR **Commit:** $COMMIT EOL From 05bf6da93f4fde0555b61f8902e050df96a5def8 Mon Sep 17 00:00:00 2001 From: chodeus <190988615+chodeus@users.noreply.github.com> Date: Wed, 18 Nov 2026 13:03:52 +0800 Subject: [PATCH 4/5] fix(release): PluginCheck checks overrides, every library Lidarr ships and deeper Lidarr bases An override whose Lidarr base changed signature, a removed member of a library Lidarr provides (NLog, FluentValidation, the BCL), an abstract member of a second-level Lidarr base, or a same-named non-virtual method now count as problems. A missing Lidarr assembly is listed instead of crashing the tool, and stale Lidarr copies beside a CI build no longer stand in for it. --- tools/PluginCheck/Checker.cs | 135 ++++++++++++++++++++++++----------- tools/PluginCheck/Program.cs | 6 +- 2 files changed, 97 insertions(+), 44 deletions(-) diff --git a/tools/PluginCheck/Checker.cs b/tools/PluginCheck/Checker.cs index c6cb9a8d..caf163a8 100644 --- a/tools/PluginCheck/Checker.cs +++ b/tools/PluginCheck/Checker.cs @@ -6,14 +6,17 @@ public sealed class Checker { private readonly ModuleDefinition _module; private readonly string _self; + private readonly string _lib; private readonly SortedSet _problems = new(StringComparer.Ordinal); + // The plugin's folder is not searched: a CI build keeps net8 Lidarr copies there that would hide an assembly the build lacks public Checker(string plugin, string lib) { + _lib = lib; var resolver = new DefaultAssemblyResolver(); + resolver.RemoveSearchDirectory("."); + resolver.RemoveSearchDirectory("bin"); resolver.AddSearchDirectory(lib); - resolver.AddSearchDirectory(Path.GetDirectoryName(Path.GetFullPath(plugin))); - resolver.AddSearchDirectory(System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory()); _module = ModuleDefinition.ReadModule(plugin, new ReaderParameters { AssemblyResolver = resolver }); _self = _module.Assembly.Name.Name; } @@ -21,34 +24,36 @@ public Checker(string plugin, string lib) public int TypeRefs { get; private set; } public int MemberRefs { get; private set; } public int RequiredMembers { get; private set; } + public int Overrides { get; private set; } public IReadOnlyCollection Run() { CheckTypeRefs(); CheckMemberRefs(); CheckImplementations(); + CheckOverrides(); return _problems; } private void CheckTypeRefs() { - foreach (var tr in _module.GetTypeReferences().Where(t => IsLidarr(Outer(t).Scope))) + foreach (var tr in _module.GetTypeReferences().Where(t => IsHost(t.Scope))) { TypeRefs++; - if (tr.Resolve() == null) + if (ResolveType(tr) == null) { - _problems.Add($"missing type {tr.FullName} ({Outer(tr).Scope.Name})"); + _problems.Add($"missing type {tr.FullName} ({tr.Scope.Name})"); } } } + // Array members are made by the runtime, so they never resolve private void CheckMemberRefs() { - foreach (var mr in _module.GetMemberReferences().Where(m => IsLidarr(Outer(Element(m.DeclaringType)).Scope))) + foreach (var mr in _module.GetMemberReferences().Where(m => m.DeclaringType is not ArrayType && IsHost(m.DeclaringType.Scope))) { MemberRefs++; - var resolved = mr switch { MethodReference m => (IMemberDefinition)m.Resolve(), FieldReference f => f.Resolve(), _ => null }; - if (resolved == null) + if (ResolveMember(mr) == null) { _problems.Add($"missing member {mr.FullName}"); } @@ -59,10 +64,12 @@ private void CheckImplementations() { foreach (var type in AllTypes(_module.Types).Where(t => !t.IsInterface && !t.IsAbstract)) { - foreach (var method in RequiredMethods(type)) + var interfaces = new List(); + CollectInterfaces(type, interfaces); + foreach (var method in RequiredMethods(type, interfaces)) { RequiredMembers++; - if (!Implements(type, method)) + if (!Implements(type, interfaces, method)) { _problems.Add($"unimplemented {type.FullName} lacks {method.FullName}"); } @@ -70,63 +77,96 @@ private void CheckImplementations() } } - private IEnumerable RequiredMethods(TypeDefinition type) + // An override whose base member changed signature becomes a new member the host never calls; explicit overrides are member refs + private void CheckOverrides() { - var required = new List(); - for (var b = type.BaseType; b != null && Element(b).Resolve() is TypeDefinition bd; b = bd.BaseType) + foreach (var type in AllTypes(_module.Types).Where(t => !t.IsInterface)) { - if (IsLidarr(Outer(Element(b)).Scope)) + foreach (var method in type.Methods.Where(m => m.IsVirtual && !m.IsNewSlot && !m.HasOverrides)) { - required.Add(bd); + Overrides++; + if (Overridden(type, method) == false) + { + _problems.Add($"not overriding {method.FullName}"); + } + } + } + } + + private IEnumerable RequiredMethods(TypeDefinition type, List interfaces) + { + var required = interfaces.Where(i => IsHost(i)).ToList(); + for (var b = ResolveType(type.BaseType); b != null; b = ResolveType(b.BaseType)) + { + if (IsHost(b)) + { + required.Add(b); } } - CollectInterfaces(type, required); return required.SelectMany(t => t.Methods).Where(m => m.IsAbstract && !m.IsStatic).Distinct(); } - private void CollectInterfaces(TypeDefinition t, List into) + private static void CollectInterfaces(TypeDefinition t, List into) { - if (t == null) + for (; t != null; t = ResolveType(t.BaseType)) { - return; + foreach (var d in t.Interfaces.Select(i => ResolveType(i.InterfaceType)).Where(d => d != null && !into.Contains(d))) + { + into.Add(d); + CollectInterfaces(d, into); + } } + } + + // Host: Lidarr's own assemblies, even ones the build dropped, and every library in its bin dir + private bool IsHost(string assembly) => + assembly != _self && (assembly.StartsWith("Lidarr.", StringComparison.Ordinal) || File.Exists(Path.Combine(_lib, assembly + ".dll"))); + + private bool IsHost(IMetadataScope scope) => scope is AssemblyNameReference a && IsHost(a.Name); + + private bool IsHost(TypeDefinition t) => IsHost(t.Module.Assembly.Name.Name); - foreach (var i in t.Interfaces) + // An interface member is met by any virtual method of its name and signature or by an interface's default; a class member only by an override + private static bool Implements(TypeDefinition type, List interfaces, MethodDefinition required) + { + var isInterface = required.DeclaringType.IsInterface; + for (var t = type; t != null; t = ResolveType(t.BaseType)) { - var d = Element(i.InterfaceType).Resolve(); - if (d == null) + if (t.Methods.Any(m => m.IsVirtual && !m.IsAbstract && (isInterface || !m.IsNewSlot) && m.Name == required.Name && SameSignature(m, required))) { - continue; + return true; } - if (IsLidarr(Outer(Element(i.InterfaceType)).Scope)) + if (t.Methods.Any(m => ExplicitlyOverrides(m, required))) { - into.Add(d); + return true; } - - CollectInterfaces(d, into); } - CollectInterfaces(t.BaseType == null ? null : Element(t.BaseType).Resolve(), into); + return isInterface && interfaces.Any(i => i.Methods.Any(m => !m.IsAbstract && ExplicitlyOverrides(m, required))); } - private bool IsLidarr(IMetadataScope scope) => - scope is AssemblyNameReference a && a.Name.StartsWith("Lidarr.", StringComparison.Ordinal) && a.Name != _self; + private static bool ExplicitlyOverrides(MethodDefinition m, MethodDefinition required) => + m.Overrides.Any(o => o.Name == required.Name && o.DeclaringType.GetElementType().FullName == required.DeclaringType.FullName && SameSignature(o, required)); - private static bool Implements(TypeDefinition type, MethodDefinition required) + // null when a base can't be read; a plugin type's own base the build lacks is reported by CheckTypeRefs + private static bool? Overridden(TypeDefinition type, MethodDefinition method) { - for (var t = type; t != null; t = t.BaseType?.Resolve()) + for (var b = type.BaseType; b != null;) { - if (t.Methods.Any(m => !m.IsAbstract && (m.Name == required.Name || m.Name.EndsWith("." + required.Name, StringComparison.Ordinal)) && SameSignature(m, required))) + var bd = ResolveType(b); + if (bd == null) { - return true; + return null; } - if (t.Methods.Any(m => m.Overrides.Any(o => o.Name == required.Name && SameSignature(o, required)))) + if (bd.Methods.Any(m => m.IsVirtual && m.Name == method.Name && SameSignature(m, method))) { return true; } + + b = bd.BaseType; } return false; @@ -167,16 +207,29 @@ private static bool SameType(TypeReference a, TypeReference b) private static IEnumerable AllTypes(IEnumerable ts) => ts.SelectMany(t => new[] { t }.Concat(AllTypes(t.NestedTypes))); - private static TypeReference Outer(TypeReference t) + // Cecil throws, rather than returning null, when the assembly itself is missing + private static TypeDefinition ResolveType(TypeReference t) { - while (t.DeclaringType != null) + try { - t = t.DeclaringType; + return t?.GetElementType().Resolve(); + } + catch (AssemblyResolutionException) + { + return null; } - - return t; } - private static TypeReference Element(TypeReference t) => t is TypeSpecification s ? Element(s.ElementType) : t; + private static IMemberDefinition ResolveMember(MemberReference m) + { + try + { + return m switch { MethodReference r => r.Resolve(), FieldReference f => f.Resolve(), _ => null }; + } + catch (AssemblyResolutionException) + { + return null; + } + } } } diff --git a/tools/PluginCheck/Program.cs b/tools/PluginCheck/Program.cs index 771b044f..e72c6ece 100644 --- a/tools/PluginCheck/Program.cs +++ b/tools/PluginCheck/Program.cs @@ -1,7 +1,7 @@ using Sleezer.PluginCheck; -// Usage: Sleezer.PluginCheck . Lists each Lidarr type or member the plugin uses that the build lacks, -// and each Lidarr interface or abstract member a plugin type no longer implements (Checker.SameType says what a signature match is). +// Usage: Sleezer.PluginCheck . Lists each type or member the plugin uses from Lidarr's bin dir that the build lacks, +// each host abstract member a plugin type no longer implements, and each override left with no base member (see Checker.SameType). if (args.Length < 2) { Console.Error.WriteLine("Usage: Sleezer.PluginCheck "); @@ -11,7 +11,7 @@ var checker = new Checker(args[0], args[1]); var problems = checker.Run(); -Console.WriteLine($"checked {checker.TypeRefs} Lidarr type refs, {checker.MemberRefs} member refs, {checker.RequiredMembers} required members against {args[1]}"); +Console.WriteLine($"checked {checker.TypeRefs} host type refs, {checker.MemberRefs} member refs, {checker.RequiredMembers} required members, {checker.Overrides} overrides against {args[1]}"); foreach (var p in problems) { Console.WriteLine(p); From baf03ad7be707f98a561d8a4100b31ca302fc9f6 Mon Sep 17 00:00:00 2001 From: chodeus <190988615+chodeus@users.noreply.github.com> Date: Wed, 18 Nov 2026 13:15:23 +0800 Subject: [PATCH 5/5] fix(ci): check the plugin where the CI build writes it ci.yml builds without -f, so Directory.Build.props puts the plugin in _plugins/Sleezer/, not _plugins/net8.0/Sleezer/ as in build.yml. --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cab262d4..3e822bc0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -83,8 +83,9 @@ jobs: dotnet test tests/${PLUGIN_NAME}.Tests/${PLUGIN_NAME}.Tests.csproj \ -c Release -p:NuGetAudit=false + # Built without -f, so the plugin lands in _plugins//, not _plugins/// as in build.yml - name: Check against Lidarr nightly - run: bash tools/PluginCheck/check-nightly.sh "_plugins/net8.0/${PLUGIN_NAME}/Lidarr.Plugin.${PLUGIN_NAME}.dll" + run: bash tools/PluginCheck/check-nightly.sh "_plugins/${PLUGIN_NAME}/Lidarr.Plugin.${PLUGIN_NAME}.dll" dependency-audit: runs-on: ubuntu-latest