mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 18:57:24 +00:00
Merge pull request #310 from BinaryAlley/feature/per-platform-release-artifacts
Adds per-platform release artifacts and fixes fresh theme activation
This commit is contained in:
23 files changed
+748
-189
No files matched your search
@@ -45,7 +45,16 @@ jobs:
|
||||
env:
|
||||
SixLaborsLicenseKey: ${{ secrets.SIXLABORS_LICENSE_KEY }}
|
||||
RELEASE_BRANCH: ${{ github.ref_name }}
|
||||
run: dotnet msbuild build/build.proj -t:RecordBundledPlugins -p:Configuration=Release -p:OfficialReleaseBuild=true -p:AllowBundledPluginsRecording=true -p:ReleaseBranch="$RELEASE_BRANCH"
|
||||
run: |
|
||||
release_version="${RELEASE_BRANCH#release/}"
|
||||
dotnet msbuild build/build.proj -t:RecordBundledPlugins -p:Configuration=Release -p:OfficialReleaseBuild=true -p:AllowBundledPluginsRecording=true -p:ReleaseBranch="$RELEASE_BRANCH" -p:Version="$release_version"
|
||||
# Upload the verified archives before the image step, so a Docker failure does not discard successfully built archives.
|
||||
- name: Upload release archives
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: release-archives
|
||||
path: bin/release/*
|
||||
if-no-files-found: error
|
||||
# Reuse the verified publish output, so the images contain exactly the plugin binaries whose hashes were recorded.
|
||||
- name: Build release images
|
||||
env:
|
||||
@@ -53,18 +62,6 @@ jobs:
|
||||
run: |
|
||||
release_version="${RELEASE_BRANCH#release/}"
|
||||
dotnet msbuild build/build.proj -t:Docker -p:Configuration=Release -p:OfficialReleaseBuild=true -p:ReusePublishedBundledPlugins=true -p:Version="$release_version"
|
||||
- name: Upload release server files
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: release-api
|
||||
path: bin/api/publish
|
||||
if-no-files-found: error
|
||||
- name: Upload release web files
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: release-web
|
||||
path: bin/web/publish
|
||||
if-no-files-found: error
|
||||
- name: Upload bundled plugin manifest
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
<Project>
|
||||
<!-- The runtime identifiers the release supports and the archive name for each one. The PDF plugin native validation, the publish loop, verification and archive naming all read this single item list. -->
|
||||
<ItemGroup>
|
||||
<BundledPluginRuntime Include="win-x64">
|
||||
<ReleaseArchiveStem>windows-x64</ReleaseArchiveStem>
|
||||
<ReleaseArchiveExtension>.zip</ReleaseArchiveExtension>
|
||||
</BundledPluginRuntime>
|
||||
<BundledPluginRuntime Include="win-x86">
|
||||
<ReleaseArchiveStem>windows-x86</ReleaseArchiveStem>
|
||||
<ReleaseArchiveExtension>.zip</ReleaseArchiveExtension>
|
||||
</BundledPluginRuntime>
|
||||
<BundledPluginRuntime Include="win-arm64">
|
||||
<ReleaseArchiveStem>windows-arm64</ReleaseArchiveStem>
|
||||
<ReleaseArchiveExtension>.zip</ReleaseArchiveExtension>
|
||||
</BundledPluginRuntime>
|
||||
<BundledPluginRuntime Include="linux-x64">
|
||||
<ReleaseArchiveStem>linux-x64</ReleaseArchiveStem>
|
||||
<ReleaseArchiveExtension>.tar.gz</ReleaseArchiveExtension>
|
||||
</BundledPluginRuntime>
|
||||
<BundledPluginRuntime Include="linux-arm64">
|
||||
<ReleaseArchiveStem>linux-arm64</ReleaseArchiveStem>
|
||||
<ReleaseArchiveExtension>.tar.gz</ReleaseArchiveExtension>
|
||||
</BundledPluginRuntime>
|
||||
<BundledPluginRuntime Include="linux-musl-x64">
|
||||
<ReleaseArchiveStem>linux-musl-x64</ReleaseArchiveStem>
|
||||
<ReleaseArchiveExtension>.tar.gz</ReleaseArchiveExtension>
|
||||
</BundledPluginRuntime>
|
||||
<BundledPluginRuntime Include="osx-x64">
|
||||
<ReleaseArchiveStem>macos-x64</ReleaseArchiveStem>
|
||||
<ReleaseArchiveExtension>.tar.gz</ReleaseArchiveExtension>
|
||||
</BundledPluginRuntime>
|
||||
<BundledPluginRuntime Include="osx-arm64">
|
||||
<ReleaseArchiveStem>macos-arm64</ReleaseArchiveStem>
|
||||
<ReleaseArchiveExtension>.tar.gz</ReleaseArchiveExtension>
|
||||
</BundledPluginRuntime>
|
||||
</ItemGroup>
|
||||
|
||||
<!-- The native runtime folders each release must contain. A shared family fallback is listed once per runtime that uses it. The list must match the folders the bundled plugins deploy: verification fails when a declared folder is missing from the staging folder or when the staging folder contains an undeclared folder. -->
|
||||
<ItemGroup>
|
||||
<BundledPluginRuntimeDirectory Include="win-x64" RuntimeIdentifier="win-x64" />
|
||||
<BundledPluginRuntimeDirectory Include="win-x86" RuntimeIdentifier="win-x86" />
|
||||
<BundledPluginRuntimeDirectory Include="win-arm64" RuntimeIdentifier="win-arm64" />
|
||||
<BundledPluginRuntimeDirectory Include="linux-x64" RuntimeIdentifier="linux-x64" />
|
||||
<BundledPluginRuntimeDirectory Include="linux-arm64" RuntimeIdentifier="linux-arm64" />
|
||||
<BundledPluginRuntimeDirectory Include="linux-musl-x64" RuntimeIdentifier="linux-musl-x64" />
|
||||
<BundledPluginRuntimeDirectory Include="osx-x64" RuntimeIdentifier="osx-x64" />
|
||||
<BundledPluginRuntimeDirectory Include="osx" RuntimeIdentifier="osx-x64" />
|
||||
<BundledPluginRuntimeDirectory Include="osx-arm64" RuntimeIdentifier="osx-arm64" />
|
||||
<BundledPluginRuntimeDirectory Include="osx" RuntimeIdentifier="osx-arm64" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
+343
-29
@@ -1,5 +1,6 @@
|
||||
<Project DefaultTargets="CI">
|
||||
<Import Project="$(MSBuildThisFileDirectory)BundledPlugins.props" />
|
||||
<Import Project="$(MSBuildThisFileDirectory)RuntimeIdentifiers.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<RepoRoot>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..'))</RepoRoot>
|
||||
@@ -7,14 +8,41 @@
|
||||
<Configuration Condition="'$(Configuration)' == ''">Debug</Configuration>
|
||||
<ApiPublishDirectory>$(RepoRoot)/bin/api/publish</ApiPublishDirectory>
|
||||
<WebPublishDirectory>$(RepoRoot)/bin/web/publish</WebPublishDirectory>
|
||||
<!-- The per-runtime archives that are attached to a GitHub release. -->
|
||||
<ReleaseArchivesDirectory>$(RepoRoot)/bin/release</ReleaseArchivesDirectory>
|
||||
<!-- Archive verification extracts into its own folder, outside the uploaded release root, so an interrupted verification cannot leak scratch files into the release archives artifact. -->
|
||||
<ReleaseArchiveVerificationDirectory>$(RepoRoot)/bin/release-verify</ReleaseArchiveVerificationDirectory>
|
||||
<ReleaseVersion Condition="'$(ReleaseVersion)' == ''">$(Version)</ReleaseVersion>
|
||||
<ReleaseVersion Condition="'$(ReleaseVersion)' == ''">0.0.0-dev</ReleaseVersion>
|
||||
<!-- The version is embedded in archive names and tar commands, so only a three-part version or the development default is accepted. -->
|
||||
<_ReleaseVersionPattern>^([0-9]+\.[0-9]+\.[0-9]+|0\.0\.0-dev)$</_ReleaseVersionPattern>
|
||||
<!-- The Docker image tag, which defaults to latest for local images. -->
|
||||
<_ImageVersion Condition="'$(Version)' != ''">$(Version)</_ImageVersion>
|
||||
<_ImageVersion Condition="'$(Version)' == ''">latest</_ImageVersion>
|
||||
<!-- The shared plugin staging folder is outside the release root, so it is never uploaded with the release. -->
|
||||
<BundledPluginsPublishDirectory>$(RepoRoot)/bin/api/bundled-plugins</BundledPluginsPublishDirectory>
|
||||
<!-- The runtime used for the Docker images and for the published manifest verification. -->
|
||||
<ApiReleaseRuntimeIdentifier Condition="'$(ApiReleaseRuntimeIdentifier)' == ''">linux-x64</ApiReleaseRuntimeIdentifier>
|
||||
<!-- Official images copy a published folder into a base image of the same architecture, so each glibc Linux runtime maps to its Docker platform. -->
|
||||
<_DockerPlatform Condition="'$(ApiReleaseRuntimeIdentifier)' == 'linux-x64'">linux/amd64</_DockerPlatform>
|
||||
<_DockerPlatform Condition="'$(ApiReleaseRuntimeIdentifier)' == 'linux-arm64'">linux/arm64</_DockerPlatform>
|
||||
<BundledPluginsCurrentManifest Condition="'$(BundledPluginsCurrentManifest)' == ''">$(RepoRoot)/bin/api/BundledPlugins.current.manifest</BundledPluginsCurrentManifest>
|
||||
<BundledPluginsSolution Condition="'$(BundledPluginsSolution)' == ''">$(MSBuildThisFileDirectory)obj/BundledPlugins.slnx</BundledPluginsSolution>
|
||||
<_OfficialReleaseBuild Condition="'$(OfficialReleaseBuild)' == ''">false</_OfficialReleaseBuild>
|
||||
<_OfficialReleaseBuild Condition="'$(OfficialReleaseBuild)' != ''">$(OfficialReleaseBuild)</_OfficialReleaseBuild>
|
||||
<_DockerDependsOn>Build</_DockerDependsOn>
|
||||
<_DockerDependsOn Condition="'$(_OfficialReleaseBuild)' == 'true'">ValidateDockerRelease;VerifyPublishedBundledPlugins</_DockerDependsOn>
|
||||
<!-- A reused publish output was verified by the preceding publish step, so verifying it again only repeats the work. -->
|
||||
<_DockerDependsOn Condition="'$(_OfficialReleaseBuild)' == 'true' And '$(ReusePublishedBundledPlugins)' == 'true'">ValidateDockerRelease</_DockerDependsOn>
|
||||
<!-- Local images build for the host so docker compose keeps working; only release images pin the platform of the published folder they copy. -->
|
||||
<_DockerPlatformOption Condition="'$(_OfficialReleaseBuild)' == 'true'">--platform "$(_DockerPlatform)" </_DockerPlatformOption>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Defined once because Publish and the verification targets run in the same project instance during RecordBundledPlugins. -->
|
||||
<ItemGroup>
|
||||
<_ReleaseRuntime Include="@(BundledPluginRuntime)" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="Restore">
|
||||
<Exec Command="dotnet restore "$(Solution)"" />
|
||||
<PropertyGroup>
|
||||
@@ -50,7 +78,7 @@
|
||||
</Target>
|
||||
|
||||
<Target Name="BuildBundledPlugins" DependsOnTargets="PrepareBundledPluginsSolution;RestoreBundledPlugins">
|
||||
<Exec Command="dotnet build "$(BundledPluginsSolution)" -c $(Configuration) --no-restore -p:NemeraPluginsOutputDirectory="$(NemeraPluginsOutputDirectory)"" WorkingDirectory="$(RepoRoot)" />
|
||||
<Exec Command="dotnet build "$(BundledPluginsSolution)" -c $(Configuration) --no-restore -p:NemeraPluginsOutputDirectory="$(NemeraPluginsOutputDirectory)" -p:OfficialReleaseBuild=$(_OfficialReleaseBuild)" WorkingDirectory="$(RepoRoot)" />
|
||||
</Target>
|
||||
|
||||
<!-- The first official build needs a current manifest file to embed. The real manifest is generated from the deployed plugins after the solution build. -->
|
||||
@@ -93,61 +121,347 @@
|
||||
<MSBuild Projects="$(MSBuildThisFileFullPath)" Targets="Publish" Condition="'$(ReusePublishedBundledPlugins)' != 'true' And '$(_PublishedBundledPlugins)' != 'true'" />
|
||||
</Target>
|
||||
|
||||
<!-- Verifies the manifest embedded in the published API assembly against the plugin binaries that were actually published. -->
|
||||
<Target Name="VerifyPublishedBundledPlugins" DependsOnTargets="EnsurePublishedBundledPlugins">
|
||||
<Error Condition="!Exists('$(ApiPublishDirectory)/Nemera.Presentation.Api.dll')" Text="The published API assembly is missing from '$(ApiPublishDirectory)'." />
|
||||
<Error Condition="!Exists('$(ApiPublishDirectory)/plugins')" Text="The published bundled plugins are missing from '$(ApiPublishDirectory)/plugins'." />
|
||||
<Exec Command="dotnet test "$(Solution)" -c $(Configuration) --no-build --filter "FullyQualifiedName~PublishedBundledPluginManifest"" EnvironmentVariables="NEMERA_API_PUBLISH_DIRECTORY=$(ApiPublishDirectory)" />
|
||||
<!-- The catalog is the source of truth, so the staging folder must contain exactly the native runtime folders it declares. This fails the build when a dependency starts or stops deploying a folder. -->
|
||||
<Target Name="VerifyStagingNativeRuntimeDirectories" DependsOnTargets="EnsurePublishedBundledPlugins">
|
||||
<ItemGroup>
|
||||
<_StagingNativeRuntimeDirectory Include="$([System.IO.Directory]::GetDirectories('$(BundledPluginsPublishDirectory)/runtimes'))" Condition="Exists('$(BundledPluginsPublishDirectory)/runtimes')" />
|
||||
<_DeclaredStagingNativeRuntimeDirectory Include="@(BundledPluginRuntimeDirectory->'$(BundledPluginsPublishDirectory)/runtimes/%(Identity)')" />
|
||||
</ItemGroup>
|
||||
<!-- A shared fallback folder is declared once per runtime that uses it, so deduplicate the expected list before it is reported. -->
|
||||
<RemoveDuplicates Inputs="@(_DeclaredStagingNativeRuntimeDirectory)">
|
||||
<Output TaskParameter="Filtered" ItemName="_ExpectedStagingNativeRuntimeDirectory" />
|
||||
</RemoveDuplicates>
|
||||
<ItemGroup>
|
||||
<_MissingStagingNativeRuntimeDirectory Include="@(_ExpectedStagingNativeRuntimeDirectory)" Condition="!Exists('%(FullPath)')" />
|
||||
<_UnexpectedStagingNativeRuntimeDirectory Include="@(_StagingNativeRuntimeDirectory)" Exclude="@(_ExpectedStagingNativeRuntimeDirectory)" />
|
||||
</ItemGroup>
|
||||
<Error Condition="'@(_MissingStagingNativeRuntimeDirectory)' != ''" Text="The bundled plugin staging folder is missing native runtime folders that build/RuntimeIdentifiers.props declares: @(_MissingStagingNativeRuntimeDirectory)" />
|
||||
<Error Condition="'@(_UnexpectedStagingNativeRuntimeDirectory)' != ''" Text="The bundled plugin staging folder contains native runtime folders that build/RuntimeIdentifiers.props does not declare: @(_UnexpectedStagingNativeRuntimeDirectory)" />
|
||||
</Target>
|
||||
|
||||
<!-- Verifies every published runtime folder: assemblies, apphosts, plugins, native folders and files, the embedded plugin manifest, and the plugin binaries that the trust list records. Archive checks live in VerifyReleaseArchives. -->
|
||||
<Target Name="VerifyPublishedBundledPlugins" DependsOnTargets="EnsurePublishedBundledPlugins;VerifyStagingNativeRuntimeDirectories">
|
||||
<PropertyGroup>
|
||||
<_ApiReleaseDirectory>$(ApiPublishDirectory)/$(ApiReleaseRuntimeIdentifier)</_ApiReleaseDirectory>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('$(_ApiReleaseDirectory)/Nemera.Presentation.Api.dll')" Text="The published API assembly is missing from '$(_ApiReleaseDirectory)'." />
|
||||
<Error Condition="!Exists('$(_ApiReleaseDirectory)/plugins')" Text="The published bundled plugins are missing from '$(_ApiReleaseDirectory)/plugins'." />
|
||||
<ItemGroup>
|
||||
<_WindowsReleaseRuntime Include="@(_ReleaseRuntime)" Condition="$([System.String]::Copy('%(Identity)').StartsWith('win-'))" />
|
||||
<_UnixReleaseRuntime Include="@(_ReleaseRuntime)" Condition="$([System.String]::Copy('%(Identity)').StartsWith('win-')) == false" />
|
||||
<_ReleaseApiPath Include="@(_ReleaseRuntime->'$(ApiPublishDirectory)/%(Identity)/Nemera.Presentation.Api.dll')" />
|
||||
<_ReleaseWebPath Include="@(_ReleaseRuntime->'$(WebPublishDirectory)/%(Identity)/Nemera.Presentation.Web.dll')" />
|
||||
<_ReleaseApiAppHostPath Include="@(_WindowsReleaseRuntime->'$(ApiPublishDirectory)/%(Identity)/Nemera.Presentation.Api.exe')" />
|
||||
<_ReleaseApiAppHostPath Include="@(_UnixReleaseRuntime->'$(ApiPublishDirectory)/%(Identity)/Nemera.Presentation.Api')" />
|
||||
<_ReleaseWebAppHostPath Include="@(_WindowsReleaseRuntime->'$(WebPublishDirectory)/%(Identity)/Nemera.Presentation.Web.exe')" />
|
||||
<_ReleaseWebAppHostPath Include="@(_UnixReleaseRuntime->'$(WebPublishDirectory)/%(Identity)/Nemera.Presentation.Web')" />
|
||||
<_MissingReleaseApi Include="@(_ReleaseApiPath)" Condition="!Exists('%(FullPath)')" />
|
||||
<_MissingReleaseWeb Include="@(_ReleaseWebPath)" Condition="!Exists('%(FullPath)')" />
|
||||
<_MissingReleaseApiAppHost Include="@(_ReleaseApiAppHostPath)" Condition="!Exists('%(FullPath)')" />
|
||||
<_MissingReleaseWebAppHost Include="@(_ReleaseWebAppHostPath)" Condition="!Exists('%(FullPath)')" />
|
||||
<_ReleaseNativeRuntimeMapping Include="@(BundledPluginRuntimeDirectory)" />
|
||||
<_ReleasePdb Include="$(ApiPublishDirectory)/**/*.pdb;$(WebPublishDirectory)/**/*.pdb" />
|
||||
</ItemGroup>
|
||||
<Error Condition="'@(_MissingReleaseApi)' != ''" Text="The release is missing the API assembly for these runtimes: @(_MissingReleaseApi)" />
|
||||
<Error Condition="'@(_MissingReleaseWeb)' != ''" Text="The release is missing the web assembly for these runtimes: @(_MissingReleaseWeb)" />
|
||||
<Error Condition="'@(_MissingReleaseApiAppHost)' != ''" Text="The release is missing the API executable for these runtimes: @(_MissingReleaseApiAppHost)" />
|
||||
<Error Condition="'@(_MissingReleaseWebAppHost)' != ''" Text="The release is missing the web executable for these runtimes: @(_MissingReleaseWebAppHost)" />
|
||||
<Error Condition="'@(_ReleasePdb)' != ''" Text="The release still contains PDB files: @(_ReleasePdb)" />
|
||||
<!-- Verify that every bundled plugin project has an assembly in every published runtime folder. -->
|
||||
<MSBuild Projects="$(MSBuildThisFileFullPath)" Targets="VerifyReleasePluginAssemblies" Properties="ApiPublishDirectory=$(ApiPublishDirectory);BundledPluginReleaseRuntimeIdentifier=%(_ReleaseRuntime.Identity)" />
|
||||
<!-- Verify the exact native runtime folders for every release, so a foreign OS or a foreign architecture of the same OS cannot pass. -->
|
||||
<MSBuild Projects="$(MSBuildThisFileFullPath)" Targets="VerifyReleaseRuntimeDirectories" Properties="ApiPublishDirectory=$(ApiPublishDirectory);BundledPluginsPublishDirectory=$(BundledPluginsPublishDirectory);BundledPluginReleaseRuntimeIdentifier=%(_ReleaseRuntime.Identity)" />
|
||||
<!-- Verify every declared native folder file by file, including the destination architecture and its fallback folders. -->
|
||||
<MSBuild Projects="$(MSBuildThisFileFullPath)" Targets="VerifyReleaseRuntimeNativeFiles" Properties="ApiPublishDirectory=$(ApiPublishDirectory);BundledPluginsPublishDirectory=$(BundledPluginsPublishDirectory);BundledPluginReleaseRuntimeIdentifier=%(_ReleaseNativeRuntimeMapping.RuntimeIdentifier);BundledPluginRuntimeDirectoryName=%(_ReleaseNativeRuntimeMapping.Identity)" />
|
||||
<!-- Verify the embedded manifest against every published API folder, not only the folder used by the Docker images. -->
|
||||
<Exec Command="dotnet test "$(RepoRoot)/tests/IntegrationTests/Nemera.Presentation.Api.IntegrationTests/Nemera.Presentation.Api.IntegrationTests.csproj" -c $(Configuration) --no-build --filter "FullyQualifiedName~PublishedBundledPluginManifest"" EnvironmentVariables="NEMERA_API_PUBLISH_DIRECTORY=$(ApiPublishDirectory)/%(_ReleaseRuntime.Identity)" />
|
||||
<!-- Every runtime folder must ship the same plugin binaries as the reference folder that the trust list records. -->
|
||||
<MSBuild Projects="$(MSBuildThisFileFullPath)" Targets="VerifyReleasePluginFiles" Properties="BundledPluginReleaseRuntimeIdentifier=%(_ReleaseRuntime.Identity);ReferencePluginsDirectory=$(ApiPublishDirectory)/$(ApiReleaseRuntimeIdentifier)/plugins;ReleasePluginsDirectory=$(ApiPublishDirectory)/%(_ReleaseRuntime.Identity)/plugins" />
|
||||
</Target>
|
||||
|
||||
<!-- The Linux and macOS archives keep their executable bit, so they must be created and verified on Linux or macOS. -->
|
||||
<Target Name="ValidateReleaseArchivesPlatform">
|
||||
<Error Condition="'$(OS)' == 'Windows_NT'" Text="Linux and macOS archives must be created and verified on Linux or macOS, because Windows cannot store the executable bit. Run this target on a non-Windows host." />
|
||||
</Target>
|
||||
|
||||
<!-- Verifies every platform archive, independently of the publish-folder checks, so Docker reuse does not require bin/release to exist. -->
|
||||
<Target Name="VerifyReleaseArchives" DependsOnTargets="ValidateReleaseArchivesPlatform;EnsurePublishedBundledPlugins;CreateReleaseArchives">
|
||||
<ItemGroup>
|
||||
<_ReleaseApiArchive Include="@(_ReleaseRuntime->'$(ReleaseArchivesDirectory)/Nemera-$(ReleaseVersion)-%(ReleaseArchiveStem)-api%(ReleaseArchiveExtension)')" />
|
||||
<_ReleaseWebArchive Include="@(_ReleaseRuntime->'$(ReleaseArchivesDirectory)/Nemera-$(ReleaseVersion)-%(ReleaseArchiveStem)-web%(ReleaseArchiveExtension)')" />
|
||||
<_MissingReleaseApiArchive Include="@(_ReleaseApiArchive)" Condition="!Exists('%(FullPath)')" />
|
||||
<_MissingReleaseWebArchive Include="@(_ReleaseWebArchive)" Condition="!Exists('%(FullPath)')" />
|
||||
</ItemGroup>
|
||||
<Error Condition="'@(_MissingReleaseApiArchive)' != ''" Text="The release is missing these API archives: @(_MissingReleaseApiArchive)" />
|
||||
<Error Condition="'@(_MissingReleaseWebArchive)' != ''" Text="The release is missing these web archives: @(_MissingReleaseWebArchive)" />
|
||||
<!-- Extract every archive and compare its files and hashes with the publish folder it was built from. -->
|
||||
<MSBuild Projects="$(MSBuildThisFileFullPath)" Targets="VerifyReleaseArchive" Properties="ReleaseArchivePath=$(ReleaseArchivesDirectory)/Nemera-$(ReleaseVersion)-%(_ReleaseRuntime.ReleaseArchiveStem)-api%(_ReleaseRuntime.ReleaseArchiveExtension);ReleaseArchiveSourceDirectory=$(ApiPublishDirectory)/%(_ReleaseRuntime.Identity);ReleaseArchiveExtension=%(_ReleaseRuntime.ReleaseArchiveExtension);ReleaseArchiveAppHostFileName=Nemera.Presentation.Api;ReleaseArchiveVerificationDirectory=$(ReleaseArchiveVerificationDirectory)/%(_ReleaseRuntime.Identity)-api" />
|
||||
<MSBuild Projects="$(MSBuildThisFileFullPath)" Targets="VerifyReleaseArchive" Properties="ReleaseArchivePath=$(ReleaseArchivesDirectory)/Nemera-$(ReleaseVersion)-%(_ReleaseRuntime.ReleaseArchiveStem)-web%(_ReleaseRuntime.ReleaseArchiveExtension);ReleaseArchiveSourceDirectory=$(WebPublishDirectory)/%(_ReleaseRuntime.Identity);ReleaseArchiveExtension=%(_ReleaseRuntime.ReleaseArchiveExtension);ReleaseArchiveAppHostFileName=Nemera.Presentation.Web;ReleaseArchiveVerificationDirectory=$(ReleaseArchiveVerificationDirectory)/%(_ReleaseRuntime.Identity)-web" />
|
||||
</Target>
|
||||
|
||||
<!-- Verifies that one release contains exactly the native runtime folders that the catalog declares for it, so a folder that never reached the release cannot pass. -->
|
||||
<Target Name="VerifyReleaseRuntimeDirectories">
|
||||
<PropertyGroup>
|
||||
<_ReleaseRuntimeDirectoryPath>$(ApiPublishDirectory)/$(BundledPluginReleaseRuntimeIdentifier)/plugins/runtimes</_ReleaseRuntimeDirectoryPath>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('$(_ReleaseRuntimeDirectoryPath)')" Text="The release for $(BundledPluginReleaseRuntimeIdentifier) is missing the native runtime folder '$(_ReleaseRuntimeDirectoryPath)'." />
|
||||
<ItemGroup>
|
||||
<_DeclaredRuntimeDirectory Include="@(BundledPluginRuntimeDirectory)" Condition="'%(BundledPluginRuntimeDirectory.RuntimeIdentifier)' == '$(BundledPluginReleaseRuntimeIdentifier)'" />
|
||||
<_ExpectedRuntimeDirectory Include="@(_DeclaredRuntimeDirectory->'$(_ReleaseRuntimeDirectoryPath)/%(Identity)')" />
|
||||
<_ActualRuntimeDirectory Include="$([System.IO.Directory]::GetDirectories('$(_ReleaseRuntimeDirectoryPath)'))" />
|
||||
<_MissingRuntimeDirectory Include="@(_ExpectedRuntimeDirectory)" Condition="!Exists('%(FullPath)')" />
|
||||
<_UnexpectedRuntimeDirectory Include="@(_ActualRuntimeDirectory)" Exclude="@(_ExpectedRuntimeDirectory)" />
|
||||
</ItemGroup>
|
||||
<Error Condition="'@(_DeclaredRuntimeDirectory)' == ''" Text="The runtime catalog declares no native runtime folders for $(BundledPluginReleaseRuntimeIdentifier)." />
|
||||
<Error Condition="'@(_MissingRuntimeDirectory)' != ''" Text="The release for $(BundledPluginReleaseRuntimeIdentifier) is missing native runtime folders: @(_MissingRuntimeDirectory)" />
|
||||
<Error Condition="'@(_UnexpectedRuntimeDirectory)' != ''" Text="The release for $(BundledPluginReleaseRuntimeIdentifier) contains unexpected native runtime folders: @(_UnexpectedRuntimeDirectory)" />
|
||||
</Target>
|
||||
|
||||
<!-- Verifies that one declared native runtime folder in a release contains exactly the files from the bundled plugin staging folder, with identical hashes. -->
|
||||
<Target Name="VerifyReleaseRuntimeNativeFiles">
|
||||
<PropertyGroup>
|
||||
<_NativeSourceDirectory>$(BundledPluginsPublishDirectory)/runtimes/$(BundledPluginRuntimeDirectoryName)</_NativeSourceDirectory>
|
||||
<_NativeReleaseDirectory>$(ApiPublishDirectory)/$(BundledPluginReleaseRuntimeIdentifier)/plugins/runtimes/$(BundledPluginRuntimeDirectoryName)</_NativeReleaseDirectory>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('$(_NativeSourceDirectory)')" Text="The bundled plugin staging folder is missing the native runtime directory '$(BundledPluginRuntimeDirectoryName)'." />
|
||||
<ItemGroup>
|
||||
<_NativeSourceFile Include="$(_NativeSourceDirectory)/**/*" />
|
||||
<_NativeReleaseFile Include="@(_NativeSourceFile->'$(_NativeReleaseDirectory)/%(RecursiveDir)%(Filename)%(Extension)')" />
|
||||
<_ActualNativeReleaseFile Include="$(_NativeReleaseDirectory)/**/*" />
|
||||
<_MissingNativeReleaseFile Include="@(_NativeReleaseFile)" Condition="!Exists('%(FullPath)')" />
|
||||
</ItemGroup>
|
||||
<Error Condition="'@(_MissingNativeReleaseFile)' != ''" Text="The release for $(BundledPluginReleaseRuntimeIdentifier) is missing native files: @(_MissingNativeReleaseFile)" />
|
||||
<GetFileHash Files="@(_NativeSourceFile)" Algorithm="SHA256">
|
||||
<Output TaskParameter="Items" ItemName="_NativeSourceFileHash" />
|
||||
</GetFileHash>
|
||||
<GetFileHash Files="@(_NativeReleaseFile)" Algorithm="SHA256">
|
||||
<Output TaskParameter="Items" ItemName="_NativeReleaseFileHash" />
|
||||
</GetFileHash>
|
||||
<PropertyGroup>
|
||||
<_NativeSourceHashList>@(_NativeSourceFileHash->'%(FileHash)')</_NativeSourceHashList>
|
||||
<_NativeReleaseHashList>@(_NativeReleaseFileHash->'%(FileHash)')</_NativeReleaseHashList>
|
||||
<_NativeSourceFileCount>@(_NativeSourceFile->Count())</_NativeSourceFileCount>
|
||||
<_ActualNativeFileCount>@(_ActualNativeReleaseFile->Count())</_ActualNativeFileCount>
|
||||
</PropertyGroup>
|
||||
<Error Condition="'$(_NativeSourceHashList)' != '$(_NativeReleaseHashList)'" Text="The native files in the release for $(BundledPluginReleaseRuntimeIdentifier) do not match the bundled plugin staging folder." />
|
||||
<Error Condition="'$(_NativeSourceFileCount)' != '$(_ActualNativeFileCount)'" Text="The release for $(BundledPluginReleaseRuntimeIdentifier) contains an unexpected number of native files." />
|
||||
</Target>
|
||||
|
||||
<!-- Verifies that every runtime folder contains an assembly for every bundled plugin project in the release catalog, so a plugin that never reached a published folder cannot pass. -->
|
||||
<Target Name="VerifyReleasePluginAssemblies">
|
||||
<ItemGroup>
|
||||
<_ExpectedBundledPluginAssembly Include="@(BundledPluginProject->'$(ApiPublishDirectory)/$(BundledPluginReleaseRuntimeIdentifier)/plugins/%(Filename).dll')" />
|
||||
<_MissingBundledPluginAssembly Include="@(_ExpectedBundledPluginAssembly)" Condition="!Exists('%(FullPath)')" />
|
||||
</ItemGroup>
|
||||
<Error Condition="'@(BundledPluginProject)' == ''" Text="The bundled plugin catalog is empty." />
|
||||
<Error Condition="'@(_MissingBundledPluginAssembly)' != ''" Text="The release for $(BundledPluginReleaseRuntimeIdentifier) is missing bundled plugin assemblies: @(_MissingBundledPluginAssembly)" />
|
||||
</Target>
|
||||
|
||||
<!-- Verifies that one release folder contains exactly the same plugin binaries as the reference published folder that the trust list records. -->
|
||||
<Target Name="VerifyReleasePluginFiles">
|
||||
<ItemGroup>
|
||||
<_ReferencePluginAssembly Include="$(ReferencePluginsDirectory)/Nemera.Plugins.*.dll" />
|
||||
<_ReleasePluginAssembly Include="@(_ReferencePluginAssembly->'$(ReleasePluginsDirectory)/%(Filename)%(Extension)')" />
|
||||
<_ActualReleasePluginAssembly Include="$(ReleasePluginsDirectory)/Nemera.Plugins.*.dll" />
|
||||
<_MissingReleasePluginAssembly Include="@(_ReleasePluginAssembly)" Condition="!Exists('%(FullPath)')" />
|
||||
<_UnexpectedReleasePluginAssembly Include="@(_ActualReleasePluginAssembly)" Exclude="@(_ReleasePluginAssembly)" />
|
||||
</ItemGroup>
|
||||
<Error Condition="'@(_ReferencePluginAssembly)' == ''" Text="No plugin binaries were found in the reference published folder '$(ReferencePluginsDirectory)'." />
|
||||
<Error Condition="'@(_MissingReleasePluginAssembly)' != ''" Text="The release for $(BundledPluginReleaseRuntimeIdentifier) is missing plugin binaries: @(_MissingReleasePluginAssembly)" />
|
||||
<Error Condition="'@(_UnexpectedReleasePluginAssembly)' != ''" Text="The release for $(BundledPluginReleaseRuntimeIdentifier) contains unexpected plugin binaries: @(_UnexpectedReleasePluginAssembly)" />
|
||||
<GetFileHash Files="@(_ReferencePluginAssembly)" Algorithm="SHA256">
|
||||
<Output TaskParameter="Items" ItemName="_ReferencePluginAssemblyHash" />
|
||||
</GetFileHash>
|
||||
<GetFileHash Files="@(_ReleasePluginAssembly)" Algorithm="SHA256">
|
||||
<Output TaskParameter="Items" ItemName="_ReleasePluginAssemblyHash" />
|
||||
</GetFileHash>
|
||||
<PropertyGroup>
|
||||
<_ReferencePluginAssemblyCount>@(_ReferencePluginAssembly->Count())</_ReferencePluginAssemblyCount>
|
||||
<_ActualReleasePluginAssemblyCount>@(_ActualReleasePluginAssembly->Count())</_ActualReleasePluginAssemblyCount>
|
||||
<_ReferencePluginAssemblyHashList>@(_ReferencePluginAssemblyHash->'%(FileHash)')</_ReferencePluginAssemblyHashList>
|
||||
<_ReleasePluginAssemblyHashList>@(_ReleasePluginAssemblyHash->'%(FileHash)')</_ReleasePluginAssemblyHashList>
|
||||
</PropertyGroup>
|
||||
<Error Condition="'$(_ReferencePluginAssemblyCount)' != '$(_ActualReleasePluginAssemblyCount)'" Text="The release for $(BundledPluginReleaseRuntimeIdentifier) contains an unexpected number of plugin binaries." />
|
||||
<Error Condition="'$(_ReferencePluginAssemblyHashList)' != '$(_ReleasePluginAssemblyHashList)'" Text="The plugin binaries in the release for $(BundledPluginReleaseRuntimeIdentifier) do not match the reference published folder." />
|
||||
</Target>
|
||||
|
||||
<!-- Extracts one release archive and verifies that it contains exactly the files from its publish folder, including their hashes. -->
|
||||
<Target Name="VerifyReleaseArchive">
|
||||
<RemoveDir Directories="$(ReleaseArchiveVerificationDirectory)" Condition="Exists('$(ReleaseArchiveVerificationDirectory)')" />
|
||||
<MakeDir Directories="$(ReleaseArchiveVerificationDirectory)" />
|
||||
<Exec Condition="'$(ReleaseArchiveExtension)' == '.zip' And '$(OS)' == 'Windows_NT'" Command="tar -xf "$(ReleaseArchivePath)" -C "$(ReleaseArchiveVerificationDirectory)"" />
|
||||
<Exec Condition="'$(ReleaseArchiveExtension)' == '.zip' And '$(OS)' != 'Windows_NT'" Command="unzip -q "$(ReleaseArchivePath)" -d "$(ReleaseArchiveVerificationDirectory)"" />
|
||||
<Exec Condition="'$(ReleaseArchiveExtension)' == '.tar.gz'" Command="tar -xzf "$(ReleaseArchivePath)" -C "$(ReleaseArchiveVerificationDirectory)"" />
|
||||
<!-- Linux and macOS archives must keep the app host executable, which Windows cannot store when it creates the archive. -->
|
||||
<Exec Condition="'$(ReleaseArchiveExtension)' == '.tar.gz'" Command="tar -tvzf "$(ReleaseArchivePath)"" ConsoleToMSBuild="true" StandardOutputImportance="low">
|
||||
<Output TaskParameter="ConsoleOutput" ItemName="_TarReleaseArchiveEntry" />
|
||||
</Exec>
|
||||
<ItemGroup>
|
||||
<_ExecutableTarReleaseArchiveEntry Include="@(_TarReleaseArchiveEntry)" Condition="'$(ReleaseArchiveExtension)' == '.tar.gz' And $([System.Text.RegularExpressions.Regex]::IsMatch('%(Identity)', '^-..x.*[ ./]$(ReleaseArchiveAppHostFileName)\s*$'))" />
|
||||
</ItemGroup>
|
||||
<Error Condition="'$(ReleaseArchiveExtension)' == '.tar.gz' And '$(ReleaseArchiveAppHostFileName)' == ''" Text="The release archive verification requires the app host file name of the archive." />
|
||||
<Error Condition="'$(ReleaseArchiveExtension)' == '.tar.gz' And '$(ReleaseArchiveAppHostFileName)' != '' And '@(_ExecutableTarReleaseArchiveEntry)' == ''" Text="The release archive '$(ReleaseArchivePath)' does not store '$(ReleaseArchiveAppHostFileName)' with the executable bit, so it cannot be started after extraction. Create Linux and macOS archives on Linux or macOS." />
|
||||
<ItemGroup>
|
||||
<_ArchiveSourceFile Include="$(ReleaseArchiveSourceDirectory)/**/*" />
|
||||
<_ArchiveExpectedFile Include="@(_ArchiveSourceFile->'$(ReleaseArchiveVerificationDirectory)/%(RecursiveDir)%(Filename)%(Extension)')" />
|
||||
<_ArchiveExtractedFile Include="$(ReleaseArchiveVerificationDirectory)/**/*" />
|
||||
<_MissingArchiveFile Include="@(_ArchiveExpectedFile)" Condition="!Exists('%(FullPath)')" />
|
||||
</ItemGroup>
|
||||
<Error Condition="'@(_MissingArchiveFile)' != ''" Text="The release archive '$(ReleaseArchivePath)' is missing files: @(_MissingArchiveFile)" />
|
||||
<GetFileHash Files="@(_ArchiveSourceFile)" Algorithm="SHA256">
|
||||
<Output TaskParameter="Items" ItemName="_ArchiveSourceFileHash" />
|
||||
</GetFileHash>
|
||||
<GetFileHash Files="@(_ArchiveExpectedFile)" Algorithm="SHA256">
|
||||
<Output TaskParameter="Items" ItemName="_ArchiveVerificationFileHash" />
|
||||
</GetFileHash>
|
||||
<PropertyGroup>
|
||||
<_ArchiveSourceHashList>@(_ArchiveSourceFileHash->'%(FileHash)')</_ArchiveSourceHashList>
|
||||
<_ArchiveExtractedHashList>@(_ArchiveVerificationFileHash->'%(FileHash)')</_ArchiveExtractedHashList>
|
||||
<_ArchiveSourceFileCount>@(_ArchiveSourceFile->Count())</_ArchiveSourceFileCount>
|
||||
<_ArchiveExtractedFileCount>@(_ArchiveExtractedFile->Count())</_ArchiveExtractedFileCount>
|
||||
</PropertyGroup>
|
||||
<Error Condition="'$(_ArchiveSourceHashList)' != '$(_ArchiveExtractedHashList)'" Text="The release archive '$(ReleaseArchivePath)' does not match its publish folder." />
|
||||
<Error Condition="'$(_ArchiveSourceFileCount)' != '$(_ArchiveExtractedFileCount)'" Text="The release archive '$(ReleaseArchivePath)' contains an unexpected number of files." />
|
||||
<RemoveDir Directories="$(ReleaseArchiveVerificationDirectory)" Condition="Exists('$(ReleaseArchiveVerificationDirectory)')" />
|
||||
</Target>
|
||||
|
||||
<!-- ApiReleaseRuntimeIdentifier selects the reference publish folder, the recorded hashes and the Docker context, so it must be one of the release catalog runtimes. -->
|
||||
<Target Name="ValidateReleaseRuntimeIdentifier">
|
||||
<ItemGroup>
|
||||
<_UnknownReleaseRuntime Include="$(ApiReleaseRuntimeIdentifier)" Exclude="@(BundledPluginRuntime)" />
|
||||
</ItemGroup>
|
||||
<Error Condition="'@(_UnknownReleaseRuntime)' != ''" Text="ApiReleaseRuntimeIdentifier '$(ApiReleaseRuntimeIdentifier)' is not in the release runtime catalog. Use one of: @(BundledPluginRuntime)." />
|
||||
</Target>
|
||||
|
||||
<!-- Official release configuration must be validated before any build or test work starts. -->
|
||||
<Target Name="ValidateOfficialRelease">
|
||||
<Target Name="ValidateOfficialRelease" DependsOnTargets="ValidateReleaseRuntimeIdentifier">
|
||||
<Error Condition="'$(OfficialReleaseBuild)' != 'true'" Text="The Publish target is reserved for official release builds. Pass -p:OfficialReleaseBuild=true." />
|
||||
<Error Condition="'$(Configuration)' != 'Release'" Text="Official releases must be published in the Release configuration." />
|
||||
</Target>
|
||||
|
||||
<Target Name="Publish" DependsOnTargets="ValidateOfficialRelease;VerifyBundledPlugins">
|
||||
<!-- Publishes one framework-dependent folder per supported runtime, so every platform gets its native apphost and the bundled plugins, and then packages each folder into its own API and web archive. -->
|
||||
<Target Name="Publish" DependsOnTargets="ValidateOfficialRelease;ValidateReleaseVersion;VerifyBundledPlugins">
|
||||
<RemoveDir Directories="$(ApiPublishDirectory)" Condition="Exists('$(ApiPublishDirectory)')" />
|
||||
<RemoveDir Directories="$(WebPublishDirectory)" Condition="Exists('$(WebPublishDirectory)')" />
|
||||
<RemoveDir Directories="$(BundledPluginsPublishDirectory)" Condition="Exists('$(BundledPluginsPublishDirectory)')" />
|
||||
<RemoveDir Directories="$(ReleaseArchivesDirectory)" Condition="Exists('$(ReleaseArchivesDirectory)')" />
|
||||
<Error Condition="!Exists('$(BundledPluginsCurrentManifest)')" Text="The current bundled plugin manifest '$(BundledPluginsCurrentManifest)' is missing. Build the official plugins before publishing." />
|
||||
<MakeDir Directories="$(ApiPublishDirectory)/plugins" />
|
||||
<MSBuild Projects="@(BundledPluginProject)" Targets="Build" Properties="Configuration=$(Configuration);NemeraPluginsOutputDirectory=$(ApiPublishDirectory)/plugins/" />
|
||||
<MakeDir Directories="$(BundledPluginsPublishDirectory)" />
|
||||
<MSBuild Projects="@(BundledPluginProject)" Targets="Build" Properties="Configuration=$(Configuration);NemeraPluginsOutputDirectory=$(BundledPluginsPublishDirectory)/;OfficialReleaseBuild=$(_OfficialReleaseBuild)" />
|
||||
<ItemGroup>
|
||||
<_PublishedBundledPluginAssembly Include="$(ApiPublishDirectory)/plugins/Nemera.Plugins.*.dll" />
|
||||
<_PublishedBundledPluginAssembly Include="$(BundledPluginsPublishDirectory)/Nemera.Plugins.*.dll" />
|
||||
</ItemGroup>
|
||||
<Error Condition="'@(_PublishedBundledPluginAssembly)' == ''" Text="No bundled plugin binaries were deployed to '$(ApiPublishDirectory)/plugins'." />
|
||||
<Error Condition="'@(_PublishedBundledPluginAssembly)' == ''" Text="No bundled plugin binaries were deployed to '$(BundledPluginsPublishDirectory)'." />
|
||||
<GetFileHash Files="@(_PublishedBundledPluginAssembly)" Algorithm="SHA256">
|
||||
<Output TaskParameter="Items" ItemName="_PublishedBundledPluginHash" />
|
||||
</GetFileHash>
|
||||
<WriteLinesToFile File="$(BundledPluginsCurrentManifest)" Lines="@(_PublishedBundledPluginHash->'%(Filename)%(Extension)|%(FileHash)')" Overwrite="true" WriteOnlyWhenDifferent="true" />
|
||||
<Exec Command="dotnet publish "$(RepoRoot)/src/Nemera.Presentation.Api/Nemera.Presentation.Api.csproj" -c $(Configuration) -o "$(ApiPublishDirectory)" -p:OfficialReleaseBuild=true -p:BundledPluginsCurrentManifest="$(BundledPluginsCurrentManifest)" -p:BundledPluginsPredeployed=true" />
|
||||
<Exec Command="dotnet publish "$(RepoRoot)/src/Nemera.Presentation.Web/Nemera.Presentation.Web.csproj" -c $(Configuration) -o "$(WebPublishDirectory)"" />
|
||||
<!-- Restore once for every runtime, so the publishes reuse a multi-RID assets file instead of leaving the last single-RID restore behind. The environment variable avoids passing semicolons as a global MSBuild property. -->
|
||||
<Exec Condition="'$(OS)' == 'Windows_NT'" Command="set "NEMERA_RELEASE_RUNTIME_IDENTIFIERS=@(_ReleaseRuntime)" && dotnet restore "$(RepoRoot)/src/Nemera.Presentation.Api/Nemera.Presentation.Api.csproj"" />
|
||||
<Exec Condition="'$(OS)' != 'Windows_NT'" Command="NEMERA_RELEASE_RUNTIME_IDENTIFIERS='@(_ReleaseRuntime)' dotnet restore "$(RepoRoot)/src/Nemera.Presentation.Api/Nemera.Presentation.Api.csproj"" />
|
||||
<Exec Condition="'$(OS)' == 'Windows_NT'" Command="set "NEMERA_RELEASE_RUNTIME_IDENTIFIERS=@(_ReleaseRuntime)" && dotnet restore "$(RepoRoot)/src/Nemera.Presentation.Web/Nemera.Presentation.Web.csproj"" />
|
||||
<Exec Condition="'$(OS)' != 'Windows_NT'" Command="NEMERA_RELEASE_RUNTIME_IDENTIFIERS='@(_ReleaseRuntime)' dotnet restore "$(RepoRoot)/src/Nemera.Presentation.Web/Nemera.Presentation.Web.csproj"" />
|
||||
<!-- Each publish produces the native launcher for that runtime: .exe on Windows, extensionless on Linux and macOS. -->
|
||||
<Exec Command="dotnet publish "$(RepoRoot)/src/Nemera.Presentation.Api/Nemera.Presentation.Api.csproj" -c $(Configuration) --no-restore -r %(_ReleaseRuntime.Identity) --self-contained false -o "$(ApiPublishDirectory)/%(_ReleaseRuntime.Identity)" -p:OfficialReleaseBuild=true -p:BundledPluginsCurrentManifest="$(BundledPluginsCurrentManifest)" -p:BundledPluginsPredeployed=true" />
|
||||
<Exec Command="dotnet publish "$(RepoRoot)/src/Nemera.Presentation.Web/Nemera.Presentation.Web.csproj" -c $(Configuration) --no-restore -r %(_ReleaseRuntime.Identity) --self-contained false -o "$(WebPublishDirectory)/%(_ReleaseRuntime.Identity)"" />
|
||||
<MSBuild Projects="$(MSBuildThisFileFullPath)" Targets="CopyBundledPluginsToReleaseRuntime" Properties="Configuration=$(Configuration);ApiPublishDirectory=$(ApiPublishDirectory);BundledPluginsPublishDirectory=$(BundledPluginsPublishDirectory);BundledPluginReleaseRuntimeIdentifier=%(_ReleaseRuntime.Identity)" />
|
||||
<ItemGroup>
|
||||
<!-- Release downloads do not need debug symbols. -->
|
||||
<_PublishedPdb Include="$(ApiPublishDirectory)/**/*.pdb;$(WebPublishDirectory)/**/*.pdb" />
|
||||
</ItemGroup>
|
||||
<Delete Files="@(_PublishedPdb)" />
|
||||
<PropertyGroup>
|
||||
<_PublishedBundledPlugins>true</_PublishedBundledPlugins>
|
||||
</PropertyGroup>
|
||||
</Target>
|
||||
|
||||
<!-- Official images must be Release builds, so they cannot bypass the release configuration or the manifest checks. -->
|
||||
<Target Name="ValidateDockerRelease" Condition="'$(_OfficialReleaseBuild)' == 'true'">
|
||||
<Error Condition="'$(Configuration)' != 'Release'" Text="Official Docker images must be built in the Release configuration." />
|
||||
<!-- Copies only the destination runtime and its declared native folders into one release folder, so a Windows release never contains Linux or macOS native libraries. -->
|
||||
<Target Name="CopyBundledPluginsToReleaseRuntime">
|
||||
<ItemGroup>
|
||||
<!-- Everything outside runtimes is shared by all plugins and is always copied. -->
|
||||
<_RuntimeBundledPluginSharedFile Include="$(BundledPluginsPublishDirectory)/**/*" Exclude="$(BundledPluginsPublishDirectory)/runtimes/**" />
|
||||
<!-- The runtime catalog declares the native folders that belong to each release, including family fallbacks such as osx. -->
|
||||
<_ReleaseNativeRuntimeDirectory Include="@(BundledPluginRuntimeDirectory)" Condition="'%(BundledPluginRuntimeDirectory.RuntimeIdentifier)' == '$(BundledPluginReleaseRuntimeIdentifier)'" />
|
||||
</ItemGroup>
|
||||
<Copy SourceFiles="@(_RuntimeBundledPluginSharedFile)" DestinationFiles="@(_RuntimeBundledPluginSharedFile->'$(ApiPublishDirectory)/$(BundledPluginReleaseRuntimeIdentifier)/plugins/%(RecursiveDir)%(Filename)%(Extension)')" />
|
||||
<MSBuild Projects="$(MSBuildThisFileFullPath)" Targets="CopyBundledPluginRuntimeDirectory" Properties="Configuration=$(Configuration);ApiPublishDirectory=$(ApiPublishDirectory);BundledPluginsPublishDirectory=$(BundledPluginsPublishDirectory);BundledPluginReleaseRuntimeIdentifier=$(BundledPluginReleaseRuntimeIdentifier);BundledPluginRuntimeDirectoryName=%(_ReleaseNativeRuntimeDirectory.Identity)" />
|
||||
</Target>
|
||||
|
||||
<!-- Official images ship the verified publish output. Local images build from source so docker compose keeps working without a prior publish. -->
|
||||
<Target Name="Docker" DependsOnTargets="$(_DockerDependsOn)">
|
||||
<!-- Copies one declared native runtime folder, for example osx, into the release folder of the runtime that needs it. -->
|
||||
<Target Name="CopyBundledPluginRuntimeDirectory">
|
||||
<ItemGroup>
|
||||
<_RuntimeBundledPluginNativeFile Include="$(BundledPluginsPublishDirectory)/runtimes/$(BundledPluginRuntimeDirectoryName)/**/*" />
|
||||
</ItemGroup>
|
||||
<Copy SourceFiles="@(_RuntimeBundledPluginNativeFile)" DestinationFiles="@(_RuntimeBundledPluginNativeFile->'$(ApiPublishDirectory)/$(BundledPluginReleaseRuntimeIdentifier)/plugins/runtimes/$(BundledPluginRuntimeDirectoryName)/%(RecursiveDir)%(Filename)%(Extension)')" />
|
||||
</Target>
|
||||
|
||||
<!-- ReleaseVersion becomes the archive file name, so it is validated before any archive path or tar command uses it. -->
|
||||
<Target Name="ValidateReleaseVersion">
|
||||
<PropertyGroup>
|
||||
<_ReleaseVersionIsValid>false</_ReleaseVersionIsValid>
|
||||
<_ReleaseVersionIsValid Condition="$([System.Text.RegularExpressions.Regex]::IsMatch('$(ReleaseVersion)', '$(_ReleaseVersionPattern)'))">true</_ReleaseVersionIsValid>
|
||||
</PropertyGroup>
|
||||
<Error Condition="'$(_ReleaseVersionIsValid)' != 'true'" Text="The release version '$(ReleaseVersion)' is invalid. Pass a three-part version such as 1.2.3, for example -p:Version=1.2.3." />
|
||||
</Target>
|
||||
|
||||
<!-- Builds one API archive and one web archive per runtime from the publish output, so each download contains only that platform's files. It can run directly after a publish. -->
|
||||
<Target Name="CreateReleaseArchives" AfterTargets="Publish" DependsOnTargets="ValidateReleaseVersion">
|
||||
<ItemGroup>
|
||||
<_ArchiveRuntime Include="@(BundledPluginRuntime)" />
|
||||
<_ArchivePublishOutput Include="@(_ArchiveRuntime->'$(ApiPublishDirectory)/%(Identity)/Nemera.Presentation.Api.dll')" />
|
||||
<_ArchivePublishOutput Include="@(_ArchiveRuntime->'$(WebPublishDirectory)/%(Identity)/Nemera.Presentation.Web.dll')" />
|
||||
<_MissingArchivePublishOutput Include="@(_ArchivePublishOutput)" Condition="!Exists('%(FullPath)')" />
|
||||
</ItemGroup>
|
||||
<Error Condition="'@(_MissingArchivePublishOutput)' != ''" Text="The release archives cannot be created because the publish output is missing. Run the Publish target first, which also creates the archives: @(_MissingArchivePublishOutput)" />
|
||||
<RemoveDir Directories="$(ReleaseArchivesDirectory)" Condition="Exists('$(ReleaseArchivesDirectory)')" />
|
||||
<MakeDir Directories="$(ReleaseArchivesDirectory)" />
|
||||
<!-- Windows cannot store the executable bit in a tar archive, so it must not create the Linux and macOS archives. -->
|
||||
<Warning Condition="'$(OS)' == 'Windows_NT'" Text="Windows cannot store the executable bit in a tar archive, so the Linux and macOS archives are not created. Run the archive targets on Linux or macOS to create them." />
|
||||
<!-- Windows archives are zip files. Linux and macOS archives are tar.gz so the executable permission survives the download. -->
|
||||
<ZipDirectory SourceDirectory="$(ApiPublishDirectory)/%(_ArchiveRuntime.Identity)" DestinationFile="$(ReleaseArchivesDirectory)/Nemera-$(ReleaseVersion)-%(_ArchiveRuntime.ReleaseArchiveStem)-api%(_ArchiveRuntime.ReleaseArchiveExtension)" Condition="'%(_ArchiveRuntime.ReleaseArchiveExtension)' == '.zip'" />
|
||||
<ZipDirectory SourceDirectory="$(WebPublishDirectory)/%(_ArchiveRuntime.Identity)" DestinationFile="$(ReleaseArchivesDirectory)/Nemera-$(ReleaseVersion)-%(_ArchiveRuntime.ReleaseArchiveStem)-web%(_ArchiveRuntime.ReleaseArchiveExtension)" Condition="'%(_ArchiveRuntime.ReleaseArchiveExtension)' == '.zip'" />
|
||||
<Exec Command="tar -czf "$(ReleaseArchivesDirectory)/Nemera-$(ReleaseVersion)-%(_ArchiveRuntime.ReleaseArchiveStem)-api%(_ArchiveRuntime.ReleaseArchiveExtension)" -C "$(ApiPublishDirectory)/%(_ArchiveRuntime.Identity)" ." Condition="'%(_ArchiveRuntime.ReleaseArchiveExtension)' == '.tar.gz' And '$(OS)' != 'Windows_NT'" />
|
||||
<Exec Command="tar -czf "$(ReleaseArchivesDirectory)/Nemera-$(ReleaseVersion)-%(_ArchiveRuntime.ReleaseArchiveStem)-web%(_ArchiveRuntime.ReleaseArchiveExtension)" -C "$(WebPublishDirectory)/%(_ArchiveRuntime.Identity)" ." Condition="'%(_ArchiveRuntime.ReleaseArchiveExtension)' == '.tar.gz' And '$(OS)' != 'Windows_NT'" />
|
||||
</Target>
|
||||
|
||||
<!-- Official images must be Release builds and must use a glibc Linux runtime, because the image base is a glibc distribution and copies the published folder of that architecture. -->
|
||||
<Target Name="ValidateDockerRelease" Condition="'$(_OfficialReleaseBuild)' == 'true'" DependsOnTargets="ValidateReleaseRuntimeIdentifier">
|
||||
<Error Condition="'$(Configuration)' != 'Release'" Text="Official Docker images must be built in the Release configuration." />
|
||||
<ItemGroup>
|
||||
<_DockerReleaseRuntime Include="linux-x64;linux-arm64" />
|
||||
<_NonGlibcDockerReleaseRuntime Include="$(ApiReleaseRuntimeIdentifier)" Exclude="@(_DockerReleaseRuntime)" />
|
||||
</ItemGroup>
|
||||
<Error Condition="'@(_NonGlibcDockerReleaseRuntime)' != ''" Text="Official Docker images require a glibc Linux runtime identifier, because the image base is a glibc distribution. Use one of: @(_DockerReleaseRuntime). The linux-musl-x64 runtime cannot be used with these images." />
|
||||
<Error Condition="'$(_DockerPlatform)' == ''" Text="No Docker platform is defined for ApiReleaseRuntimeIdentifier '$(ApiReleaseRuntimeIdentifier)'." />
|
||||
<!-- A reused publish output skips the publish-folder verification, so at least require the folders the images are built from. -->
|
||||
<Error Condition="'$(ReusePublishedBundledPlugins)' == 'true' And !Exists('$(ApiPublishDirectory)/$(ApiReleaseRuntimeIdentifier)/Nemera.Presentation.Api.dll')" Text="ReusePublishedBundledPlugins=true requires a published API folder at '$(ApiPublishDirectory)/$(ApiReleaseRuntimeIdentifier)'. Publish the release first." />
|
||||
<Error Condition="'$(ReusePublishedBundledPlugins)' == 'true' And !Exists('$(WebPublishDirectory)/$(ApiReleaseRuntimeIdentifier)/Nemera.Presentation.Web.dll')" Text="ReusePublishedBundledPlugins=true requires a published web folder at '$(WebPublishDirectory)/$(ApiReleaseRuntimeIdentifier)'. Publish the release first." />
|
||||
</Target>
|
||||
|
||||
<!-- The image tag comes from Version and is passed to docker build, so it must be a plain release version or the local latest default, never a shell fragment. -->
|
||||
<Target Name="ValidateDockerImageVersion">
|
||||
<PropertyGroup>
|
||||
<_DockerImageVersionIsValid>false</_DockerImageVersionIsValid>
|
||||
<_DockerImageVersionIsValid Condition="'$(_ImageVersion)' == 'latest'">true</_DockerImageVersionIsValid>
|
||||
<_DockerImageVersionIsValid Condition="$([System.Text.RegularExpressions.Regex]::IsMatch('$(_ImageVersion)', '$(_ReleaseVersionPattern)'))">true</_DockerImageVersionIsValid>
|
||||
</PropertyGroup>
|
||||
<Error Condition="'$(_DockerImageVersionIsValid)' != 'true'" Text="The Docker image version '$(Version)' is invalid. Pass a three-part version such as 1.2.3, for example -p:Version=1.2.3." />
|
||||
</Target>
|
||||
|
||||
<!-- Official images build from a publish folder that the preceding step verified, and local images build from source so docker compose keeps working without a prior publish. -->
|
||||
<Target Name="Docker" DependsOnTargets="ValidateDockerImageVersion;$(_DockerDependsOn)">
|
||||
<PropertyGroup>
|
||||
<_ImageVersion Condition="'$(Version)' != ''">$(Version)</_ImageVersion>
|
||||
<_ImageVersion Condition="'$(Version)' == ''">latest</_ImageVersion>
|
||||
<_DockerApiDockerfile Condition="'$(_OfficialReleaseBuild)' == 'true'">$(RepoRoot)/src/Nemera.Presentation.Api/Dockerfile.release</_DockerApiDockerfile>
|
||||
<_DockerApiDockerfile Condition="'$(_OfficialReleaseBuild)' != 'true'">$(RepoRoot)/src/Nemera.Presentation.Api/Dockerfile</_DockerApiDockerfile>
|
||||
<_DockerApiContext Condition="'$(_OfficialReleaseBuild)' == 'true'">$(ApiPublishDirectory)</_DockerApiContext>
|
||||
<_DockerApiContext Condition="'$(_OfficialReleaseBuild)' == 'true'">$(ApiPublishDirectory)/$(ApiReleaseRuntimeIdentifier)</_DockerApiContext>
|
||||
<_DockerApiContext Condition="'$(_OfficialReleaseBuild)' != 'true'">$(RepoRoot)</_DockerApiContext>
|
||||
<_DockerWebDockerfile Condition="'$(_OfficialReleaseBuild)' == 'true'">$(RepoRoot)/src/Nemera.Presentation.Web/Dockerfile.release</_DockerWebDockerfile>
|
||||
<_DockerWebDockerfile Condition="'$(_OfficialReleaseBuild)' != 'true'">$(RepoRoot)/src/Nemera.Presentation.Web/Dockerfile</_DockerWebDockerfile>
|
||||
<_DockerWebContext Condition="'$(_OfficialReleaseBuild)' == 'true'">$(WebPublishDirectory)</_DockerWebContext>
|
||||
<_DockerWebContext Condition="'$(_OfficialReleaseBuild)' == 'true'">$(WebPublishDirectory)/$(ApiReleaseRuntimeIdentifier)</_DockerWebContext>
|
||||
<_DockerWebContext Condition="'$(_OfficialReleaseBuild)' != 'true'">$(RepoRoot)</_DockerWebContext>
|
||||
</PropertyGroup>
|
||||
<Exec Command="docker build -t nemera-api:$(_ImageVersion) -f "$(_DockerApiDockerfile)" "$(_DockerApiContext)"" />
|
||||
<Exec Command="docker build -t nemera-web:$(_ImageVersion) -f "$(_DockerWebDockerfile)" "$(_DockerWebContext)"" />
|
||||
<Exec Command="docker build $(_DockerPlatformOption)-t "nemera-api:$(_ImageVersion)" -f "$(_DockerApiDockerfile)" "$(_DockerApiContext)"" />
|
||||
<Exec Command="docker build $(_DockerPlatformOption)-t "nemera-web:$(_ImageVersion)" -f "$(_DockerWebDockerfile)" "$(_DockerWebContext)"" />
|
||||
</Target>
|
||||
|
||||
<!-- Recording is only allowed from a clean GitHub Actions checkout whose commit is the current origin/master. -->
|
||||
@@ -172,17 +486,17 @@
|
||||
<Error Condition="'@(_BundledPluginsHead)' != '@(_BundledPluginsMasterHead)'" Text="Recording bundled plugin hashes requires the release branch to point at origin/master. Merge the previous trust-list pull request and recreate the release branch from master." />
|
||||
</Target>
|
||||
|
||||
<Target Name="RecordBundledPlugins" DependsOnTargets="ValidateBundledPluginsRecording;Publish;VerifyPublishedBundledPlugins;RecordBundledPluginsFromPublish" />
|
||||
<Target Name="RecordBundledPlugins" DependsOnTargets="ValidateBundledPluginsRecording;Publish;VerifyPublishedBundledPlugins;VerifyReleaseArchives;RecordBundledPluginsFromPublish" />
|
||||
|
||||
<!-- VerifyPublishedBundledPlugins has already proved that the published plugin set exactly matches the embedded current manifest. -->
|
||||
<!-- VerifyPublishedBundledPlugins has already checked the embedded manifest against every published API folder and compared every runtime folder's plugin binaries with the reference folder, so the reference folder is representative of every shipped platform. -->
|
||||
<Target Name="RecordBundledPluginsFromPublish" DependsOnTargets="ValidateOfficialRelease;ValidateBundledPluginsRecording;VerifyPublishedBundledPlugins">
|
||||
<ItemGroup>
|
||||
<_BundledPluginPublishedAssembly Include="$(ApiPublishDirectory)/plugins/Nemera.Plugins.*.dll" />
|
||||
<_BundledPluginPublishedAssembly Include="$(ApiPublishDirectory)/$(ApiReleaseRuntimeIdentifier)/plugins/Nemera.Plugins.*.dll" />
|
||||
</ItemGroup>
|
||||
<GetFileHash Files="@(_BundledPluginPublishedAssembly)" Algorithm="SHA256">
|
||||
<Output TaskParameter="Items" ItemName="_RecordedBundledPluginHash" />
|
||||
</GetFileHash>
|
||||
<Error Condition="'@(_RecordedBundledPluginHash)' == ''" Text="No bundled plugin binaries were found in '$(ApiPublishDirectory)/plugins'." />
|
||||
<Error Condition="'@(_RecordedBundledPluginHash)' == ''" Text="No bundled plugin binaries were found in '$(ApiPublishDirectory)/$(ApiReleaseRuntimeIdentifier)/plugins'." />
|
||||
<Error Condition="!Exists('$(BundledPluginsManifest)')" Text="The bundled plugin trust manifest '$(BundledPluginsManifest)' is missing." />
|
||||
<ReadLinesFromFile File="$(BundledPluginsManifest)">
|
||||
<Output TaskParameter="Lines" ItemName="_ExistingBundledPluginManifestLine" />
|
||||
|
||||
@@ -30,7 +30,7 @@ Everything from Configuration onward applies to whichever route you chose.
|
||||
|
||||
## Before you start
|
||||
|
||||
- **Docker**, if you want the container route. For a non-container install, you need the Nemera application files, from a release package or installer, or from your own build, plus the **.NET 10 runtime** unless that package is self-contained. The **.NET 10 SDK** is only needed if you build from source.
|
||||
- **Docker**, if you want the container route. For a non-container install, you need the Nemera application files, from a release package or installer, or from your own build, plus the **ASP.NET Core Runtime 10** unless that package is self-contained. The **.NET 10 SDK** is only needed if you build from source.
|
||||
- **ffmpeg**, for any non-container install, however you obtained the application files. The API server uses it to remux or transcode audio that the browser cannot play as stored. The Docker API container image already includes it.
|
||||
- By default the **web client listens on port `5012`** and the **API on port `5214`**. You can change either, as long as the two agree on where the API is (see [Configuration](#configuration)).
|
||||
- For anything reachable beyond your own machine, put a **reverse proxy** in front to terminate TLS and forward to the web client.
|
||||
@@ -86,12 +86,25 @@ Use a release package or installer when one is available, or, with the .NET 10 S
|
||||
dotnet build Nemera.slnx
|
||||
```
|
||||
|
||||
The official release artifacts include the PDF plugin's native libraries for Linux x64 and ARM64 (including Alpine x64), macOS Intel and Apple Silicon, and Windows x64 and ARM64. The single release download works on those platforms; the plugin loads the native libraries that match the host at runtime.
|
||||
The official release is split into one API archive and one web archive per platform and architecture. Download both archives for your platform:
|
||||
|
||||
Run the API and the web client from the installed release package or from the published build. In development, their addresses come from each project's `launchSettings.json` (`http://localhost:5214` and `http://localhost:5012`). When you run a published build directly on a host, set the addresses yourself, either with `ASPNETCORE_URLS` or with `ASPNETCORE_HTTP_PORTS`:
|
||||
| Platform | API archive | Web archive |
|
||||
| --- | --- | --- |
|
||||
| Linux x64 | `Nemera-<version>-linux-x64-api.tar.gz` | `Nemera-<version>-linux-x64-web.tar.gz` |
|
||||
| Linux ARM64 | `Nemera-<version>-linux-arm64-api.tar.gz` | `Nemera-<version>-linux-arm64-web.tar.gz` |
|
||||
| Linux x64 with musl, including Alpine | `Nemera-<version>-linux-musl-x64-api.tar.gz` | `Nemera-<version>-linux-musl-x64-web.tar.gz` |
|
||||
| macOS Intel | `Nemera-<version>-macos-x64-api.tar.gz` | `Nemera-<version>-macos-x64-web.tar.gz` |
|
||||
| macOS Apple Silicon | `Nemera-<version>-macos-arm64-api.tar.gz` | `Nemera-<version>-macos-arm64-web.tar.gz` |
|
||||
| Windows x64 | `Nemera-<version>-windows-x64-api.zip` | `Nemera-<version>-windows-x64-web.zip` |
|
||||
| Windows x86 | `Nemera-<version>-windows-x86-api.zip` | `Nemera-<version>-windows-x86-web.zip` |
|
||||
| Windows ARM64 | `Nemera-<version>-windows-arm64-api.zip` | `Nemera-<version>-windows-arm64-web.zip` |
|
||||
|
||||
Each archive contains only the files for its platform and architecture. The API archive includes the bundled plugins and the PDF plugin's native libraries for that platform. Extract both archives into separate folders.
|
||||
|
||||
When using the release package, run the API and the web client from the folders you extracted. On Windows, start `Nemera.Presentation.Api.exe` and `Nemera.Presentation.Web.exe`. On Linux and macOS, start `./Nemera.Presentation.Api` and `./Nemera.Presentation.Web`. The API listens on `http://localhost:5214` and the web client on `http://localhost:5012` by default. Set `ASPNETCORE_URLS`, `ASPNETCORE_HTTP_PORTS` or `ASPNETCORE_HTTPS_PORTS` only when you need different addresses:
|
||||
|
||||
```bash
|
||||
ASPNETCORE_HTTP_PORTS=5012 dotnet Nemera.Presentation.Web.dll
|
||||
ASPNETCORE_URLS=http://0.0.0.0:5012 ./Nemera.Presentation.Web
|
||||
```
|
||||
|
||||
The API creates its SQLite database (`Nemera.db`) next to its own binary and applies any pending migrations at startup, so the first launch sets up the schema on its own.
|
||||
|
||||
+23
-15
@@ -19,15 +19,17 @@ Releases are cut only by the repository owner. There is one official build, and
|
||||
|
||||
1. The owner creates a `release/x.y.z` branch from `master`.
|
||||
2. The `Publish Release` workflow builds and publishes the official artifacts with `OfficialReleaseBuild=true`.
|
||||
3. The same workflow verifies the published API assembly against the published plugin binaries, records the release's plugin hashes in the append-only trust list, builds the release images from the verified publish output, and opens a pull request to `master`.
|
||||
4. The owner downloads the official artifacts and creates the GitHub release and tag.
|
||||
3. The same workflow verifies the embedded plugin manifest against every published API folder, records the release's plugin hashes in the append-only trust list, builds the release images from the verified publish output, and opens a pull request to `master`.
|
||||
4. The owner downloads the release archives and creates the GitHub release and tag.
|
||||
5. The owner merges the trust-list pull request. The current release already embeds its own official plugin manifest, so this pull request keeps the release's plugin binaries Official in future releases.
|
||||
|
||||
The full test suite runs on normal pull requests to `master`. The release build does not rerun the full suite. It runs the manifest verification tests for the official build, publishes, verifies the published API assembly against the published plugin binaries, records the hashes and builds the release images from the verified publish output.
|
||||
The full test suite runs on normal pull requests to `master`. The release build does not rerun the full suite. It runs the manifest verification tests for the official build, publishes, verifies the embedded plugin manifest against every published API folder, checks the native folders and files of every runtime, verifies every archive against its publish folder, records the hashes and builds the release images from the verified publish output.
|
||||
|
||||
The repository pins the .NET SDK in `global.json`. The workflows install that exact SDK, and the Docker build stage uses the matching `10.0.100` SDK image, so root-level and container builds use the same toolchain.
|
||||
|
||||
The `release-api` artifact is a single framework-dependent publish built on `ubuntu-latest`. The bundled plugin deployment keeps the PDF plugin's native libraries for the supported runtime identifiers: `win-x64`, `win-arm64`, `linux-x64`, `linux-arm64`, `linux-musl-x64`, `osx-x64` and `osx-arm64`. The macOS packages also keep their shared SkiaSharp library in the `osx` fallback folder, which the build retains automatically even though no device reports that identifier. The list is defined by `BundledPluginRuntimeIdentifiers` in `plugins/Directory.Build.props`, and the PDF plugin validates its required native libraries for every identifier in it, accepting a library from either the identifier's own folder or its OS family fallback. The plugin resolves the matching native library at runtime from its dependency manifest. The release Docker images copy that same publish output.
|
||||
The `Publish` target produces two archives for each supported runtime identifier: an API archive and a web archive. The names are `Nemera-<version>-<platform>-<architecture>-api.<extension>` and `Nemera-<version>-<platform>-<architecture>-web.<extension>`, for example `Nemera-1.2.3-linux-x64-web.tar.gz` and `Nemera-1.2.3-windows-x64-api.zip`. Windows archives are `.zip` files; Linux and macOS archives are `.tar.gz` files, so the executable permission survives the download. Each archive contains the application files, the native apphost and the native libraries for that runtime identifier only. The supported runtime identifiers are `linux-x64`, `linux-arm64`, `linux-musl-x64`, `osx-x64`, `osx-arm64`, `win-x64`, `win-x86` and `win-arm64`, and the workflow builds them all on `ubuntu-latest`. The API archive also contains the bundled plugins, so the API can run directly from the extracted folder. The plugin deployment copies only the native runtime folders the catalog declares for that runtime: the identifier's own folder and the shared `osx` folder for the macOS archives, so the PDF plugin's native libraries for the other operating systems are not shipped. The macOS archives keep their shared SkiaSharp library in the `osx` fallback folder, which the build retains automatically even though no device reports that identifier. The runtime list is defined by the `BundledPluginRuntime` items and the native folder mapping by `BundledPluginRuntimeDirectory` in `build/RuntimeIdentifiers.props`. The catalog must list exactly the folders the bundled plugins deploy: verification fails when the staging folder is missing a declared folder or contains an undeclared one, and each release must contain exactly the folders declared for its runtime identifier. The PDF plugin validates its required native libraries for every identifier in it, accepting a library from either the identifier's own folder or its OS family fallback. The plugin resolves the matching native library at runtime from its dependency manifest. Verification runs the embedded manifest test against every published API folder, requires exactly the declared native runtime folders and their files, and extracts every archive to compare its contents and hashes with the publish folder it was built from. The trust list records the published plugin hashes from the verified `linux-x64` folder; every other runtime folder is verified against the same embedded manifest and its plugin binaries are compared with that reference folder, so the recorded hashes describe every shipped platform. The publish output excludes `.pdb` files. The API listens on `http://localhost:5214` and the web client on `http://localhost:5012` by default. The `Publish Release` workflow builds the release images from the `linux-x64` publish folders to validate the image definitions, and does not upload them. The images you ship are built manually from the extracted `Nemera-<version>-linux-x64-api` and `Nemera-<version>-linux-x64-web` archives with `--platform linux/amd64`, or from the `linux-arm64` archives with `--platform linux/arm64`; the `linux-musl-x64` archives cannot be used with these images, because their base image is a glibc distribution. The Linux and macOS archives must be created on Linux or macOS, because Windows cannot store the executable bit in a tar archive: `Publish` on Windows creates only the Windows archives and warns that the others were skipped.
|
||||
|
||||
`Publish` restores the API and web projects once for all supported runtimes and publishes each runtime with `--no-restore`, so the projects keep a multi-RID assets file. The restore reads the runtime list from an environment variable set only for that command, so normal builds are unaffected.
|
||||
|
||||
The presentation host does not compile against the concrete plugin projects, and it does not own the bundled plugin catalog. The plugin projects are part of the solution and copy their outputs to the API plugin folder. `build.proj` owns the release catalog: it builds and hashes the plugin binaries, writes the current manifest, passes that manifest to the API publish, and copies the binaries into the published plugin folder. Adding or removing a bundled plugin changes the release catalog and the solution, not the host project.
|
||||
|
||||
@@ -93,12 +95,12 @@ The token is used only by the `record-manifest` job. It is not available to the
|
||||
## Workflows
|
||||
|
||||
- `Publish Release` runs when the owner creates a `release/x.y.z` branch. It has two jobs:
|
||||
- `publish`: builds and publishes the official artifacts with `OfficialReleaseBuild=true`, runs the manifest verification tests, verifies the published API assembly against the published plugin binaries, records the released plugin hashes, builds the release images from the verified publish output, and uploads the `release-api`, `release-web` and `bundled-plugins-manifest` artifacts. It has the license secret and a read-only token.
|
||||
- `publish`: builds and publishes the official artifacts with `OfficialReleaseBuild=true`, runs the manifest verification tests, verifies the embedded plugin manifest against every published API folder, checks every runtime's native folders and files, verifies every archive against its publish folder, records the released plugin hashes, builds the release images from the verified publish output, and uploads the `release-archives` and `bundled-plugins-manifest` artifacts. The `release-archives` artifact contains the API and web archives for every supported runtime. It has the license secret and a read-only token.
|
||||
- `record-manifest`: downloads the manifest artifact, appends only the release entries that are missing from master's current trust list, and opens the `other/record-release-x.y.z` pull request to `master` with the `RELEASE_PR_TOKEN`. It does not have the license secret.
|
||||
- `Run All Tests` runs on pull requests to `master` and uses the repository `SIXLABORS_LICENSE_KEY` secret.
|
||||
- `Branch Push Naming Convention Check` and `Pull Request Source Branch Validation Check` allow `feature/`, `bugfix/`, `hotfix/`, `documentation/`, `refactor/`, `other/`, and `release/x.y.z`.
|
||||
|
||||
The release branch is built from `master` after the normal pull request checks have passed. The release build does not rerun the full test suite. It runs the manifest verification tests, because that is the only part of the build that changes when the official plugin manifest and the official release marker are embedded. It then verifies the published API assembly against the published plugin binaries before recording hashes or building images. The trust-list pull request runs the full suite before it can be merged.
|
||||
The release branch is built from `master` after the normal pull request checks have passed. The release build does not rerun the full test suite. It runs the manifest verification tests, because that is the only part of the build that changes when the official plugin manifest and the official release marker are embedded. It then verifies the embedded plugin manifest against every published API folder, the native folders and files of every runtime, and the contents of every archive before recording hashes or building images. The trust-list pull request runs the full suite before it can be merged.
|
||||
|
||||
Recording is CI-only. The publish job checks that the worktree is clean and that `HEAD` matches `origin/master` before it appends to the trust list. A local `RecordBundledPlugins` run is rejected by the guard.
|
||||
|
||||
@@ -111,26 +113,29 @@ The trust list `build/BundledPlugins.manifest` is append-only. Never remove exis
|
||||
3. Create the `release/x.y.z` branch from the current `master` as the owner. The publish job requires the branch to point at the current `origin/master`. The check is exact: if anything merges to `master` before the job runs, the job fails and the branch must be recreated from the new `master`.
|
||||
4. Approve the `release` environment for the `publish` and `record-manifest` jobs.
|
||||
5. Wait for `Publish Release` to publish and verify the official artifacts, record the trust list and build the release images.
|
||||
6. Download the `release-api` and `release-web` artifacts.
|
||||
7. Create the GitHub release and tag manually from those artifacts. The workflow does not create the release.
|
||||
6. Download the `release-archives` artifact. It contains one API archive and one web archive for each supported runtime identifier.
|
||||
7. Create the GitHub release and tag manually from those archives. The workflow does not create the release.
|
||||
8. Wait for `Run All Tests` and both branch validators on the `other/record-release-1.2.3` pull request. Review the trust-list diff and merge it.
|
||||
9. The workflow builds the release images from the verified publish output to validate the image definitions, but it does not upload them. Build the images you ship from the downloaded artifacts, so they contain exactly the plugin binaries whose hashes were recorded:
|
||||
9. The workflow builds the release images from the verified publish output to validate the image definitions, but it does not upload them. Build the images you ship from the extracted archives, so they contain exactly the plugin binaries whose hashes were recorded:
|
||||
```bash
|
||||
docker build -t nemera-api:1.2.3 -f src/Nemera.Presentation.Api/Dockerfile.release <release-api-directory>
|
||||
docker build -t nemera-web:1.2.3 -f src/Nemera.Presentation.Web/Dockerfile.release <release-web-directory>
|
||||
docker build --platform linux/amd64 -t nemera-api:1.2.3 -f src/Nemera.Presentation.Api/Dockerfile.release <extracted-api-folder>
|
||||
docker build --platform linux/amd64 -t nemera-web:1.2.3 -f src/Nemera.Presentation.Web/Dockerfile.release <extracted-web-folder>
|
||||
```
|
||||
Extract `Nemera-1.2.3-linux-x64-api.tar.gz` and `Nemera-1.2.3-linux-x64-web.tar.gz` first. Each archive contains its publish files at the root, so the extracted folder is the Docker context. Use `--platform linux/arm64` with the `linux-arm64` archives. The `linux-musl-x64` archives cannot be used with these images, because their base image is a glibc distribution.
|
||||
To publish, verify and build in one local step instead, run:
|
||||
```bash
|
||||
dotnet msbuild build/build.proj -t:Docker -p:Configuration=Release -p:OfficialReleaseBuild=true -p:Version=1.2.3
|
||||
```
|
||||
That target publishes from source, verifies the publish output and builds the images from it. Those images are not the exact released artifacts unless the build is byte-identical, so prefer the downloaded artifacts for the images you ship.
|
||||
That target publishes from source, verifies the publish output and builds the images from the `linux-x64` publish folder with the `linux/amd64` platform derived from `ApiReleaseRuntimeIdentifier`. Pass `-p:ApiReleaseRuntimeIdentifier=linux-arm64` to build from the arm64 publish folder instead. Those images are not the exact released artifacts unless the build is byte-identical, so prefer the downloaded archives for the images you ship.
|
||||
|
||||
The local equivalent of the official build is verification only. Recording is CI-only. The release workflow checks that the checkout is clean and that `HEAD` matches `origin/master` exactly before it appends to the trust list.
|
||||
|
||||
```bash
|
||||
dotnet msbuild build/build.proj -t:VerifyPublishedBundledPlugins -p:Configuration=Release -p:OfficialReleaseBuild=true
|
||||
dotnet msbuild build/build.proj -t:VerifyPublishedBundledPlugins -p:Configuration=Release -p:OfficialReleaseBuild=true -p:Version=1.2.3
|
||||
```
|
||||
|
||||
`VerifyPublishedBundledPlugins` checks the publish folders and does not require `bin/release`. `CreateReleaseArchives` can run on its own after a publish, and `VerifyReleaseArchives` creates the archives if needed and verifies every archive against its publish folder; both must run on Linux or macOS, because Windows cannot create `.tar.gz` archives with the executable bit. The Docker target only needs the publish folders, so `-t:Docker -p:ReusePublishedBundledPlugins=true` works even when `bin/release` is absent. `ReusePublishedBundledPlugins=true` skips both the publish and its verification, so pass it only after the publish folders were just verified, as the release workflow does. The release Docker target derives `--platform` from `ApiReleaseRuntimeIdentifier`, which must be `linux-x64` (`linux/amd64`) or `linux-arm64` (`linux/arm64`); `linux-musl-x64` has no matching glibc image base.
|
||||
|
||||
For a local Release build, set `SixLaborsLicenseKey` to the content of `src/Nemera.Domain/sixlabors.lic` first. The file alone is only discovered by `Nemera.Domain`, and projects that reference ImageSharp through it fail license validation otherwise.
|
||||
|
||||
## Revoking a bundled plugin hash
|
||||
@@ -184,5 +189,8 @@ If the token is compromised, also review recent branches, pull requests and work
|
||||
| `RecordBundledPlugins` fails because `master` moved | The release branch no longer matches the current `origin/master`. | Recreate the `release/x.y.z` branch from the new `master` and approve the new run. |
|
||||
| The record-list pull request removes trust-list lines | The merge step was skipped, or master's current manifest was replaced with an older artifact. | The record job only appends missing entries and fails if the staged diff removes a line. Rerun the workflow. |
|
||||
| A known good plugin is not Official | A deny-list entry matches its hash. | Remove the matching line from `build/BundledPlugins.deny.manifest`. |
|
||||
| `VerifyPublishedBundledPlugins` fails | The manifest embedded in the published API assembly does not match the published plugin binaries. | Re-run the release build from the same commit. Do not mix artifacts from different builds. |
|
||||
| The release image build fails with an official configuration error | `Docker` was called with `OfficialReleaseBuild=true` and a configuration other than `Release`. | Pass `-p:Configuration=Release`. |
|
||||
| `VerifyPublishedBundledPlugins` fails | The bundled plugin staging folder is missing a native folder the catalog declares or contains an undeclared one, a published runtime folder is missing its assembly, apphost, plugin binary or native file, still contains a PDB or an undeclared native runtime folder or an unexpected number of plugin binaries, its embedded plugin manifest does not match its plugin binaries, or its plugin binaries differ from the reference `linux-x64` folder. | Re-run the release build from the same commit. Do not mix artifacts from different builds. If the staging folder and the catalog disagree, align `build/RuntimeIdentifiers.props` with the native folders the bundled plugins deploy. |
|
||||
| `VerifyReleaseArchives` fails | A platform archive is missing, or its files or hashes differ from the publish folder it was built from, or the Linux or macOS app host is not executable inside the archive. | Re-run the release build from the same commit, so the archives and the publish folders come from the same build. Build Linux and macOS archives on Linux or macOS. |
|
||||
| The Linux or macOS archives are missing after `Publish` | `Publish` ran on Windows, which cannot store the executable bit in a tar archive, so those archives are skipped with a warning. | Run `Publish` on Linux or macOS. The `Publish Release` workflow builds the released archives on `ubuntu-latest`. |
|
||||
| The release build rejects the version | `Version` or `ReleaseVersion` is not three numeric parts. | Pass a version such as `-p:Version=1.2.3`. |
|
||||
| The release image build fails with an official configuration error | `Docker` was called with `OfficialReleaseBuild=true` and a configuration other than `Release`, or with an `ApiReleaseRuntimeIdentifier` that is not a glibc runtime (`linux-x64` or `linux-arm64`; the musl runtime has no matching image base). | Pass `-p:Configuration=Release` and a glibc runtime identifier such as `linux-x64`. |
|
||||
@@ -1,11 +1,10 @@
|
||||
<Project>
|
||||
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)..'))" />
|
||||
<Import Project="$(MSBuildThisFileDirectory)../build/RuntimeIdentifiers.props" />
|
||||
|
||||
<!-- Shared warning and documentation policy for every plugin project under plugins. -->
|
||||
<PropertyGroup>
|
||||
<BaseOutputPath>$(RepoRoot)bin/plugins/</BaseOutputPath>
|
||||
<!-- The real runtime identifiers the release artifact supports. Every bundled plugin with native dependencies must provide its libraries for each of them. The OS family fallback folders, such as osx, are kept automatically. -->
|
||||
<BundledPluginRuntimeIdentifiers>win-x64;win-arm64;linux-x64;linux-arm64;linux-musl-x64;osx-x64;osx-arm64</BundledPluginRuntimeIdentifiers>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<WarningsAsErrors>$(WarningsAsErrors);CS1591</WarningsAsErrors><!--Public members must have XML documentation.-->
|
||||
|
||||
@@ -11,10 +11,11 @@
|
||||
<Compile Include="..\..\src\AssemblyInfo_Shared.cs" Link="Properties\AssemblyInfo_Shared.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- The supported runtimes come from the shared bundled plugin property. Each runtime also uses an OS family fallback folder, where the native dependency packages keep the libraries shared by every architecture of that operating system. -->
|
||||
<!-- The supported runtimes come from the shared bundled plugin runtime list. Each runtime also uses an OS family fallback folder, where the native dependency packages keep the libraries shared by every architecture of that operating system. -->
|
||||
<Target Name="DefinePdfRuntimeLibraries">
|
||||
<Error Condition="'@(BundledPluginRuntime)' == ''" Text="The bundled plugin runtime list is empty. Restore the BundledPluginRuntime items in build/RuntimeIdentifiers.props." />
|
||||
<ItemGroup>
|
||||
<_SupportedPdfRuntime Include="$(BundledPluginRuntimeIdentifiers)" />
|
||||
<_SupportedPdfRuntime Include="@(BundledPluginRuntime)" />
|
||||
<_WindowsPdfRuntime Include="@(_SupportedPdfRuntime)" Condition="$([System.String]::Copy('%(Identity)').StartsWith('win-'))">
|
||||
<PdfFamily>win</PdfFamily>
|
||||
</_WindowsPdfRuntime>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Nemera.Application.Common.DataAccess.Entities.Themes;
|
||||
using Nemera.Application.Common.DataAccess.UoW;
|
||||
using Nemera.Application.Common.DTO.Filtering;
|
||||
@@ -7,7 +8,6 @@ using Nemera.Application.Common.Infrastructure.Models.DTO.Themes;
|
||||
using Nemera.Application.Common.Infrastructure.Themes;
|
||||
using Nemera.Domain.Common.Primitives;
|
||||
using Nemera.Domain.SharedKernel.Common.Enums.Themes;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -32,6 +32,8 @@ internal static class ThemeSynchronizer
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
internal static async Task SynchronizeAsync(IThemeService themeService, IUnitOfWork unitOfWork, ILogger logger, CancellationToken cancellationToken)
|
||||
{
|
||||
// The installed themes are read tracked, so the current flag that EnsureCurrentThemeExists sets on an existing theme is
|
||||
// persisted by the final SaveChangesAsync; a theme inserted during this synchronization is tracked as added by InsertAsync.
|
||||
Result<PaginatedResultDto<ThemeEntity>> getThemesResult = await unitOfWork.ThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (getThemesResult.IsFailure)
|
||||
{
|
||||
@@ -127,7 +129,7 @@ internal static class ThemeSynchronizer
|
||||
}
|
||||
|
||||
await CleanUpMissingThemePacksAsync(themeService, unitOfWork, themes, logger, cancellationToken).ConfigureAwait(false);
|
||||
await EnsureCurrentThemeExistsAsync(themeService, unitOfWork, themes, logger, cancellationToken).ConfigureAwait(false);
|
||||
EnsureCurrentThemeExists(themeService, themes);
|
||||
|
||||
Result<Success> saveChangesResult = await unitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
||||
if (saveChangesResult.IsFailure)
|
||||
@@ -208,14 +210,11 @@ internal static class ThemeSynchronizer
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Activates the configured default theme when no theme is currently active, so the application always has an active theme.
|
||||
/// Marks the configured default theme as current when no theme is currently active, so the application always has an active theme.
|
||||
/// </summary>
|
||||
/// <param name="themeService">Injected service for the server-side storage and serving of theme packs.</param>
|
||||
/// <param name="unitOfWork">The unit of work for interacting with the theme repository.</param>
|
||||
/// <param name="themes">The installed themes read from the storage medium.</param>
|
||||
/// <param name="logger">Injected logger used for logging.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
private static async Task EnsureCurrentThemeExistsAsync(IThemeService themeService, IUnitOfWork unitOfWork, IReadOnlyList<ThemeEntity> themes, ILogger logger, CancellationToken cancellationToken)
|
||||
internal static void EnsureCurrentThemeExists(IThemeService themeService, IReadOnlyList<ThemeEntity> themes)
|
||||
{
|
||||
if (themes.Any(theme => !theme.IsDeleted && theme.IsCurrent == true))
|
||||
return;
|
||||
@@ -231,10 +230,9 @@ internal static class ThemeSynchronizer
|
||||
if (defaultTheme is null)
|
||||
return;
|
||||
|
||||
// A theme inserted during this synchronization is not in the database yet, so an UpdateAsync call would fail with ThemeNotFound.
|
||||
// The entity is already tracked, as added by InsertAsync or as an existing row from the tracked read, so setting the flag here
|
||||
// is persisted by the SaveChangesAsync that follows the synchronization.
|
||||
defaultTheme.IsCurrent = true;
|
||||
Result<Updated> updateResult = await unitOfWork.ThemeRepository.UpdateAsync(defaultTheme, cancellationToken).ConfigureAwait(false);
|
||||
if (updateResult.IsFailure)
|
||||
if (logger.IsEnabled(LogLevel.Warning))
|
||||
logger.LogWarning("Failed to activate theme '{ThemeId}': {Error}", defaultTheme.ThemeId, updateResult.FirstError.Description);
|
||||
}
|
||||
}
|
||||
@@ -62,9 +62,8 @@ WORKDIR /app
|
||||
|
||||
# The app user must own the published files, because the plugin installer writes into /app/plugins.
|
||||
COPY --from=publish --chown=app:app /app/publish .
|
||||
# The HTTP port is controlled per run mode: launchSettings.json for local development, ASPNETCORE_HTTP_PORTS here for
|
||||
# Docker, and for a published DLL run directly on a host, ASPNETCORE_URLS (or ASPNETCORE_HTTP_PORTS) must be set.
|
||||
ENV ASPNETCORE_HTTP_PORTS=5214
|
||||
# The container branch in Program.cs binds the API to this port. Direct published runs default to the documented address
|
||||
# and can override it with ASPNETCORE_URLS, ASPNETCORE_HTTP_PORTS or ASPNETCORE_HTTPS_PORTS.
|
||||
EXPOSE 5214
|
||||
ENTRYPOINT ["dotnet", "Nemera.Presentation.Api.dll"]
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# This image ships the published release artifacts, so the recorded plugin hashes and the image contents are the same files.
|
||||
# Build it with the published API directory as the context:
|
||||
# docker build -t nemera-api -f src/Nemera.Presentation.Api/Dockerfile.release bin/api/publish
|
||||
# Build it with the extracted Linux x64 API archive as the context.
|
||||
# docker build -t nemera-api -f src/Nemera.Presentation.Api/Dockerfile.release <extracted-Nemera-version-linux-x64-api>
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS final
|
||||
|
||||
# Curl is used by the container healthcheck to probe the /health endpoints.
|
||||
@@ -16,6 +16,6 @@ WORKDIR /app
|
||||
# The app user must own the published files, because the plugin installer writes into /app/plugins.
|
||||
COPY --chown=app:app . .
|
||||
|
||||
ENV ASPNETCORE_HTTP_PORTS=5214
|
||||
# The container branch in Program.cs binds the API to this port.
|
||||
EXPOSE 5214
|
||||
ENTRYPOINT ["dotnet", "Nemera.Presentation.Api.dll"]
|
||||
@@ -9,6 +9,8 @@
|
||||
<ContainerRepository>nemera-api</ContainerRepository>
|
||||
<DockerfileTag>nemera-api</DockerfileTag>
|
||||
<DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
|
||||
<!-- The release restore sets this environment variable to restore every supported runtime in one pass. -->
|
||||
<RuntimeIdentifiers Condition="'$(NEMERA_RELEASE_RUNTIME_IDENTIFIERS)' != ''">$(NEMERA_RELEASE_RUNTIME_IDENTIFIERS)</RuntimeIdentifiers>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(OfficialReleaseBuild)' == 'true'">
|
||||
<DefineConstants>$(DefineConstants);OFFICIAL_RELEASE_BUILD</DefineConstants>
|
||||
|
||||
@@ -74,7 +74,16 @@ public class Program
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
logPath = Path.Combine(AppContext.BaseDirectory, "logs"); // Use local binary path.
|
||||
// A published build used to fall back to the framework's port 5000. Keep the documented default only when the host
|
||||
// did not provide an address or a port through configuration, including ASPNETCORE_URLS, ASPNETCORE_HTTP_PORTS
|
||||
// and ASPNETCORE_HTTPS_PORTS.
|
||||
if (string.IsNullOrWhiteSpace(builder.Configuration["Urls"])
|
||||
&& string.IsNullOrWhiteSpace(builder.Configuration["HTTP_PORTS"])
|
||||
&& string.IsNullOrWhiteSpace(builder.Configuration["HTTPS_PORTS"]))
|
||||
builder.WebHost.UseUrls("http://localhost:5214");
|
||||
}
|
||||
Directory.CreateDirectory(logPath);
|
||||
if (!logPath.EndsWith(Path.DirectorySeparatorChar.ToString()))
|
||||
logPath = logPath += Path.DirectorySeparatorChar;
|
||||
|
||||
@@ -47,9 +47,8 @@ FROM base AS final
|
||||
WORKDIR /app
|
||||
|
||||
COPY --from=publish --chown=app:app /app/publish .
|
||||
# The HTTP port is controlled per run mode: launchSettings.json for local development, ASPNETCORE_HTTP_PORTS here for
|
||||
# Docker, and for a published DLL run directly on a host, ASPNETCORE_URLS (or ASPNETCORE_HTTP_PORTS) must be set.
|
||||
ENV ASPNETCORE_HTTP_PORTS=5012
|
||||
# The container branch in Program.cs binds the web client to this port. Direct published runs default to the documented
|
||||
# address and can override it with ASPNETCORE_URLS, ASPNETCORE_HTTP_PORTS or ASPNETCORE_HTTPS_PORTS.
|
||||
EXPOSE 5012
|
||||
ENTRYPOINT ["dotnet", "Nemera.Presentation.Web.dll"]
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# This image ships the published release artifacts, so the image contents are the same files the release workflow exported.
|
||||
# Build it with the published Web directory as the context:
|
||||
# docker build -t nemera-web -f src/Nemera.Presentation.Web/Dockerfile.release bin/web/publish
|
||||
# Build it with the extracted Linux x64 Web archive as the context.
|
||||
# docker build -t nemera-web -f src/Nemera.Presentation.Web/Dockerfile.release <extracted-Nemera-version-linux-x64-web>
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS final
|
||||
|
||||
# Curl is used by the container healthcheck to probe the /health endpoints.
|
||||
@@ -14,6 +14,6 @@ WORKDIR /app
|
||||
|
||||
COPY --chown=app:app . .
|
||||
|
||||
ENV ASPNETCORE_HTTP_PORTS=5012
|
||||
# The container branch in Program.cs binds the web client to this port.
|
||||
EXPOSE 5012
|
||||
ENTRYPOINT ["dotnet", "Nemera.Presentation.Web.dll"]
|
||||
@@ -11,6 +11,8 @@
|
||||
<ContainerRepository>nemera-web</ContainerRepository>
|
||||
<DockerfileTag>nemera-web</DockerfileTag>
|
||||
<DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
|
||||
<!-- The release restore sets this environment variable to restore every supported runtime in one pass. -->
|
||||
<RuntimeIdentifiers Condition="'$(NEMERA_RELEASE_RUNTIME_IDENTIFIERS)' != ''">$(NEMERA_RELEASE_RUNTIME_IDENTIFIERS)</RuntimeIdentifiers>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Nemera.Presentation.Web.Common.DependencyInjection;
|
||||
using Nemera.Presentation.Web.Common.HealthChecks;
|
||||
using Nemera.Presentation.Web.Common.Utilities;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
@@ -11,6 +8,9 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
using Nemera.Presentation.Web.Common.DependencyInjection;
|
||||
using Nemera.Presentation.Web.Common.HealthChecks;
|
||||
using Nemera.Presentation.Web.Common.Utilities;
|
||||
using Scalar.AspNetCore;
|
||||
using Serilog;
|
||||
using System;
|
||||
@@ -50,7 +50,16 @@ public class Program
|
||||
builder.WebHost.ConfigureKestrel(options => options.ListenAnyIP(5012)); // HTTP only.
|
||||
}
|
||||
else
|
||||
{
|
||||
logPath = Path.Combine(AppContext.BaseDirectory, "logs"); // Use local binary path.
|
||||
// A published build used to fall back to the framework's port 5000. Keep the documented default only when the host
|
||||
// did not provide an address or a port through configuration, including ASPNETCORE_URLS, ASPNETCORE_HTTP_PORTS
|
||||
// and ASPNETCORE_HTTPS_PORTS.
|
||||
if (string.IsNullOrWhiteSpace(builder.Configuration["Urls"])
|
||||
&& string.IsNullOrWhiteSpace(builder.Configuration["HTTP_PORTS"])
|
||||
&& string.IsNullOrWhiteSpace(builder.Configuration["HTTPS_PORTS"]))
|
||||
builder.WebHost.UseUrls("http://localhost:5012");
|
||||
}
|
||||
Directory.CreateDirectory(logPath);
|
||||
if (!logPath.EndsWith(Path.DirectorySeparatorChar.ToString()))
|
||||
logPath = logPath += Path.DirectorySeparatorChar;
|
||||
|
||||
@@ -366,6 +366,7 @@
|
||||
<File Path="../global.json" />
|
||||
<File Path="../build/build.proj" />
|
||||
<File Path="../build/BundledPlugins.props" />
|
||||
<File Path="../build/RuntimeIdentifiers.props" />
|
||||
<File Path="../build/BundledPlugins.manifest" />
|
||||
<File Path="../build/BundledPlugins.deny.manifest" />
|
||||
<File Path="../src/Nemera.Presentation.Api/Dockerfile.release" />
|
||||
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Nemera.Application.Common.DataAccess.Entities.Themes;
|
||||
using Nemera.Application.Common.Infrastructure.Models.DTO.Themes;
|
||||
using Nemera.Application.Common.Infrastructure.Themes;
|
||||
using Nemera.Application.Common.Infrastructure.Time;
|
||||
using Nemera.Application.Fixtures.Common.Infrastructure.Models.DTO.Themes;
|
||||
using Nemera.DataAccess.Core.UoW;
|
||||
using Nemera.Domain.Common.Primitives;
|
||||
using Nemera.Infrastructure.Core.Themes;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Nemera.Infrastructure.IntegrationTests.Core.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Contains integration tests for the <see cref="ThemeSynchronizer"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ThemeSynchronizerTests : IDisposable
|
||||
{
|
||||
private readonly DbContextOptions<NemeraDbContext> _dbContextOptions;
|
||||
private readonly NemeraDbContext _dbContext;
|
||||
private readonly UnitOfWork _unitOfWork;
|
||||
private readonly IThemeService _mockThemeService;
|
||||
private readonly ILogger _mockLogger;
|
||||
private readonly ThemeManifestDtoFixture _themeManifestDtoFixture = new();
|
||||
private readonly string _archivePath;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ThemeSynchronizerTests"/> class.
|
||||
/// </summary>
|
||||
public ThemeSynchronizerTests()
|
||||
{
|
||||
_dbContextOptions = new DbContextOptionsBuilder<NemeraDbContext>()
|
||||
.UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
|
||||
.Options;
|
||||
_dbContext = new NemeraDbContext(_dbContextOptions);
|
||||
_unitOfWork = new UnitOfWork(_dbContext, Substitute.For<IDateTimeProvider>());
|
||||
_mockThemeService = Substitute.For<IThemeService>();
|
||||
_mockLogger = Substitute.For<ILogger>();
|
||||
_mockLogger.IsEnabled(Arg.Any<LogLevel>()).Returns(true);
|
||||
_archivePath = Path.Combine(Path.GetTempPath(), $"nemera-theme-sync-{Guid.NewGuid():N}.zip");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SynchronizeAsync_WhenANewBundledThemeIsInstalled_ShouldPersistTheActivatedTheme()
|
||||
{
|
||||
// Arrange
|
||||
ThemeManifestDto manifest = _themeManifestDtoFixture.Create();
|
||||
File.WriteAllText(_archivePath, "theme-pack");
|
||||
_mockThemeService.GetBundledThemeArchivePaths().Returns([_archivePath]);
|
||||
_mockThemeService.ReadManifestFromArchiveAsync(_archivePath, Arg.Any<CancellationToken>()).Returns(Result.From(manifest));
|
||||
_mockThemeService.InstallAsync(Arg.Any<Stream>(), Arg.Any<CancellationToken>()).Returns(Result.From(manifest));
|
||||
_mockThemeService.HasThemePack(Arg.Any<string>()).Returns(true);
|
||||
_mockThemeService.DefaultThemeId.Returns(manifest.Id);
|
||||
|
||||
// Act
|
||||
await ThemeSynchronizer.SynchronizeAsync(_mockThemeService, _unitOfWork, _mockLogger, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
// Activating an inserted theme must not attempt an update, which the repository would report as a failed activation warning.
|
||||
_mockLogger.DidNotReceive().Log(
|
||||
LogLevel.Warning,
|
||||
Arg.Any<EventId>(),
|
||||
Arg.Any<object>(),
|
||||
Arg.Any<Exception?>(),
|
||||
Arg.Any<Func<object, Exception?, string>>());
|
||||
// Read through a fresh context so the assertion proves SaveChanges wrote the activation, not only that the entity was tracked.
|
||||
using (NemeraDbContext verificationContext = new(_dbContextOptions))
|
||||
{
|
||||
ThemeEntity persistedTheme = Assert.Single(verificationContext.Themes);
|
||||
Assert.True(persistedTheme.IsCurrent);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Releases the database context and removes the temporary archive file.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
_dbContext.Dispose();
|
||||
if (File.Exists(_archivePath))
|
||||
File.Delete(_archivePath);
|
||||
}
|
||||
}
|
||||
+2
@@ -24,6 +24,7 @@
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Http.Features" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" />
|
||||
<PackageReference Include="NSubstitute" />
|
||||
@@ -40,6 +41,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Nemera.Infrastructure\Nemera.Infrastructure.csproj" />
|
||||
<ProjectReference Include="..\..\..\src\Nemera.DataAccess\Nemera.DataAccess.csproj" />
|
||||
<ProjectReference Include="..\..\Common\Nemera.Domain.Fixtures\Nemera.Domain.Fixtures.csproj" />
|
||||
<ProjectReference Include="..\..\Common\Nemera.Application.Fixtures\Nemera.Application.Fixtures.csproj" />
|
||||
<ProjectReference Include="..\..\Common\Nemera.Contracts.Fixtures\Nemera.Contracts.Fixtures.csproj" />
|
||||
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Reflection.Metadata;
|
||||
using System.Reflection.PortableExecutable;
|
||||
#endregion
|
||||
|
||||
namespace Nemera.Presentation.Api.IntegrationTests.Common.Setup;
|
||||
|
||||
/// <summary>
|
||||
/// Reads an embedded resource from an assembly file without loading the assembly into the current process.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The published bundled plugin manifest verification inspects publish folders of other architectures, where loading the assembly would fail.
|
||||
/// </remarks>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public static class PublishedAssemblyResourceReader
|
||||
{
|
||||
/// <summary>
|
||||
/// Reads an embedded resource from an assembly file without loading the assembly into the current process.
|
||||
/// </summary>
|
||||
/// <param name="assemblyPath">The absolute path of the assembly file.</param>
|
||||
/// <param name="resourceName">The name of the embedded resource.</param>
|
||||
/// <returns>The raw bytes of the embedded resource.</returns>
|
||||
public static byte[] ReadEmbeddedResource(string assemblyPath, string resourceName)
|
||||
{
|
||||
using (FileStream assemblyStream = File.OpenRead(assemblyPath))
|
||||
{
|
||||
using (PEReader peReader = new(assemblyStream))
|
||||
{
|
||||
// A publish folder without managed metadata means the wrong artifact was passed, so fail instead of reporting a missing resource.
|
||||
if (!peReader.HasMetadata)
|
||||
throw new InvalidOperationException($"The assembly '{assemblyPath}' does not contain managed metadata.");
|
||||
MetadataReader metadataReader = peReader.GetMetadataReader();
|
||||
foreach (ManifestResourceHandle resourceHandle in metadataReader.ManifestResources)
|
||||
{
|
||||
ManifestResource resource = metadataReader.GetManifestResource(resourceHandle);
|
||||
// A resource with a non-null implementation is linked from another file, so its bytes are not stored in this resources directory.
|
||||
if (!metadataReader.StringComparer.Equals(resource.Name, resourceName) || !resource.Implementation.IsNil)
|
||||
continue;
|
||||
// The embedded payloads live in the PE resources directory, and every resource offset is relative to the start of that directory.
|
||||
PEMemoryBlock resourceDirectory = peReader.GetSectionData(peReader.PEHeaders.CorHeader!.ResourcesDirectory.RelativeVirtualAddress);
|
||||
BlobReader resourceReader = resourceDirectory.GetReader((int)resource.Offset, resourceDirectory.Length - (int)resource.Offset);
|
||||
// Every embedded resource is prefixed with a four-byte length before its payload.
|
||||
int resourceLength = resourceReader.ReadInt32();
|
||||
return resourceReader.ReadBytes(resourceLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Returning empty bytes would let the manifest verification compare against nothing, so a missing resource is treated as a broken artifact.
|
||||
throw new InvalidOperationException($"The embedded resource '{resourceName}' is missing from '{assemblyPath}'.");
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
#endregion
|
||||
|
||||
namespace Nemera.Presentation.Api.IntegrationTests.Common.Setup;
|
||||
|
||||
/// <summary>
|
||||
/// Contains integration tests for the <see cref="PublishedAssemblyResourceReader"/> test helper.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class PublishedAssemblyResourceReaderTests
|
||||
{
|
||||
/// <summary>
|
||||
/// The resource name of the append-only trust list of previously released bundled plugin binaries.
|
||||
/// </summary>
|
||||
private const string HISTORICAL_MANIFEST_RESOURCE_NAME = "Nemera.Presentation.Api.BundledPlugins.historical.manifest";
|
||||
|
||||
[Fact]
|
||||
public void ReadEmbeddedResource_WhenReadingTheLoadedAssemblyFile_ShouldMatchTheLoadedResourceStream()
|
||||
{
|
||||
// Arrange
|
||||
// The loaded assembly's file is read directly, which is the same path the published artifact verification uses.
|
||||
string assemblyPath = typeof(Program).Assembly.Location;
|
||||
byte[] expectedResourceBytes;
|
||||
using (Stream resourceStream = typeof(Program).Assembly.GetManifestResourceStream(HISTORICAL_MANIFEST_RESOURCE_NAME)
|
||||
?? throw new InvalidOperationException($"The embedded manifest resource '{HISTORICAL_MANIFEST_RESOURCE_NAME}' is missing."))
|
||||
{
|
||||
using (MemoryStream resourceBuffer = new())
|
||||
{
|
||||
resourceStream.CopyTo(resourceBuffer);
|
||||
expectedResourceBytes = resourceBuffer.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
// Act
|
||||
byte[] actualResourceBytes = PublishedAssemblyResourceReader.ReadEmbeddedResource(assemblyPath, HISTORICAL_MANIFEST_RESOURCE_NAME);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedResourceBytes, actualResourceBytes);
|
||||
}
|
||||
}
|
||||
+22
-35
@@ -7,8 +7,6 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Loader;
|
||||
using System.Xml.Linq;
|
||||
#endregion
|
||||
|
||||
@@ -217,41 +215,30 @@ public class BundledPluginManifestReaderTests
|
||||
?? throw new InvalidOperationException($"The environment variable '{PUBLISH_DIRECTORY_ENVIRONMENT_VARIABLE}' is not set.");
|
||||
string publishedApiAssemblyPath = BundledPluginManifestTestPaths.GetPublishedApiAssemblyPath(publishDirectory);
|
||||
string publishedPluginsDirectory = BundledPluginManifestTestPaths.GetPublishedPluginsDirectory(publishDirectory);
|
||||
// Load the published API assembly in its own context, so the test reads the exact shipped binary without loading it into the test process.
|
||||
AssemblyLoadContext loadContext = new("PublishedBundledPluginManifestVerification", isCollectible: true);
|
||||
try
|
||||
// Read the resource directly from the file. Loading the assembly would fail for a runtime whose architecture differs from the test process.
|
||||
byte[] publishedManifestBytes = PublishedAssemblyResourceReader.ReadEmbeddedResource(publishedApiAssemblyPath, CURRENT_MANIFEST_RESOURCE_NAME);
|
||||
using (MemoryStream manifestStream = new(publishedManifestBytes))
|
||||
{
|
||||
Assembly publishedApiAssembly = loadContext.LoadFromAssemblyPath(publishedApiAssemblyPath);
|
||||
// The published assembly must embed the current manifest. A missing resource means the official publish step did not run.
|
||||
using (Stream manifestStream = publishedApiAssembly.GetManifestResourceStream(CURRENT_MANIFEST_RESOURCE_NAME)
|
||||
?? throw new InvalidOperationException("The published API assembly does not embed the current bundled plugin manifest."))
|
||||
{
|
||||
// Act
|
||||
IReadOnlyDictionary<string, IReadOnlySet<string>> publishedManifestEntries = BundledPluginManifestReader.ReadExpectedChecksums(manifestStream);
|
||||
// Act
|
||||
IReadOnlyDictionary<string, IReadOnlySet<string>> publishedManifestEntries = BundledPluginManifestReader.ReadExpectedChecksums(manifestStream);
|
||||
|
||||
// Assert
|
||||
Assert.NotEmpty(publishedManifestEntries);
|
||||
// The manifest and the published plugin folder must agree exactly: every entry has a file, and the counts match.
|
||||
string[] publishedPluginAssemblyFileNames = [.. Directory.EnumerateFiles(publishedPluginsDirectory, BundledPluginManifestTestPaths.PLUGIN_ASSEMBLY_SEARCH_PATTERN)
|
||||
.Select(Path.GetFileName)
|
||||
.OfType<string>()];
|
||||
Assert.Equal(publishedManifestEntries.Count, publishedPluginAssemblyFileNames.Length);
|
||||
foreach (KeyValuePair<string, IReadOnlySet<string>> entry in publishedManifestEntries)
|
||||
{
|
||||
Assert.Contains(entry.Key, publishedPluginAssemblyFileNames, StringComparer.OrdinalIgnoreCase);
|
||||
string publishedAssemblyPath = Path.Combine(publishedPluginsDirectory, entry.Key);
|
||||
Assert.True(File.Exists(publishedAssemblyPath), $"The published plugin assembly '{entry.Key}' is missing from '{publishedPluginsDirectory}'.");
|
||||
string actualSha256 = _bundledPluginFileHashFixture.Create(publishedAssemblyPath);
|
||||
string expectedSha256 = Assert.Single(entry.Value);
|
||||
Assert.Equal(expectedSha256, actualSha256, ignoreCase: true);
|
||||
}
|
||||
// Assert
|
||||
Assert.NotEmpty(publishedManifestEntries);
|
||||
// The manifest and the published plugin folder must agree exactly: every entry has a file, and the counts match.
|
||||
string[] publishedPluginAssemblyFileNames = [.. Directory.EnumerateFiles(publishedPluginsDirectory, BundledPluginManifestTestPaths.PLUGIN_ASSEMBLY_SEARCH_PATTERN)
|
||||
.Select(Path.GetFileName)
|
||||
.OfType<string>()];
|
||||
Assert.Equal(publishedManifestEntries.Count, publishedPluginAssemblyFileNames.Length);
|
||||
foreach (KeyValuePair<string, IReadOnlySet<string>> entry in publishedManifestEntries)
|
||||
{
|
||||
Assert.Contains(entry.Key, publishedPluginAssemblyFileNames, StringComparer.OrdinalIgnoreCase);
|
||||
string publishedAssemblyPath = Path.Combine(publishedPluginsDirectory, entry.Key);
|
||||
Assert.True(File.Exists(publishedAssemblyPath), $"The published plugin assembly '{entry.Key}' is missing from '{publishedPluginsDirectory}'.");
|
||||
string actualSha256 = _bundledPluginFileHashFixture.Create(publishedAssemblyPath);
|
||||
string expectedSha256 = Assert.Single(entry.Value);
|
||||
Assert.Equal(expectedSha256, actualSha256, ignoreCase: true);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Unload the collectible context so the published assembly does not stay locked for later test runs.
|
||||
loadContext.Unload();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -285,8 +272,8 @@ public class BundledPluginManifestReaderTests
|
||||
{
|
||||
using (Stream stream = typeof(Program).Assembly.GetManifestResourceStream(resourceName)
|
||||
?? throw new InvalidOperationException($"The embedded manifest resource '{resourceName}' is missing."))
|
||||
using (StreamReader reader = new(stream))
|
||||
return reader.ReadToEnd();
|
||||
using (StreamReader reader = new(stream))
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+42
-63
@@ -1,9 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Nemera.Application.Common.DataAccess.Entities.Themes;
|
||||
using Nemera.Application.Common.DataAccess.Repositories.Themes;
|
||||
using Nemera.Application.Common.DataAccess.UoW;
|
||||
using Nemera.Application.Common.DTO.Filtering;
|
||||
using Nemera.Application.Common.DTO.Pagination;
|
||||
using Nemera.Application.Common.Infrastructure.Models.DTO.Themes;
|
||||
using Nemera.Application.Common.Infrastructure.Themes;
|
||||
using Nemera.Application.Fixtures.Common.DataAccess.Entities.Themes;
|
||||
@@ -12,14 +12,10 @@ using Nemera.Application.Fixtures.Common.Infrastructure.Models.DTO.Themes;
|
||||
using Nemera.Domain.Common.Primitives;
|
||||
using Nemera.Domain.SharedKernel.Common.Enums.Themes;
|
||||
using Nemera.Infrastructure.Core.Themes;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
@@ -56,7 +52,7 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
_mockThemeService.GetBundledThemeArchivePaths().Returns([]);
|
||||
_mockThemeService.HasThemePack(Arg.Any<string>()).Returns(true);
|
||||
_mockThemeService.DefaultThemeId.Returns("nemera-default");
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [], currentPage: 1, perPage: 0, count: 0, numberOfPages: 1)));
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(shouldTrackEntities: true, cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [], currentPage: 1, perPage: 0, count: 0, numberOfPages: 1)));
|
||||
_mockThemeRepository.InsertAsync(Arg.Any<ThemeEntity>(), Arg.Any<CancellationToken>()).Returns(Result.Created);
|
||||
_mockThemeRepository.UpdateAsync(Arg.Any<ThemeEntity>(), Arg.Any<CancellationToken>()).Returns(Result.Updated);
|
||||
_mockThemeRepository.DeleteByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(Result.Deleted);
|
||||
@@ -68,7 +64,7 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
public async Task SynchronizeAsync_WhenTheInstalledThemesCannotBeRead_ShouldLogAndReturn()
|
||||
{
|
||||
// Arrange
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(shouldTrackEntities: true, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure("Themes.NotFound", "Failed to read the installed themes"));
|
||||
_mockThemeService.GetBundledThemeArchivePaths().Returns(["bundled.zip"]);
|
||||
|
||||
@@ -85,7 +81,7 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
{
|
||||
// Arrange
|
||||
_mockLogger.IsEnabled(Arg.Any<LogLevel>()).Returns(false);
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(shouldTrackEntities: true, cancellationToken: Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure("Themes.NotFound", "Failed to read the installed themes"));
|
||||
_mockThemeService.GetBundledThemeArchivePaths().Returns(["bundled.zip"]);
|
||||
|
||||
@@ -124,7 +120,7 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
// Arrange
|
||||
ThemeManifestDto manifest = _themeManifestDtoFixture.Create(version: "1.2.3");
|
||||
ThemeEntity installedTheme = _themeEntityFixture.Create(themeId: manifest.Id, version: "1.2.3", installSource: ThemeInstallSource.Bundled, isDeleted: false, includeIsCurrent: true, isCurrent: true);
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [installedTheme], currentPage: 1, perPage: 1, count: 1, numberOfPages: 1)));
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(shouldTrackEntities: true, cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [installedTheme], currentPage: 1, perPage: 1, count: 1, numberOfPages: 1)));
|
||||
_mockThemeService.GetBundledThemeArchivePaths().Returns(["bundled.zip"]);
|
||||
_mockThemeService.ReadManifestFromArchiveAsync("bundled.zip", Arg.Any<CancellationToken>()).Returns(Result.From(manifest));
|
||||
|
||||
@@ -143,7 +139,7 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
// Arrange
|
||||
ThemeManifestDto manifest = _themeManifestDtoFixture.Create(version: "2.0.0");
|
||||
ThemeEntity installedTheme = _themeEntityFixture.Create(themeId: manifest.Id, version: "1.0.0", installSource: ThemeInstallSource.Bundled, isDeleted: false, includeIsCurrent: true, isCurrent: true);
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [installedTheme], currentPage: 1, perPage: 1, count: 1, numberOfPages: 1)));
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(shouldTrackEntities: true, cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [installedTheme], currentPage: 1, perPage: 1, count: 1, numberOfPages: 1)));
|
||||
string archivePath = CreateArchiveFile();
|
||||
_mockThemeService.GetBundledThemeArchivePaths().Returns([archivePath]);
|
||||
_mockThemeService.ReadManifestFromArchiveAsync(archivePath, Arg.Any<CancellationToken>()).Returns(Result.From(manifest));
|
||||
@@ -164,7 +160,7 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
// Arrange
|
||||
ThemeManifestDto manifest = _themeManifestDtoFixture.Create();
|
||||
ThemeEntity deletedTheme = _themeEntityFixture.Create(themeId: manifest.Id, installSource: ThemeInstallSource.Bundled, isDeleted: true);
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [deletedTheme], currentPage: 1, perPage: 1, count: 1, numberOfPages: 1)));
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(shouldTrackEntities: true, cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [deletedTheme], currentPage: 1, perPage: 1, count: 1, numberOfPages: 1)));
|
||||
_mockThemeService.GetBundledThemeArchivePaths().Returns(["bundled.zip"]);
|
||||
_mockThemeService.ReadManifestFromArchiveAsync("bundled.zip", Arg.Any<CancellationToken>()).Returns(Result.From(manifest));
|
||||
|
||||
@@ -182,7 +178,7 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
// Arrange
|
||||
ThemeManifestDto manifest = _themeManifestDtoFixture.Create();
|
||||
ThemeEntity damagedTheme = _themeEntityFixture.Create(themeId: manifest.Id, installSource: ThemeInstallSource.Bundled, isDeleted: false, includeIsCurrent: true, isCurrent: true);
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [damagedTheme], currentPage: 1, perPage: 1, count: 1, numberOfPages: 1)));
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(shouldTrackEntities: true, cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [damagedTheme], currentPage: 1, perPage: 1, count: 1, numberOfPages: 1)));
|
||||
string archivePath = CreateArchiveFile();
|
||||
_mockThemeService.GetBundledThemeArchivePaths().Returns([archivePath]);
|
||||
// The first pack check happens before the repair and reports the files as missing; the later checks report the files as present.
|
||||
@@ -204,7 +200,7 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
// Arrange
|
||||
ThemeManifestDto manifest = _themeManifestDtoFixture.Create();
|
||||
ThemeEntity damagedTheme = _themeEntityFixture.Create(themeId: manifest.Id, installSource: ThemeInstallSource.Bundled, isDeleted: false, includeIsCurrent: true, isCurrent: true);
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [damagedTheme], currentPage: 1, perPage: 1, count: 1, numberOfPages: 1)));
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(shouldTrackEntities: true, cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [damagedTheme], currentPage: 1, perPage: 1, count: 1, numberOfPages: 1)));
|
||||
string archivePath = CreateArchiveFile();
|
||||
_mockThemeService.GetBundledThemeArchivePaths().Returns([archivePath]);
|
||||
_mockThemeService.HasThemePack(damagedTheme.ThemeId).Returns(false, true);
|
||||
@@ -309,7 +305,7 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
{
|
||||
// Arrange
|
||||
ThemeEntity healthyTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: false, includeIsCurrent: true, isCurrent: true);
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [healthyTheme], currentPage: 1, perPage: 1, count: 1, numberOfPages: 1)));
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(shouldTrackEntities: true, cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [healthyTheme], currentPage: 1, perPage: 1, count: 1, numberOfPages: 1)));
|
||||
|
||||
// Act
|
||||
await ThemeSynchronizer.SynchronizeAsync(_mockThemeService, _mockUnitOfWork, _mockLogger, CancellationToken.None);
|
||||
@@ -324,7 +320,7 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
{
|
||||
// Arrange
|
||||
ThemeEntity brokenTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: false, includeIsCurrent: true, isCurrent: true);
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [brokenTheme], currentPage: 1, perPage: 1, count: 1, numberOfPages: 1)));
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(shouldTrackEntities: true, cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [brokenTheme], currentPage: 1, perPage: 1, count: 1, numberOfPages: 1)));
|
||||
_mockThemeService.HasThemePack(brokenTheme.ThemeId).Returns(false);
|
||||
_mockThemeService.RestoreBundledThemeAsync(brokenTheme.ThemeId, Arg.Any<CancellationToken>()).Returns(Result.Success);
|
||||
|
||||
@@ -342,7 +338,7 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
{
|
||||
// Arrange
|
||||
ThemeEntity lastBundledTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: false, includeIsCurrent: true, isCurrent: true);
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [lastBundledTheme], currentPage: 1, perPage: 1, count: 1, numberOfPages: 1)));
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(shouldTrackEntities: true, cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [lastBundledTheme], currentPage: 1, perPage: 1, count: 1, numberOfPages: 1)));
|
||||
_mockThemeService.HasThemePack(lastBundledTheme.ThemeId).Returns(false);
|
||||
_mockThemeService.RestoreBundledThemeAsync(lastBundledTheme.ThemeId, Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure("Theme.Restore", "Failed to restore the theme"));
|
||||
@@ -361,7 +357,7 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
// Arrange
|
||||
ThemeEntity brokenBundledTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: false);
|
||||
ThemeEntity healthyBundledTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: false, includeIsCurrent: true, isCurrent: true);
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [brokenBundledTheme, healthyBundledTheme], currentPage: 1, perPage: 2, count: 2, numberOfPages: 1)));
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(shouldTrackEntities: true, cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [brokenBundledTheme, healthyBundledTheme], currentPage: 1, perPage: 2, count: 2, numberOfPages: 1)));
|
||||
_mockThemeService.HasThemePack(brokenBundledTheme.ThemeId).Returns(false);
|
||||
_mockThemeService.RestoreBundledThemeAsync(brokenBundledTheme.ThemeId, Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure("Theme.Restore", "Failed to restore the theme"));
|
||||
@@ -381,7 +377,7 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
// Arrange
|
||||
ThemeEntity brokenBundledTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: false);
|
||||
ThemeEntity healthyBundledTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: false, includeIsCurrent: true, isCurrent: true);
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [brokenBundledTheme, healthyBundledTheme], currentPage: 1, perPage: 2, count: 2, numberOfPages: 1)));
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(shouldTrackEntities: true, cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [brokenBundledTheme, healthyBundledTheme], currentPage: 1, perPage: 2, count: 2, numberOfPages: 1)));
|
||||
_mockThemeService.HasThemePack(brokenBundledTheme.ThemeId).Returns(false);
|
||||
_mockThemeService.RestoreBundledThemeAsync(brokenBundledTheme.ThemeId, Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure("Theme.Restore", "Failed to restore the theme"));
|
||||
@@ -401,7 +397,7 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
{
|
||||
// Arrange
|
||||
ThemeEntity brokenUserTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Uploaded, isDeleted: false, includeIsCurrent: true, isCurrent: true);
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [brokenUserTheme], currentPage: 1, perPage: 1, count: 1, numberOfPages: 1)));
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(shouldTrackEntities: true, cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [brokenUserTheme], currentPage: 1, perPage: 1, count: 1, numberOfPages: 1)));
|
||||
_mockThemeService.HasThemePack(brokenUserTheme.ThemeId).Returns(false);
|
||||
|
||||
// Act
|
||||
@@ -416,7 +412,7 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
{
|
||||
// Arrange
|
||||
ThemeEntity brokenUserTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Uploaded, isDeleted: false, includeIsCurrent: true, isCurrent: true);
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [brokenUserTheme], currentPage: 1, perPage: 1, count: 1, numberOfPages: 1)));
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(shouldTrackEntities: true, cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [brokenUserTheme], currentPage: 1, perPage: 1, count: 1, numberOfPages: 1)));
|
||||
_mockThemeService.HasThemePack(brokenUserTheme.ThemeId).Returns(false);
|
||||
_mockThemeRepository.DeleteByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure("Themes.DeleteFailed", "Failed to delete the theme"));
|
||||
@@ -435,7 +431,7 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
// Arrange
|
||||
ThemeEntity throwingBundledTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: false);
|
||||
ThemeEntity healthyBundledTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: false, includeIsCurrent: true, isCurrent: true);
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [throwingBundledTheme, healthyBundledTheme], currentPage: 1, perPage: 2, count: 2, numberOfPages: 1)));
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(shouldTrackEntities: true, cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [throwingBundledTheme, healthyBundledTheme], currentPage: 1, perPage: 2, count: 2, numberOfPages: 1)));
|
||||
_mockThemeService.HasThemePack(Arg.Any<string>()).Returns(false);
|
||||
_mockThemeService.RestoreBundledThemeAsync(throwingBundledTheme.ThemeId, Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromException<Result<Success>>(new InvalidOperationException("Unexpected failure")));
|
||||
@@ -456,7 +452,7 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
{
|
||||
// Arrange
|
||||
ThemeEntity brokenBundledTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: false);
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [brokenBundledTheme], currentPage: 1, perPage: 1, count: 1, numberOfPages: 1)));
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(shouldTrackEntities: true, cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [brokenBundledTheme], currentPage: 1, perPage: 1, count: 1, numberOfPages: 1)));
|
||||
_mockThemeService.HasThemePack(brokenBundledTheme.ThemeId).Returns(false);
|
||||
_mockThemeService.RestoreBundledThemeAsync(brokenBundledTheme.ThemeId, Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromException<Result<Success>>(new OperationCanceledException()));
|
||||
@@ -489,7 +485,7 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
updatedBy: Guid.NewGuid());
|
||||
DateTime? initialUpdatedOnUtc = installedTheme.UpdatedOnUtc;
|
||||
Guid? initialUpdatedBy = installedTheme.UpdatedBy;
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [installedTheme], currentPage: 1, perPage: 1, count: 1, numberOfPages: 1)));
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(shouldTrackEntities: true, cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [installedTheme], currentPage: 1, perPage: 1, count: 1, numberOfPages: 1)));
|
||||
string archivePath = CreateArchiveFile();
|
||||
_mockThemeService.GetBundledThemeArchivePaths().Returns([archivePath]);
|
||||
_mockThemeService.HasThemePack(installedTheme.ThemeId).Returns(true);
|
||||
@@ -515,7 +511,7 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
// Arrange
|
||||
ThemeManifestDto manifest = _themeManifestDtoFixture.Create(version: "3.0.0");
|
||||
ThemeEntity installedTheme = _themeEntityFixture.Create(themeId: manifest.Id, version: "1.0.0", installSource: ThemeInstallSource.Bundled, isDeleted: false, includeIsCurrent: true, isCurrent: true);
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [installedTheme], currentPage: 1, perPage: 1, count: 1, numberOfPages: 1)));
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(shouldTrackEntities: true, cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [installedTheme], currentPage: 1, perPage: 1, count: 1, numberOfPages: 1)));
|
||||
string archivePath = CreateArchiveFile();
|
||||
_mockThemeService.GetBundledThemeArchivePaths().Returns([archivePath]);
|
||||
_mockThemeService.HasThemePack(installedTheme.ThemeId).Returns(true);
|
||||
@@ -544,7 +540,7 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
// Arrange
|
||||
ThemeManifestDto manifest = _themeManifestDtoFixture.Create(version: "2.0.0");
|
||||
ThemeEntity uploadedTheme = _themeEntityFixture.Create(themeId: manifest.Id, version: "1.0.0", installSource: ThemeInstallSource.Uploaded, isDeleted: false, includeIsCurrent: true, isCurrent: true);
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [uploadedTheme], currentPage: 1, perPage: 1, count: 1, numberOfPages: 1)));
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(shouldTrackEntities: true, cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [uploadedTheme], currentPage: 1, perPage: 1, count: 1, numberOfPages: 1)));
|
||||
_mockThemeService.GetBundledThemeArchivePaths().Returns(["bundled.zip"]);
|
||||
_mockThemeService.HasThemePack(uploadedTheme.ThemeId).Returns(true);
|
||||
_mockThemeService.ReadManifestFromArchiveAsync("bundled.zip", Arg.Any<CancellationToken>()).Returns(Result.From(manifest));
|
||||
@@ -564,7 +560,7 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
// Arrange
|
||||
ThemeManifestDto manifest = _themeManifestDtoFixture.Create(version: "1.5.0");
|
||||
ThemeEntity installedTheme = _themeEntityFixture.Create(themeId: manifest.Id, version: "1.5.0", installSource: ThemeInstallSource.Bundled, isDeleted: false, includeIsCurrent: true, isCurrent: true);
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [installedTheme], currentPage: 1, perPage: 1, count: 1, numberOfPages: 1)));
|
||||
_mockThemeRepository.GetAllAsync<BaseFilterDto>(shouldTrackEntities: true, cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(_paginatedResultDtoFixture.Create(data: [installedTheme], currentPage: 1, perPage: 1, count: 1, numberOfPages: 1)));
|
||||
string archivePath = CreateArchiveFile();
|
||||
_mockThemeService.GetBundledThemeArchivePaths().Returns([archivePath]);
|
||||
_mockThemeService.HasThemePack(installedTheme.ThemeId).Returns(true);
|
||||
@@ -580,37 +576,35 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsureCurrentThemeExistsAsync_WhenANonDeletedThemeIsCurrent_ShouldNotSelectAnotherTheme()
|
||||
public void EnsureCurrentThemeExists_WhenANonDeletedThemeIsCurrent_ShouldNotSelectAnotherTheme()
|
||||
{
|
||||
// Arrange
|
||||
ThemeEntity currentTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: false, includeIsCurrent: true, isCurrent: true);
|
||||
ThemeEntity otherTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Uploaded, isDeleted: false);
|
||||
|
||||
// Act
|
||||
await InvokeEnsureCurrentThemeExistsAsync([currentTheme, otherTheme]);
|
||||
ThemeSynchronizer.EnsureCurrentThemeExists(_mockThemeService, [currentTheme, otherTheme]);
|
||||
|
||||
// Assert
|
||||
Assert.True(currentTheme.IsCurrent);
|
||||
Assert.NotEqual(true, otherTheme.IsCurrent);
|
||||
await _mockThemeRepository.DidNotReceive().UpdateAsync(Arg.Any<ThemeEntity>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsureCurrentThemeExistsAsync_WhenNoThemeCanBeSelected_ShouldNotSelectAnyTheme()
|
||||
public void EnsureCurrentThemeExists_WhenNoThemeCanBeSelected_ShouldNotSelectAnyTheme()
|
||||
{
|
||||
// Arrange
|
||||
ThemeEntity deletedTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: true);
|
||||
|
||||
// Act
|
||||
await InvokeEnsureCurrentThemeExistsAsync([deletedTheme]);
|
||||
ThemeSynchronizer.EnsureCurrentThemeExists(_mockThemeService, [deletedTheme]);
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(true, deletedTheme.IsCurrent);
|
||||
await _mockThemeRepository.DidNotReceive().UpdateAsync(Arg.Any<ThemeEntity>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsureCurrentThemeExistsAsync_WhenNoThemeIsCurrent_ShouldActivateTheDefaultTheme()
|
||||
public void EnsureCurrentThemeExists_WhenNoThemeIsCurrent_ShouldActivateTheDefaultTheme()
|
||||
{
|
||||
// Arrange
|
||||
ThemeEntity defaultTheme = _themeEntityFixture.Create(themeId: "nemera-default", installSource: ThemeInstallSource.Bundled, isDeleted: false);
|
||||
@@ -619,35 +613,33 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
_mockThemeService.HasThemePack(userTheme.ThemeId).Returns(false);
|
||||
|
||||
// Act
|
||||
await InvokeEnsureCurrentThemeExistsAsync([userTheme, defaultTheme]);
|
||||
ThemeSynchronizer.EnsureCurrentThemeExists(_mockThemeService, [userTheme, defaultTheme]);
|
||||
|
||||
// Assert
|
||||
Assert.True(defaultTheme.IsCurrent);
|
||||
await _mockThemeRepository.Received(1).UpdateAsync(Arg.Is<ThemeEntity>(theme => theme.Id == defaultTheme.Id), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsureCurrentThemeExistsAsync_WhenActivatingTheDefaultThemeFails_ShouldLogAndNotThrow()
|
||||
public async Task SynchronizeAsync_WhenANewBundledThemeIsInstalled_ShouldMarkTheInsertedThemeCurrentWithoutUpdatingIt()
|
||||
{
|
||||
// Arrange
|
||||
ThemeEntity defaultTheme = _themeEntityFixture.Create(themeId: "nemera-default", installSource: ThemeInstallSource.Bundled, isDeleted: false);
|
||||
_mockThemeService.HasThemePack(defaultTheme.ThemeId).Returns(true);
|
||||
_mockThemeRepository.UpdateAsync(Arg.Any<ThemeEntity>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Error.Failure("Themes.UpdateFailed", "Failed to activate the theme"));
|
||||
ThemeManifestDto manifest = _themeManifestDtoFixture.Create();
|
||||
string archivePath = CreateArchiveFile();
|
||||
_mockThemeService.GetBundledThemeArchivePaths().Returns([archivePath]);
|
||||
_mockThemeService.ReadManifestFromArchiveAsync(archivePath, Arg.Any<CancellationToken>()).Returns(Result.From(manifest));
|
||||
_mockThemeService.InstallAsync(Arg.Any<Stream>(), Arg.Any<CancellationToken>()).Returns(Result.From(manifest));
|
||||
ThemeEntity? insertedTheme = null;
|
||||
_mockThemeRepository.InsertAsync(Arg.Do<ThemeEntity>(theme => insertedTheme = theme), Arg.Any<CancellationToken>()).Returns(Result.Created);
|
||||
|
||||
// Act
|
||||
await InvokeEnsureCurrentThemeExistsAsync([defaultTheme]);
|
||||
await ThemeSynchronizer.SynchronizeAsync(_mockThemeService, _mockUnitOfWork, _mockLogger, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(defaultTheme.IsCurrent);
|
||||
await _mockThemeRepository.Received(1).UpdateAsync(Arg.Is<ThemeEntity>(theme => theme.Id == defaultTheme.Id), Arg.Any<CancellationToken>());
|
||||
// A failed activation must not be silent, so it is logged instead of being discarded.
|
||||
_mockLogger.Received(1).Log(
|
||||
LogLevel.Warning,
|
||||
Arg.Any<EventId>(),
|
||||
Arg.Any<object>(),
|
||||
Arg.Any<Exception?>(),
|
||||
Arg.Any<Func<object, Exception?, string>>());
|
||||
Assert.NotNull(insertedTheme);
|
||||
Assert.True(insertedTheme!.IsCurrent);
|
||||
// A theme inserted in this synchronization is not in the database yet, so UpdateAsync would fail with ThemeNotFound.
|
||||
await _mockThemeRepository.DidNotReceive().UpdateAsync(Arg.Any<ThemeEntity>(), Arg.Any<CancellationToken>());
|
||||
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -661,19 +653,6 @@ public class ThemeSynchronizerTests : IDisposable
|
||||
return archivePath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invokes the private <c>EnsureCurrentThemeExistsAsync</c> method of the synchronizer.
|
||||
/// </summary>
|
||||
/// <param name="themes">The installed themes passed to the method.</param>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
private async Task InvokeEnsureCurrentThemeExistsAsync(IReadOnlyList<ThemeEntity> themes)
|
||||
{
|
||||
MethodInfo method = typeof(ThemeSynchronizer).GetMethod("EnsureCurrentThemeExistsAsync", BindingFlags.Static | BindingFlags.NonPublic)
|
||||
?? throw new InvalidOperationException("The method 'EnsureCurrentThemeExistsAsync' was not found on the theme synchronizer.");
|
||||
Task task = (Task)method.Invoke(null, [_mockThemeService, _mockUnitOfWork, themes, _mockLogger, CancellationToken.None])!;
|
||||
await task.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes the temporary files created by the tests.
|
||||
/// </summary>
|
||||
|
||||
Reference in new issue
Block a user