Merge pull request #28 from ditkrg/dev

General Improvements
This commit is contained in:
Shkar T. Noori 2024-04-28 11:33:01 +03:00 committed by GitHub
commit 011a2ab9aa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 161 additions and 50 deletions

View File

@ -1,3 +1,4 @@
---
name: Deploy To Nuget
on:
@ -19,13 +20,13 @@ jobs:
build-push:
name: Build and Publish
needs: [test]
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v1
- uses: actions/setup-dotnet@v4
with:
dotnet-version: "6.0.x"
dotnet-version: "8.0.x"
- name: Restore packages
run: dotnet restore

View File

@ -1,3 +1,4 @@
---
name: Run SonarQube Analysis
on:
@ -13,39 +14,10 @@ concurrency:
group: sonarqube-analysis
jobs:
run-tests:
name: Run SonarQube Analysis
timeout-minutes: 10
runs-on: ubuntu-latest
env:
PROJECT_KEY: ditkrg_DIT.Workflower_AYF14rjSb80e2b0bns3t
SONARQUBE_HOST: ${{ secrets.SONARQUBE_HOST }}
test:
uses: ./.github/workflows/tests-base.yaml
with:
sonarqube: true
sonarqube_host: ${{ vars.SONARQUBE_HOST }}
secrets:
SONARQUBE_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}
ASPNETCORE_ENVIRONMENT: Testing
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
distribution: "zulu"
java-version: "11"
- name: Restore tools
run: dotnet tool restore
- name: Run Tests (SonarQube)
run: |
dotnet tool run dotnet-sonarscanner begin -k:"$PROJECT_KEY" \
-d:sonar.login="$SONARQUBE_TOKEN" \
-d:sonar.host.url="$SONARQUBE_HOST" \
-d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml
dotnet build --no-incremental
dotnet dotnet-coverage collect "dotnet test" -f xml -o "coverage.xml"
dotnet tool run dotnet-sonarscanner end -d:sonar.login="$SONARQUBE_TOKEN"

View File

@ -12,6 +12,19 @@ on:
- "!.github/workflows/tests-base.yaml"
workflow_call:
inputs:
sonarqube:
type: boolean
required: false
default: false
sonarqube_host:
type: string
required: false
secrets:
SONARQUBE_TOKEN:
required: false
jobs:
run-tests:
@ -23,11 +36,44 @@ jobs:
ASPNETCORE_ENVIRONMENT: Testing
steps:
- uses: actions/checkout@v3
- uses: actions/setup-dotnet@v2
- uses: actions/setup-dotnet@v4
with:
dotnet-version: "6.0.x"
dotnet-version: "8.0.x"
- uses: actions/checkout@v4
if: ${{ !inputs.sonarqube }}
- name: Run tests
run: dotnet test
###############################
########## SONARQUBE ##########
###############################
- name: Set up JDK
uses: actions/setup-java@v4
if: ${{ inputs.sonarqube }}
with:
distribution: "zulu"
java-version: "17"
- uses: actions/checkout@v4
if: ${{ inputs.sonarqube }}
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Restore tools
if: ${{ inputs.sonarqube }}
run: dotnet tool restore
- name: Run tests (SonarQube)
if: ${{ inputs.sonarqube }}
run: |
dotnet tool run dotnet-sonarscanner begin -k:"$PROJECT_KEY" \
-d:sonar.login="$SONARQUBE_TOKEN" \
-d:sonar.host.url="${{ inputs.sonarqube_host }}" \
-d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml
dotnet build --no-incremental
dotnet dotnet-coverage collect "dotnet test" -f xml -o "coverage.xml"
dotnet tool run dotnet-sonarscanner end -d:sonar.login="$SONARQUBE_TOKEN"

View File

@ -10,6 +10,15 @@ public interface IWorkflow<TState, TCommand, TContext>
string Reference => $"{Id}.v{Version}";
/// <summary>
/// Retrieves all transition definitions for the workflow.
/// </summary>
/// <typeparam name="TState">The type of the workflow state.</typeparam>
/// <typeparam name="TCommand">The type of the workflow command.</typeparam>
/// <typeparam name="TContext">The type of the workflow context.</typeparam>
/// <returns>A list of transition definitions.</returns>
public List<TransitionDefinition<TState, TCommand, TContext>> GetAllTransitionDefinitions();
/// <summary>
/// Gets a list of allowed transitions without any condition checks.
/// </summary>
@ -24,4 +33,13 @@ public interface IWorkflow<TState, TCommand, TContext>
/// <param name="from">The incoming state</param>
/// <returns>A list of available transitions for the current context</returns>
public List<Transition<TState, TCommand>> GetAllowedTransitions(TContext context, TState from);
/// <summary>
/// Retrieves a list of allowed transitions based on the provided request.
/// </summary>
/// <typeparam name="TState">The type of the workflow state.</typeparam>
/// <typeparam name="TCommand">The type of the workflow command.</typeparam>
/// <param name="request">The request object containing the necessary information.</param>
/// <returns>An enumerable of allowed transitions.</returns>
public IEnumerable<Transition<TState, TCommand>> GetAllowedTransitions(ListTransitionsRequest<TState, TCommand, TContext> request);
}

View File

@ -1,13 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>true</IsPackable>
<PackageId>DIT.Workflower.DependencyInjection</PackageId>
<Authors>DIT</Authors>
<Company>DIT</Company>
<!-- Symbols for nuget -->
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<!-- Deterministic Builds -->
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' == 'true'">true</ContinuousIntegrationBuild>
</PropertyGroup>
<ItemGroup >
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0" Condition="'$(TargetFramework)' == 'net6.0'" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0" Condition="'$(TargetFramework)' == 'net7.0'" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0" Condition="'$(TargetFramework)' == 'net8.0'" />
</ItemGroup>
<ItemGroup>

View File

@ -5,6 +5,20 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<IsPackable>true</IsPackable>
<PackageId>DIT.Workflower</PackageId>
<Authors>DIT</Authors>
<Company>DIT</Company>
<!-- Symbols for nuget -->
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<!-- Deterministic Builds -->
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<ContinuousIntegrationBuild Condition="'$(GITHUB_ACTIONS)' == 'true'">true</ContinuousIntegrationBuild>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,13 @@
namespace DIT.Workflower;
public sealed class ListTransitionsRequest<TState, TCommand, TContext>
{
public TState? From { get; set; }
public TState? To { get; set; }
public TCommand? Command { get; set; }
public TContext? Context { get; set; }
}

View File

@ -12,6 +12,8 @@ public record WorkflowDefinition<TState, TCommand, TContext>
_transitions = transitions;
}
public List<TransitionDefinition<TState, TCommand, TContext>> GetAllTransitionDefinitions() => _transitions;
/// <summary>
/// Lists all allowed transitions from current state for the given context.
/// </summary>
@ -33,4 +35,33 @@ public record WorkflowDefinition<TState, TCommand, TContext>
return query.Select(x => x.ToTransition()).ToList();
}
public IEnumerable<Transition<TState, TCommand>> GetAllowedTransitions(ListTransitionsRequest<TState, TCommand, TContext> request)
{
var query = _transitions.AsQueryable();
if (request.From is TState from)
{
query = query.Where(doc => doc.From.Equals(from));
}
if (request.To is TState to)
{
query = query.Where(doc => doc.To.Equals(to));
}
if (request.Command is TCommand command)
{
query = query.Where(doc => doc.Command.Equals(command));
}
if (request.Context is not null)
{
query = query.Where(doc => doc.Conditions == null || !doc.Conditions.Any(cond => !cond(request.Context)));
}
return query.Select(x => x.ToTransition());
}
}

View File

@ -9,14 +9,14 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PackageReference Include="coverlet.collector" Version="3.2.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>