mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 09:11:10 +00:00
Adds bundled plugin trust and cross-platform native deployment
- embeds the append-only historical and deny trust lists in the API and marks matching bundled plugins as Official without blocking loading - builds and records the current plugin manifest only for official release builds - deploys the PDF native libraries for the supported Linux, macOS and Windows runtimes from the plugin dependency manifest - records release hashes by appending only missing entries to master's manifest and rejects any diff that removes a line - documents the release flow, the supported runtimes and the plugin installer limits
This commit is contained in:
1 parent
3fb8912c7f
commit
b30cbd6b9e
114 files changed
+2708
-243
No files matched your search
+190
@@ -0,0 +1,190 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
#endregion
|
||||
|
||||
namespace Nemera.Presentation.Api.IntegrationTests.Common.Setup;
|
||||
|
||||
/// <summary>
|
||||
/// Locates the files and directories used by the bundled plugin manifest tests.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The tests run from a configuration and target framework folder under bin/tests, so the repository root is found by walking up to the solution instead of hardcoding a machine-specific path.
|
||||
/// </remarks>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public static class BundledPluginManifestTestPaths
|
||||
{
|
||||
/// <summary>
|
||||
/// The name of the directory that holds the build scripts.
|
||||
/// </summary>
|
||||
public const string BUILD_DIRECTORY_NAME = "build";
|
||||
|
||||
/// <summary>
|
||||
/// The name of the directory that holds the build outputs.
|
||||
/// </summary>
|
||||
public const string BIN_DIRECTORY_NAME = "bin";
|
||||
|
||||
/// <summary>
|
||||
/// The name of the directory that holds the solution.
|
||||
/// </summary>
|
||||
public const string SOLUTION_DIRECTORY_NAME = "src";
|
||||
|
||||
/// <summary>
|
||||
/// The file name of the solution.
|
||||
/// </summary>
|
||||
public const string SOLUTION_FILE_NAME = "Nemera.slnx";
|
||||
|
||||
/// <summary>
|
||||
/// The name of the append-only bundled plugin trust manifest.
|
||||
/// </summary>
|
||||
public const string BUNDLED_PLUGINS_MANIFEST_FILE_NAME = "BundledPlugins.manifest";
|
||||
|
||||
/// <summary>
|
||||
/// The name of the bundled plugin revocation manifest.
|
||||
/// </summary>
|
||||
public const string BUNDLED_PLUGINS_DENY_MANIFEST_FILE_NAME = "BundledPlugins.deny.manifest";
|
||||
|
||||
/// <summary>
|
||||
/// The name of the bundled plugin release catalog.
|
||||
/// </summary>
|
||||
public const string BUNDLED_PLUGINS_PROPS_FILE_NAME = "BundledPlugins.props";
|
||||
|
||||
/// <summary>
|
||||
/// The name of the directory that holds the plugin projects.
|
||||
/// </summary>
|
||||
public const string PLUGINS_PROJECT_DIRECTORY_NAME = "plugins";
|
||||
|
||||
/// <summary>
|
||||
/// The name of the API output directory under the repository bin directory.
|
||||
/// </summary>
|
||||
public const string API_OUTPUT_DIRECTORY_NAME = "api";
|
||||
|
||||
/// <summary>
|
||||
/// The name of the directory that holds the deployed plugin assemblies.
|
||||
/// </summary>
|
||||
public const string PLUGINS_DIRECTORY_NAME = "plugins";
|
||||
|
||||
/// <summary>
|
||||
/// The file name of the published API assembly.
|
||||
/// </summary>
|
||||
public const string PUBLISHED_API_ASSEMBLY_FILE_NAME = "Nemera.Presentation.Api.dll";
|
||||
|
||||
/// <summary>
|
||||
/// The search pattern of the bundled plugin assemblies.
|
||||
/// </summary>
|
||||
public const string PLUGIN_ASSEMBLY_SEARCH_PATTERN = "Nemera.Plugins.*.dll";
|
||||
|
||||
/// <summary>
|
||||
/// The search pattern of the plugin project files.
|
||||
/// </summary>
|
||||
public const string PLUGIN_PROJECT_SEARCH_PATTERN = "*.csproj";
|
||||
|
||||
/// <summary>
|
||||
/// The extension of the bundled plugin assemblies.
|
||||
/// </summary>
|
||||
public const string PLUGIN_ASSEMBLY_EXTENSION = ".dll";
|
||||
|
||||
/// <summary>
|
||||
/// Locates the repository root from the test output directory.
|
||||
/// </summary>
|
||||
/// <returns>The absolute path of the repository root.</returns>
|
||||
public static string GetRepositoryRoot()
|
||||
{
|
||||
// Walk up from the test output directory until the solution file is found. This works regardless of how many folders the output is nested under bin.
|
||||
DirectoryInfo? directory = new(AppContext.BaseDirectory);
|
||||
while (directory is not null)
|
||||
{
|
||||
if (File.Exists(Path.Combine(directory.FullName, SOLUTION_DIRECTORY_NAME, SOLUTION_FILE_NAME)))
|
||||
return directory.FullName;
|
||||
directory = directory.Parent;
|
||||
}
|
||||
throw new InvalidOperationException("The repository root could not be located from the test output directory.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Locates the append-only bundled plugin trust manifest.
|
||||
/// </summary>
|
||||
/// <param name="repositoryRoot">The absolute path of the repository root.</param>
|
||||
/// <returns>The absolute path of the trust manifest.</returns>
|
||||
public static string GetBundledPluginsManifestPath(string repositoryRoot)
|
||||
{
|
||||
return Path.Combine(repositoryRoot, BUILD_DIRECTORY_NAME, BUNDLED_PLUGINS_MANIFEST_FILE_NAME);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Locates the bundled plugin revocation manifest.
|
||||
/// </summary>
|
||||
/// <param name="repositoryRoot">The absolute path of the repository root.</param>
|
||||
/// <returns>The absolute path of the revocation manifest.</returns>
|
||||
public static string GetBundledPluginsDenyManifestPath(string repositoryRoot)
|
||||
{
|
||||
return Path.Combine(repositoryRoot, BUILD_DIRECTORY_NAME, BUNDLED_PLUGINS_DENY_MANIFEST_FILE_NAME);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Locates the bundled plugin release catalog.
|
||||
/// </summary>
|
||||
/// <param name="repositoryRoot">The absolute path of the repository root.</param>
|
||||
/// <returns>The absolute path of the release catalog.</returns>
|
||||
public static string GetBundledPluginsPropsPath(string repositoryRoot)
|
||||
{
|
||||
return Path.Combine(repositoryRoot, BUILD_DIRECTORY_NAME, BUNDLED_PLUGINS_PROPS_FILE_NAME);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Locates the solution file.
|
||||
/// </summary>
|
||||
/// <param name="repositoryRoot">The absolute path of the repository root.</param>
|
||||
/// <returns>The absolute path of the solution file.</returns>
|
||||
public static string GetSolutionPath(string repositoryRoot)
|
||||
{
|
||||
return Path.Combine(repositoryRoot, SOLUTION_DIRECTORY_NAME, SOLUTION_FILE_NAME);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Locates the directory that holds the plugin projects.
|
||||
/// </summary>
|
||||
/// <param name="repositoryRoot">The absolute path of the repository root.</param>
|
||||
/// <returns>The absolute path of the plugin project directory.</returns>
|
||||
public static string GetPluginsProjectDirectory(string repositoryRoot)
|
||||
{
|
||||
return Path.Combine(repositoryRoot, PLUGINS_PROJECT_DIRECTORY_NAME);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Locates the plugins directory of the API build output for the current test configuration.
|
||||
/// </summary>
|
||||
/// <param name="repositoryRoot">The absolute path of the repository root.</param>
|
||||
/// <returns>The absolute path of the deployed plugins directory, whether or not it exists.</returns>
|
||||
public static string GetDeployedPluginsDirectory(string repositoryRoot)
|
||||
{
|
||||
// The test output folder is bin/tests/<project>/<configuration>/<target-framework>, so its parent names the configuration
|
||||
// and its own name is the target framework. The API output mirrors that layout under bin/api.
|
||||
DirectoryInfo testOutputDirectory = new(AppContext.BaseDirectory);
|
||||
string configuration = testOutputDirectory.Parent?.Name
|
||||
?? throw new InvalidOperationException("The test configuration could not be determined from the test output directory.");
|
||||
string targetFramework = testOutputDirectory.Name;
|
||||
return Path.Combine(repositoryRoot, BIN_DIRECTORY_NAME, API_OUTPUT_DIRECTORY_NAME, configuration, targetFramework, PLUGINS_DIRECTORY_NAME);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Locates the published API assembly in the publish output directory.
|
||||
/// </summary>
|
||||
/// <param name="publishDirectory">The absolute path of the publish output directory.</param>
|
||||
/// <returns>The absolute path of the published API assembly.</returns>
|
||||
public static string GetPublishedApiAssemblyPath(string publishDirectory)
|
||||
{
|
||||
return Path.Combine(publishDirectory, PUBLISHED_API_ASSEMBLY_FILE_NAME);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Locates the published plugins directory in the publish output directory.
|
||||
/// </summary>
|
||||
/// <param name="publishDirectory">The absolute path of the publish output directory.</param>
|
||||
/// <returns>The absolute path of the published plugins directory.</returns>
|
||||
public static string GetPublishedPluginsDirectory(string publishDirectory)
|
||||
{
|
||||
return Path.Combine(publishDirectory, PLUGINS_DIRECTORY_NAME);
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
#endregion
|
||||
|
||||
namespace Nemera.Presentation.Api.IntegrationTests.Common.Setup;
|
||||
|
||||
/// <summary>
|
||||
/// Marks a test that only runs when the API assembly was produced by an official release build and the deployed bundled plugins are present.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
[ExcludeFromCodeCoverage]
|
||||
public sealed class DeployedBundledPluginsFactAttribute : FactAttribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the reason to skip the test. If set, the test will be skipped instead of executed.
|
||||
/// </summary>
|
||||
public override string Skip
|
||||
{
|
||||
get
|
||||
{
|
||||
// xUnit evaluates Skip during discovery. Missing deployed plugins mean the solution was not built, which is normal locally,
|
||||
// so the test is skipped with a reason instead of failing.
|
||||
if (!OfficialReleaseBuildDetector.IsOfficialReleaseBuild())
|
||||
return "The API assembly was not produced by an official release build.";
|
||||
try
|
||||
{
|
||||
string repositoryRoot = BundledPluginManifestTestPaths.GetRepositoryRoot();
|
||||
string pluginsDirectory = BundledPluginManifestTestPaths.GetDeployedPluginsDirectory(repositoryRoot);
|
||||
// The deployed folder is produced by the solution build. If it is missing or empty there is no artifact to verify,
|
||||
// so the test is skipped and the reason points at the path that was expected.
|
||||
if (!Directory.Exists(pluginsDirectory))
|
||||
return $"The deployed bundled plugins directory '{pluginsDirectory}' does not exist.";
|
||||
if (!Directory.EnumerateFiles(pluginsDirectory, BundledPluginManifestTestPaths.PLUGIN_ASSEMBLY_SEARCH_PATTERN).Any())
|
||||
return $"The deployed bundled plugins directory '{pluginsDirectory}' does not contain any bundled plugin assemblies.";
|
||||
return string.Empty;
|
||||
}
|
||||
catch (InvalidOperationException exception)
|
||||
{
|
||||
return exception.Message;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Xunit;
|
||||
#endregion
|
||||
|
||||
namespace Nemera.Presentation.Api.IntegrationTests.Common.Setup;
|
||||
|
||||
/// <summary>
|
||||
/// Marks a test that only runs when the named environment variable is set.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
[ExcludeFromCodeCoverage]
|
||||
public sealed class EnvironmentVariableFactAttribute : FactAttribute
|
||||
{
|
||||
/// <summary>
|
||||
/// The name of the environment variable that must be set for the test to run.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The name is stored because Skip is evaluated later, during test discovery.
|
||||
/// </remarks>
|
||||
private readonly string _environmentVariableName;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="EnvironmentVariableFactAttribute"/> class.
|
||||
/// </summary>
|
||||
/// <param name="environmentVariableName">The name of the environment variable that must be set for the test to run.</param>
|
||||
public EnvironmentVariableFactAttribute(string environmentVariableName)
|
||||
{
|
||||
_environmentVariableName = environmentVariableName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the reason to skip the test. If set, the test will be skipped instead of executed.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The published-artifact verification is opt-in: build/build.proj sets the variable only when it checks a publish output. Without it, the test would inspect a directory that does not exist, so it is skipped with a reason instead.
|
||||
/// </remarks>
|
||||
public override string Skip => string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(_environmentVariableName))
|
||||
? $"The environment variable '{_environmentVariableName}' is not set."
|
||||
: string.Empty;
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Nemera.Presentation.Api;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
#endregion
|
||||
|
||||
namespace Nemera.Presentation.Api.IntegrationTests.Common.Setup;
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the API assembly was produced by an official release build.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public static class OfficialReleaseBuildDetector
|
||||
{
|
||||
/// <summary>
|
||||
/// Determines whether the API assembly was produced by an official release build.
|
||||
/// </summary>
|
||||
/// <returns><see langword="true"/> when the assembly carries the official release marker, <see langword="false"/> otherwise.</returns>
|
||||
public static bool IsOfficialReleaseBuild()
|
||||
{
|
||||
// The marker is injected by OfficialReleaseBuildAssemblyInfo.cs when the official build defines OFFICIAL_RELEASE_BUILD.
|
||||
// The tests inspect Program's assembly rather than their own, because the test assembly is not the shipped API assembly.
|
||||
return typeof(Program).Assembly
|
||||
.GetCustomAttributes<AssemblyMetadataAttribute>()
|
||||
.Any(attribute => attribute.Key == "OfficialReleaseBuild" && attribute.Value == "true");
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Xunit;
|
||||
#endregion
|
||||
|
||||
namespace Nemera.Presentation.Api.IntegrationTests.Common.Setup;
|
||||
|
||||
/// <summary>
|
||||
/// Marks a test that only runs when the API assembly was produced by an official release build.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
[ExcludeFromCodeCoverage]
|
||||
public sealed class OfficialReleaseFactAttribute : FactAttribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the reason to skip the test. If set, the test will be skipped instead of executed.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// xUnit evaluates Skip during test discovery, so the attribute decides at runtime whether the test runs. A normal test run skips official-only tests instead of failing them.
|
||||
/// </remarks>
|
||||
public override string Skip => OfficialReleaseBuildDetector.IsOfficialReleaseBuild()
|
||||
? string.Empty
|
||||
: "The API assembly was not produced by an official release build.";
|
||||
}
|
||||
Reference in new issue
Block a user