Skip to content

Commit

Permalink
Merge pull request #1 from Lombiq/issue/NEST-339
Browse files Browse the repository at this point in the history
NEST-339: Feature to make build number visible after deployment
  • Loading branch information
wAsnk committed Jan 6, 2023
2 parents f76fda7 + d109aa6 commit 00847bb
Show file tree
Hide file tree
Showing 20 changed files with 358 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ wwwroot/
node_modules/
*.user
.pnpm-debug.log
.editorconfig

# Mac
.DS_Store
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// Tests the Lombiq Hosting - Build Version Display for Orchard Core feature.
/// </summary>
/// <remarks>
/// <para>
/// <paramref name="checkBuildLink"/> 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.
/// </para>
/// </remarks>
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"));
}
}
}
13 changes: 13 additions & 0 deletions Lombiq.Hosting.BuildVersionDisplay.Tests.UI/License.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<DefaultItemExcludes>$(DefaultItemExcludes);.git*;node_modules\**</DefaultItemExcludes>
</PropertyGroup>

<PropertyGroup>
<Title>Lombiq Hosting - Build Version Display for Orchard Core - UI Test Extensions</Title>
<Authors>Lombiq Technologies</Authors>
<Copyright>Copyright © 2023, Lombiq Technologies Ltd.</Copyright>
<Description>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.</Description>
<PackageIcon>NuGetIcon.png</PackageIcon>
<PackageTags>OrchardCore;Lombiq;AspNetCore;CodeGeneration;ShapeTracing;Widgets</PackageTags>
<RepositoryUrl>https://github.com/Lombiq/Hosting-Build-Version-Display</RepositoryUrl>
<PackageProjectUrl>
https://github.com/Lombiq/Hosting-Build-Version-Display/tree/dev/Lombiq.Hosting.BuildVersionDisplay.Tests.UI</PackageProjectUrl>
<PackageLicenseFile>License.md</PackageLicenseFile>
</PropertyGroup>

<ItemGroup>
<None Include="License.md" Pack="true" PackagePath="" />
<None Include="Readme.md" />
<None Include="NuGetIcon.png" Pack="true" PackagePath="" />
</ItemGroup>

<ItemGroup>
<None Remove="node_modules\**" />
<None Remove="Tests\**" />
</ItemGroup>

<ItemGroup Condition="'$(NuGetBuild)' != 'true'">
<ProjectReference Include="..\..\..\..\test\Lombiq.UITestingToolbox\Lombiq.Tests.UI\Lombiq.Tests.UI.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(NuGetBuild)' == 'true'">
<PackageReference Include="Lombiq.Tests.UI" Version="5.0.0" />
</ItemGroup>

</Project>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions Lombiq.Hosting.BuildVersionDisplay.Tests.UI/Readme.md
Original file line number Diff line number Diff line change
@@ -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).
31 changes: 31 additions & 0 deletions Lombiq.Hosting.BuildVersionDisplay.sln
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions Lombiq.Hosting.BuildVersionDisplay/BuildUrlAttribute.cs
Original file line number Diff line number Diff line change
@@ -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;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -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> _adminOptions;

public BuildVersionDisplayInjectingFilter(
ILayoutAccessor layoutAccessor,
IShapeFactory shapeFactory,
IOptions<AdminOptions> 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();
}
}
13 changes: 13 additions & 0 deletions Lombiq.Hosting.BuildVersionDisplay/License.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<DefaultItemExcludes>$(DefaultItemExcludes);.git*;node_modules\**</DefaultItemExcludes>
</PropertyGroup>

<PropertyGroup>
<Title>Lombiq Hosting - Build Version Display for Orchard Core</Title>
<Authors>Lombiq Technologies</Authors>
<Copyright>Copyright © 2023, Lombiq Technologies Ltd.</Copyright>
<Description>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.</Description>
<PackageIcon>NuGetIcon.png</PackageIcon>
<PackageTags>OrchardCore;Lombiq;AspNetCore;Hosting;</PackageTags>
<RepositoryUrl>https://github.com/Lombiq/Hosting-Build-Version-Display</RepositoryUrl>
<PackageProjectUrl>https://github.com/Lombiq/Hosting-Build-Version-Display</PackageProjectUrl>
<PackageLicenseFile>License.md</PackageLicenseFile>
</PropertyGroup>

<ItemGroup>
<None Include="License.md" Pack="true" PackagePath="" />
<None Include="NuGetIcon.png" Pack="true" PackagePath="" />
<!-- If this is not explicitly specified then OrchardCore.Module.Targets will take over the build folder and it
won't be included. -->
<None Include="build\Lombiq.Hosting.BuildVersionDisplay.targets" Pack="true" PackagePath="build\Lombiq.Hosting.BuildVersionDisplay.targets" />
</ItemGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="OrchardCore.Module.Targets" Version="1.5.0" />
<PackageReference Include="OrchardCore.DisplayManagement" Version="1.5.0" />
</ItemGroup>

<ItemGroup>
<None Include="..\Readme.md" Link="Readme.md" />
</ItemGroup>

<ItemGroup>
<None Remove="node_modules\**" />
<None Remove="Tests\**" />
</ItemGroup>

<ItemGroup Condition="'$(NuGetBuild)' != 'true'">
<ProjectReference Include="..\..\..\Libraries\Lombiq.HelpfulLibraries\Lombiq.HelpfulLibraries.OrchardCore\Lombiq.HelpfulLibraries.OrchardCore.csproj" />
</ItemGroup>

<ItemGroup Condition="'$(NuGetBuild)' == 'true'">
<PackageReference Include="Lombiq.HelpfulLibraries.OrchardCore" Version="5.0.0" />
</ItemGroup>

<!-- The targets file will be automatically imported when using the project from NuGet but needs an explicit import
when used from source. -->
<Import Project="build/Lombiq.Hosting.BuildVersionDisplay.targets" Condition="'$(NuGetBuild)' != 'true'" />

</Project>
11 changes: 11 additions & 0 deletions Lombiq.Hosting.BuildVersionDisplay/Manifest.cs
Original file line number Diff line number Diff line change
@@ -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
)]
Binary file added Lombiq.Hosting.BuildVersionDisplay/NuGetIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions Lombiq.Hosting.BuildVersionDisplay/Startup.cs
Original file line number Diff line number Diff line change
@@ -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<MvcOptions>((options) => options.Filters.Add(typeof(BuildVersionDisplayInjectingFilter)));
}
40 changes: 40 additions & 0 deletions Lombiq.Hosting.BuildVersionDisplay/Views/BuildVersion.cshtml
Original file line number Diff line number Diff line change
@@ -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<BuildUrlAttribute>();
var buildUrl = webAppAttribute?.Url;
if (string.IsNullOrEmpty(buildUrl))
{
var moduleAttribute = Assembly.GetExecutingAssembly().GetCustomAttribute<BuildUrlAttribute>();
buildUrl = moduleAttribute?.Url;
}
}

<div id="lombiq-hosting-build-version-display-build-version">
@T["Build versions:"]
<ul>
<li>
@T["Orchard Core version: {0}", orchardVersion]
</li>
<li>
@T["App build version: {0}", buildVersion]
</li>
@if (!string.IsNullOrEmpty(buildUrl))
{
<li>
@T["<a href=\"{0}\" target=\"_blank\">Build link</a>", buildUrl]
</li>
}
</ul>
</div>
6 changes: 6 additions & 0 deletions Lombiq.Hosting.BuildVersionDisplay/Views/_ViewImports.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@inherits OrchardCore.DisplayManagement.Razor.RazorPage<TModel>

@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, OrchardCore.Contents.TagHelpers
@addTagHelper *, OrchardCore.DisplayManagement
@addTagHelper *, OrchardCore.ResourceManagement
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!-- This should rather be a props file, but those are overwritten by Orchard's Package.Build.props for modules. -->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<!-- Setting a test value just when working in the OSOCE solution. -->
<PropertyGroup Condition="'$(BuildUrl)' == '' AND '$(SolutionName)' == 'Lombiq.OSOCE'" >
<BuildVersionDisplay_BuildUrl>
https://github.com/Lombiq/Open-Source-Orchard-Core-Extensions/actions/runs/123
</BuildVersionDisplay_BuildUrl>
</PropertyGroup>

<ItemGroup>
<AssemblyAttribute Include="Lombiq.Hosting.BuildVersionDisplay.BuildUrlAttribute">
<_Parameter1>$(BuildVersionDisplay_BuildUrl)</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

</Project>
18 changes: 15 additions & 3 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
# Lombiq <add project name here>
# 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

Expand Down

0 comments on commit 00847bb

Please sign in to comment.