diff --git a/.github/workflows/create-jira-issues-for-community-activities.yml b/.github/workflows/create-jira-issues-for-community-activities.yml index c2cc3ec..4643070 100644 --- a/.github/workflows/create-jira-issues-for-community-activities.yml +++ b/.github/workflows/create-jira-issues-for-community-activities.yml @@ -20,4 +20,4 @@ jobs: ISSUE_JIRA_ISSUE_DESCRIPTION: ${{ secrets.DEFAULT_ISSUE_JIRA_ISSUE_DESCRIPTION }} PULL_REQUEST_JIRA_ISSUE_DESCRIPTION: ${{ secrets.DEFAULT_PULL_REQUEST_JIRA_ISSUE_DESCRIPTION }} with: - issue-component: Lombiq.MyProject + issue-component: Lombiq.Hosting.BuildVersionDisplay diff --git a/.gitignore b/.gitignore index 403cc7f..c3c8ab2 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ wwwroot/ node_modules/ *.user .pnpm-debug.log +.editorconfig # Mac .DS_Store diff --git a/Lombiq.Hosting.BuildVersionDisplay.Tests.UI/Extensions/TestCaseUITestContextExtensions.cs b/Lombiq.Hosting.BuildVersionDisplay.Tests.UI/Extensions/TestCaseUITestContextExtensions.cs new file mode 100644 index 0000000..a4fbf40 --- /dev/null +++ b/Lombiq.Hosting.BuildVersionDisplay.Tests.UI/Extensions/TestCaseUITestContextExtensions.cs @@ -0,0 +1,39 @@ +using Atata; +using Lombiq.Tests.UI.Extensions; +using Lombiq.Tests.UI.Services; +using OpenQA.Selenium; +using Shouldly; +using System.Threading.Tasks; + +namespace Lombiq.Hosting.BuildVersionDisplay.Tests.UI.Extensions; + +public static class TestCaseUITestContextExtensions +{ + /// + /// Tests the Lombiq Hosting - Build Version Display for Orchard Core feature. + /// + /// + /// + /// defaults to false since the build link won't be displayed when the tests are + /// run from a published UI test project (it displays properly when run from source). This is because the UI test + /// project doesn't (shouldn't) reference the module project/package directly and thus won't use its targets file + /// either, breaking the BuildVersionDisplay_BuildUrl property. This is not an error, the link is still displayed + /// when the web app is run directly. + /// + /// + public static async Task TestBuildVersionDisplayAsync(this UITestContext context, bool checkBuildLink = false) + { + await context.SignInDirectlyAndGoToDashboardAsync(); + + var container = context.Get(By.Id("lombiq-hosting-build-version-display-build-version")); + var listItems = container.GetAll(By.TagName("li")); + + var orchardVersion = typeof(OrchardCore.IOrchardHelper).Assembly.GetName().Version.ToString(); + listItems.ShouldContain(element => element.Text == "Orchard Core version: " + orchardVersion); + listItems.ShouldContain(element => element.Text.Contains("App build version")); + if (checkBuildLink) + { + listItems.ShouldContain(element => element.Text.Contains("Build link")); + } + } +} diff --git a/Lombiq.Hosting.BuildVersionDisplay.Tests.UI/License.md b/Lombiq.Hosting.BuildVersionDisplay.Tests.UI/License.md new file mode 100644 index 0000000..4add106 --- /dev/null +++ b/Lombiq.Hosting.BuildVersionDisplay.Tests.UI/License.md @@ -0,0 +1,13 @@ +Copyright © 2023, [Lombiq Technologies Ltd.](https://lombiq.com) + +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +- Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/Lombiq.Hosting.BuildVersionDisplay.Tests.UI/Lombiq.Hosting.BuildVersionDisplay.Tests.UI.csproj b/Lombiq.Hosting.BuildVersionDisplay.Tests.UI/Lombiq.Hosting.BuildVersionDisplay.Tests.UI.csproj new file mode 100644 index 0000000..98e3f0b --- /dev/null +++ b/Lombiq.Hosting.BuildVersionDisplay.Tests.UI/Lombiq.Hosting.BuildVersionDisplay.Tests.UI.csproj @@ -0,0 +1,40 @@ + + + + net6.0 + $(DefaultItemExcludes);.git*;node_modules\** + + + + Lombiq Hosting - Build Version Display for Orchard Core - UI Test Extensions + Lombiq Technologies + Copyright © 2023, Lombiq Technologies Ltd. + Lombiq Hosting - Build Version Display for Orchard Core - UI Test Extensions: Extension methods that test various features in Lombiq Hosting - Build Version Display for Orchard Core. + NuGetIcon.png + OrchardCore;Lombiq;AspNetCore;CodeGeneration;ShapeTracing;Widgets + https://github.com/Lombiq/Hosting-Build-Version-Display + + https://github.com/Lombiq/Hosting-Build-Version-Display/tree/dev/Lombiq.Hosting.BuildVersionDisplay.Tests.UI + License.md + + + + + + + + + + + + + + + + + + + + + + diff --git a/Lombiq.Hosting.BuildVersionDisplay.Tests.UI/NuGetIcon.png b/Lombiq.Hosting.BuildVersionDisplay.Tests.UI/NuGetIcon.png new file mode 100644 index 0000000..162a005 Binary files /dev/null and b/Lombiq.Hosting.BuildVersionDisplay.Tests.UI/NuGetIcon.png differ diff --git a/Lombiq.Hosting.BuildVersionDisplay.Tests.UI/Readme.md b/Lombiq.Hosting.BuildVersionDisplay.Tests.UI/Readme.md new file mode 100644 index 0000000..3ddfd12 --- /dev/null +++ b/Lombiq.Hosting.BuildVersionDisplay.Tests.UI/Readme.md @@ -0,0 +1,7 @@ +# Lombiq Hosting - Build Version Display for Orchard Core - UI Test Extensions + +## About + +Extension methods that test various features in Lombiq Hosting - Build Version Display for Orchard Core, with the help of [Lombiq UI Testing Toolbox for Orchard Core](https://github.com/Lombiq/UI-Testing-Toolbox). + +Call these from a UI test project to verify the module's basic features; as seen in [Open-Source Orchard Core Extensions](https://github.com/Lombiq/Open-Source-Orchard-Core-Extensions). diff --git a/Lombiq.Hosting.BuildVersionDisplay.sln b/Lombiq.Hosting.BuildVersionDisplay.sln new file mode 100644 index 0000000..ac3dd25 --- /dev/null +++ b/Lombiq.Hosting.BuildVersionDisplay.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.32126.317 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lombiq.Hosting.BuildVersionDisplay", "Lombiq.Hosting.BuildVersionDisplay\Lombiq.Hosting.BuildVersionDisplay.csproj", "{5843E46D-03E5-4B44-9731-72AC32A0FCAC}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lombiq.Hosting.BuildVersionDisplay.Tests.UI", "Lombiq.Hosting.BuildVersionDisplay.Tests.UI\Lombiq.Hosting.BuildVersionDisplay.Tests.UI.csproj", "{C2687772-E673-45F3-BA74-50A3DB739124}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5843E46D-03E5-4B44-9731-72AC32A0FCAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5843E46D-03E5-4B44-9731-72AC32A0FCAC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5843E46D-03E5-4B44-9731-72AC32A0FCAC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5843E46D-03E5-4B44-9731-72AC32A0FCAC}.Release|Any CPU.Build.0 = Release|Any CPU + {C2687772-E673-45F3-BA74-50A3DB739124}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C2687772-E673-45F3-BA74-50A3DB739124}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C2687772-E673-45F3-BA74-50A3DB739124}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C2687772-E673-45F3-BA74-50A3DB739124}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {90B82673-1604-4EEE-B74E-11AE2B4AD8D3} + EndGlobalSection +EndGlobal diff --git a/Lombiq.Hosting.BuildVersionDisplay/BuildUrlAttribute.cs b/Lombiq.Hosting.BuildVersionDisplay/BuildUrlAttribute.cs new file mode 100644 index 0000000..65e43b2 --- /dev/null +++ b/Lombiq.Hosting.BuildVersionDisplay/BuildUrlAttribute.cs @@ -0,0 +1,9 @@ +namespace Lombiq.Hosting.BuildVersionDisplay; + +[AttributeUsage(AttributeTargets.Assembly)] +public sealed class BuildUrlAttribute : Attribute +{ + public string? Url { get; } + + public BuildUrlAttribute(string? url) => Url = url; +} diff --git a/Lombiq.Hosting.BuildVersionDisplay/Docs/Attachments/Screenshot.png b/Lombiq.Hosting.BuildVersionDisplay/Docs/Attachments/Screenshot.png new file mode 100644 index 0000000..836c429 Binary files /dev/null and b/Lombiq.Hosting.BuildVersionDisplay/Docs/Attachments/Screenshot.png differ diff --git a/Lombiq.Hosting.BuildVersionDisplay/Filters/BuildVersionDisplayInjectingFilter.cs b/Lombiq.Hosting.BuildVersionDisplay/Filters/BuildVersionDisplayInjectingFilter.cs new file mode 100644 index 0000000..826f31f --- /dev/null +++ b/Lombiq.Hosting.BuildVersionDisplay/Filters/BuildVersionDisplayInjectingFilter.cs @@ -0,0 +1,42 @@ +using Microsoft.AspNetCore.Mvc.Filters; +using Microsoft.Extensions.Options; +using OrchardCore.Admin; +using OrchardCore.DisplayManagement; +using OrchardCore.DisplayManagement.Layout; + +namespace Lombiq.Hosting.BuildVersionDisplay.Filters; + +internal class BuildVersionDisplayInjectingFilter : IAsyncResultFilter +{ + private readonly ILayoutAccessor _layoutAccessor; + private readonly IShapeFactory _shapeFactory; + private readonly IOptions _adminOptions; + + public BuildVersionDisplayInjectingFilter( + ILayoutAccessor layoutAccessor, + IShapeFactory shapeFactory, + IOptions adminOptions) + { + _layoutAccessor = layoutAccessor; + _shapeFactory = shapeFactory; + _adminOptions = adminOptions; + } + + public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next) + { + if (context.IsNotFullViewRendering() || + !context.IsAdmin() || + !context.HttpContext.Request.Path.ToString().TrimEnd('/').EqualsOrdinalIgnoreCase("/" + _adminOptions.Value.AdminUrlPrefix)) + { + await next(); + + return; + } + + var layout = await _layoutAccessor.GetLayoutAsync(); + var zone = layout.Zones["Content"]; + await zone.AddAsync(await _shapeFactory.CreateAsync("BuildVersion"), ":after"); + + await next(); + } +} diff --git a/Lombiq.Hosting.BuildVersionDisplay/License.md b/Lombiq.Hosting.BuildVersionDisplay/License.md new file mode 100644 index 0000000..4add106 --- /dev/null +++ b/Lombiq.Hosting.BuildVersionDisplay/License.md @@ -0,0 +1,13 @@ +Copyright © 2023, [Lombiq Technologies Ltd.](https://lombiq.com) + +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +- Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/Lombiq.Hosting.BuildVersionDisplay/Lombiq.Hosting.BuildVersionDisplay.csproj b/Lombiq.Hosting.BuildVersionDisplay/Lombiq.Hosting.BuildVersionDisplay.csproj new file mode 100644 index 0000000..455e726 --- /dev/null +++ b/Lombiq.Hosting.BuildVersionDisplay/Lombiq.Hosting.BuildVersionDisplay.csproj @@ -0,0 +1,61 @@ + + + + net6.0 + true + enable + enable + $(DefaultItemExcludes);.git*;node_modules\** + + + + Lombiq Hosting - Build Version Display for Orchard Core + Lombiq Technologies + Copyright © 2023, Lombiq Technologies Ltd. + Lombiq Hosting - Build Version Display for Orchard Core: Orchard Core module to display the build version (i.e. .NET assembly version or other) on the admin of the Default tenant. See the project website for detailed documentation. + NuGetIcon.png + OrchardCore;Lombiq;AspNetCore;Hosting; + https://github.com/Lombiq/Hosting-Build-Version-Display + https://github.com/Lombiq/Hosting-Build-Version-Display + License.md + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Lombiq.Hosting.BuildVersionDisplay/Manifest.cs b/Lombiq.Hosting.BuildVersionDisplay/Manifest.cs new file mode 100644 index 0000000..ce4fcbb --- /dev/null +++ b/Lombiq.Hosting.BuildVersionDisplay/Manifest.cs @@ -0,0 +1,11 @@ +using OrchardCore.Modules.Manifest; + +[assembly: Module( + Name = "Lombiq Hosting - Build Version Display", + Author = "Lombiq Technologies", + Website = "https://github.com/Lombiq/Hosting-Build-Version-Display", + Version = "0.0.1", + Description = "Displays the build version (i.e. .NET assembly version or other) on the admin.", + Category = "Hosting", + DefaultTenantOnly = true +)] diff --git a/Lombiq.Hosting.BuildVersionDisplay/NuGetIcon.png b/Lombiq.Hosting.BuildVersionDisplay/NuGetIcon.png new file mode 100644 index 0000000..162a005 Binary files /dev/null and b/Lombiq.Hosting.BuildVersionDisplay/NuGetIcon.png differ diff --git a/Lombiq.Hosting.BuildVersionDisplay/Startup.cs b/Lombiq.Hosting.BuildVersionDisplay/Startup.cs new file mode 100644 index 0000000..d62f006 --- /dev/null +++ b/Lombiq.Hosting.BuildVersionDisplay/Startup.cs @@ -0,0 +1,12 @@ +using Lombiq.Hosting.BuildVersionDisplay.Filters; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.DependencyInjection; +using OrchardCore.Modules; + +namespace Lombiq.Hosting.BuildVersionDisplay; + +public class Startup : StartupBase +{ + public override void ConfigureServices(IServiceCollection services) => + services.Configure((options) => options.Filters.Add(typeof(BuildVersionDisplayInjectingFilter))); +} diff --git a/Lombiq.Hosting.BuildVersionDisplay/Views/BuildVersion.cshtml b/Lombiq.Hosting.BuildVersionDisplay/Views/BuildVersion.cshtml new file mode 100644 index 0000000..f4efc01 --- /dev/null +++ b/Lombiq.Hosting.BuildVersionDisplay/Views/BuildVersion.cshtml @@ -0,0 +1,40 @@ +@using System.Reflection; +@using Lombiq.Hosting.BuildVersionDisplay; + +@{ + var webAppAssembly = Assembly.GetEntryAssembly(); + + // These can't be null as long as the code actually compiles. +#pragma warning disable CS8602 // Dereference of a possibly null reference. + var orchardVersion = typeof(OrchardCore.IOrchardHelper).Assembly.GetName().Version.ToString(); + var buildVersion = webAppAssembly.GetName().Version.ToString(); +#pragma warning restore CS8602 // Dereference of a possibly null reference. + + // When using the module from from NuGet the web app's binaries will contain the attribute, when using it from + // source, the module's. + var webAppAttribute = webAppAssembly.GetCustomAttribute(); + var buildUrl = webAppAttribute?.Url; + if (string.IsNullOrEmpty(buildUrl)) + { + var moduleAttribute = Assembly.GetExecutingAssembly().GetCustomAttribute(); + buildUrl = moduleAttribute?.Url; + } +} + +
+ @T["Build versions:"] +
    +
  • + @T["Orchard Core version: {0}", orchardVersion] +
  • +
  • + @T["App build version: {0}", buildVersion] +
  • + @if (!string.IsNullOrEmpty(buildUrl)) + { +
  • + @T["Build link", buildUrl] +
  • + } +
+
diff --git a/Lombiq.Hosting.BuildVersionDisplay/Views/_ViewImports.cshtml b/Lombiq.Hosting.BuildVersionDisplay/Views/_ViewImports.cshtml new file mode 100644 index 0000000..6d1d688 --- /dev/null +++ b/Lombiq.Hosting.BuildVersionDisplay/Views/_ViewImports.cshtml @@ -0,0 +1,6 @@ +@inherits OrchardCore.DisplayManagement.Razor.RazorPage + +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers +@addTagHelper *, OrchardCore.Contents.TagHelpers +@addTagHelper *, OrchardCore.DisplayManagement +@addTagHelper *, OrchardCore.ResourceManagement diff --git a/Lombiq.Hosting.BuildVersionDisplay/build/Lombiq.Hosting.BuildVersionDisplay.targets b/Lombiq.Hosting.BuildVersionDisplay/build/Lombiq.Hosting.BuildVersionDisplay.targets new file mode 100644 index 0000000..a19f14a --- /dev/null +++ b/Lombiq.Hosting.BuildVersionDisplay/build/Lombiq.Hosting.BuildVersionDisplay.targets @@ -0,0 +1,17 @@ + + + + + + + https://github.com/Lombiq/Open-Source-Orchard-Core-Extensions/actions/runs/123 + + + + + + <_Parameter1>$(BuildVersionDisplay_BuildUrl) + + + + diff --git a/Readme.md b/Readme.md index e11865b..9d25a76 100644 --- a/Readme.md +++ b/Readme.md @@ -1,14 +1,26 @@ -# Lombiq +# Lombiq Hosting - Build Version Display for Orchard Core + +[![Lombiq.Hosting.BuildVersionDisplay NuGet](https://img.shields.io/nuget/v/Lombiq.Hosting.BuildVersionDisplay?label=Lombiq.Hosting.BuildVersionDisplay)](https://www.nuget.org/packages/Lombiq.Hosting.BuildVersionDisplay/) ## About -Add a general overview of the project here. Keep or remove the OSOCE note below as necessary. +[Orchard Core](https://www.orchardcore.net/) module to display the build version (i.e. .NET assembly version or other) on the admin of the `Default` tenant. This is useful to see at a glance which version of the app you have deployed currently to the given environment. You can also display a link to the CI build's page. + +![Screenshot of Build Version Display on the Orchard Core dashboard](Lombiq.Hosting.BuildVersionDisplay/Docs/Attachments/Screenshot.png) Do you want to quickly try out this project and see it in action? Check it out in our [Open-Source Orchard Core Extensions](https://github.com/Lombiq/Open-Source-Orchard-Core-Extensions) full Orchard Core solution and also see our other useful Orchard Core-related open-source projects! ## Documentation -Add detailed documentation here. If it's a lot of content then create documentation pages under the *Docs* folder and link pages here. +Just enable the "Lombiq Hosting - Build Version Display" feature on the `Default` tenant to display the Orchard Core version and the app's .NET version on the dashboard (i.e. _/admin_). + +Optionally, a link to the CI build's page can be display as well. During `dotnet build`, provide this in the `BuildVersionDisplay_BuildUrl` property. E.g.: + +```pwsh +dotnet build .\MyApp.sln -p:BuildVersionDisplay_BuildUrl=https://github.com/Lombiq/Open-Source-Orchard-Core-Extensions/actions/runs/123 +``` + +The [Deploy to Azure App Service workflow](https://github.com/Lombiq/GitHub-Actions/blob/dev/Docs/Workflows.md#deploy-to-azure-app-service-workflow) also takes care of this. ## Contributing and support