Display generated version number on the designer (#3923)

* Implemented get version endpoint

* Get version from backend to display on designer

* Updated github pipelines

---------

Co-authored-by: Gürkan Güran <gguran@interfirst.com>
This commit is contained in:
gurkanguran 2023-04-18 21:29:55 +02:00 committed by GitHub
parent 3eb304e1ec
commit ecb95cc35d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 80 additions and 2 deletions

View file

@ -166,6 +166,7 @@ jobs:
name: Update Version in Elsa.Workflows.Designer backend module
needs: publish_npm_preview
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/v3' }}
steps:
- name: Install jq
run: sudo apt-get install jq

View file

@ -5,6 +5,7 @@ import {EventBus} from '../../../services';
import toolbarComponentStore from "../../../data/toolbar-component-store";
import notificationService from '../../../modules/notifications/notification-service';
import notificationStore from "../../../modules/notifications/notification-store";
import {PackagesApi} from "../../../services/api-client/packages-api";
@Component({
tag: 'elsa-workflow-toolbar',
@ -12,11 +13,20 @@ import notificationStore from "../../../modules/notifications/notification-store
})
export class WorkflowToolbar {
private readonly eventBus: EventBus;
private readonly packagesApi: PackagesApi;
private currentElsaVersion: string;
static NotificationService = notificationService;
constructor() {
this.eventBus = Container.get(EventBus);
this.packagesApi = Container.get(PackagesApi);
}
async componentDidLoad() {
var response = await this.packagesApi.getVersion();
return this.currentElsaVersion = response.packageVersion;
}
onNotificationClick = async e => {
@ -28,7 +38,7 @@ export class WorkflowToolbar {
render() {
const logoPath = getAssetPath('./assets/logo.png');
const infoPanelBoolean = notificationStore.infoPanelBoolean;
return (
<div>
<nav class="bg-gray-800">
@ -41,7 +51,7 @@ export class WorkflowToolbar {
<a href="#"><img class="h-6 w-6" src={logoPath} alt="Workflow"/></a>
</div>
<div>
<span class="text-gray-300 text-sm">elsa 3.0.0</span>
<span class="text-gray-300 text-sm">{this.currentElsaVersion}</span>
</div>
</div>
</div>

View file

@ -79,3 +79,7 @@ export interface WorkflowActivationStrategyDescriptor {
description: string;
typeName: string;
}
export interface PackageVersion {
packageVersion: string;
}

View file

@ -0,0 +1,20 @@
import {Service} from "typedi";
import {ElsaClientProvider} from "./elsa-client";
import { PackageVersion } from "../../models";
@Service()
export class PackagesApi {
private provider: ElsaClientProvider;
constructor(provider: ElsaClientProvider) {
this.provider = provider;
}
async getVersion(): Promise<PackageVersion> {
const httpClient = await this.getHttpClient();
const response = await httpClient.get<PackageVersion>(`package/version`);
return response.data;
}
private getHttpClient = async () => await this.provider.getHttpClient();
}

View file

@ -5,6 +5,7 @@
<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<Version>3.0.0</Version>
<Description>
Provides API endpoints for client applications such as the Elsa Designer web component.
</Description>

View file

@ -0,0 +1,29 @@
using System.Reflection;
using Elsa.Abstractions;
using FastEndpoints;
using JetBrains.Annotations;
namespace Elsa.Workflows.Api.Endpoints.Package;
/// <inheritdoc />
public class GetVersion : Endpoint<Request, Response>
{
/// <inheritdoc />
public override void Configure()
{
Get("/package/version");
}
/// <inheritdoc />
public override async Task HandleAsync(Request request, CancellationToken cancellationToken)
{
var assembly = Assembly.GetExecutingAssembly();
var versionAttribute = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
var version = RemoveAutoGeneratedPostfix(versionAttribute);
await SendOkAsync(new Response(version), cancellationToken);
}
private static string RemoveAutoGeneratedPostfix(AssemblyInformationalVersionAttribute? versionAttribute) =>
versionAttribute?.InformationalVersion.Split("+")[0]!;
}

View file

@ -0,0 +1,13 @@
namespace Elsa.Workflows.Api.Endpoints.Package;
public class Response
{
public Response(string packageVersion)
{
PackageVersion = packageVersion;
}
public string PackageVersion { get; set; }
}
public class Request {}