mirror of
https://github.com/ditkrg/DIT.Workflower.git
synced 2026-01-22 22:06:42 +00:00
commit
011a2ab9aa
9
.github/workflows/deploy-nuget.yaml
vendored
9
.github/workflows/deploy-nuget.yaml
vendored
@ -1,3 +1,4 @@
|
|||||||
|
---
|
||||||
name: Deploy To Nuget
|
name: Deploy To Nuget
|
||||||
|
|
||||||
on:
|
on:
|
||||||
@ -19,13 +20,13 @@ jobs:
|
|||||||
build-push:
|
build-push:
|
||||||
name: Build and Publish
|
name: Build and Publish
|
||||||
needs: [test]
|
needs: [test]
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- uses: actions/setup-dotnet@v1
|
- uses: actions/setup-dotnet@v4
|
||||||
with:
|
with:
|
||||||
dotnet-version: "6.0.x"
|
dotnet-version: "8.0.x"
|
||||||
|
|
||||||
- name: Restore packages
|
- name: Restore packages
|
||||||
run: dotnet restore
|
run: dotnet restore
|
||||||
|
|||||||
42
.github/workflows/sonarqube.yaml
vendored
42
.github/workflows/sonarqube.yaml
vendored
@ -1,3 +1,4 @@
|
|||||||
|
---
|
||||||
name: Run SonarQube Analysis
|
name: Run SonarQube Analysis
|
||||||
|
|
||||||
on:
|
on:
|
||||||
@ -13,39 +14,10 @@ concurrency:
|
|||||||
group: sonarqube-analysis
|
group: sonarqube-analysis
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
run-tests:
|
test:
|
||||||
name: Run SonarQube Analysis
|
uses: ./.github/workflows/tests-base.yaml
|
||||||
timeout-minutes: 10
|
with:
|
||||||
runs-on: ubuntu-latest
|
sonarqube: true
|
||||||
|
sonarqube_host: ${{ vars.SONARQUBE_HOST }}
|
||||||
env:
|
secrets:
|
||||||
PROJECT_KEY: ditkrg_DIT.Workflower_AYF14rjSb80e2b0bns3t
|
|
||||||
SONARQUBE_HOST: ${{ secrets.SONARQUBE_HOST }}
|
|
||||||
SONARQUBE_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}
|
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"
|
|
||||||
|
|||||||
54
.github/workflows/tests-base.yaml
vendored
54
.github/workflows/tests-base.yaml
vendored
@ -12,6 +12,19 @@ on:
|
|||||||
- "!.github/workflows/tests-base.yaml"
|
- "!.github/workflows/tests-base.yaml"
|
||||||
|
|
||||||
workflow_call:
|
workflow_call:
|
||||||
|
inputs:
|
||||||
|
sonarqube:
|
||||||
|
type: boolean
|
||||||
|
required: false
|
||||||
|
default: false
|
||||||
|
|
||||||
|
sonarqube_host:
|
||||||
|
type: string
|
||||||
|
required: false
|
||||||
|
|
||||||
|
secrets:
|
||||||
|
SONARQUBE_TOKEN:
|
||||||
|
required: false
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
run-tests:
|
run-tests:
|
||||||
@ -23,11 +36,44 @@ jobs:
|
|||||||
ASPNETCORE_ENVIRONMENT: Testing
|
ASPNETCORE_ENVIRONMENT: Testing
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/setup-dotnet@v4
|
||||||
|
|
||||||
- uses: actions/setup-dotnet@v2
|
|
||||||
with:
|
with:
|
||||||
dotnet-version: "6.0.x"
|
dotnet-version: "8.0.x"
|
||||||
|
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
if: ${{ !inputs.sonarqube }}
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: dotnet test
|
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"
|
||||||
|
|||||||
@ -10,6 +10,15 @@ public interface IWorkflow<TState, TCommand, TContext>
|
|||||||
|
|
||||||
string Reference => $"{Id}.v{Version}";
|
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>
|
/// <summary>
|
||||||
/// Gets a list of allowed transitions without any condition checks.
|
/// Gets a list of allowed transitions without any condition checks.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -24,4 +33,13 @@ public interface IWorkflow<TState, TCommand, TContext>
|
|||||||
/// <param name="from">The incoming state</param>
|
/// <param name="from">The incoming state</param>
|
||||||
/// <returns>A list of available transitions for the current context</returns>
|
/// <returns>A list of available transitions for the current context</returns>
|
||||||
public List<Transition<TState, TCommand>> GetAllowedTransitions(TContext context, TState from);
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,29 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<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>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup >
|
<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>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -5,6 +5,20 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<LangVersion>latest</LangVersion>
|
<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>
|
</PropertyGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
13
src/DIT.Workflower/Query.cs
Normal file
13
src/DIT.Workflower/Query.cs
Normal 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; }
|
||||||
|
}
|
||||||
@ -12,6 +12,8 @@ public record WorkflowDefinition<TState, TCommand, TContext>
|
|||||||
_transitions = transitions;
|
_transitions = transitions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<TransitionDefinition<TState, TCommand, TContext>> GetAllTransitionDefinitions() => _transitions;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Lists all allowed transitions from current state for the given context.
|
/// Lists all allowed transitions from current state for the given context.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -33,4 +35,33 @@ public record WorkflowDefinition<TState, TCommand, TContext>
|
|||||||
|
|
||||||
return query.Select(x => x.ToTransition()).ToList();
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,14 +9,14 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
|
||||||
<PackageReference Include="xunit" Version="2.4.1" />
|
<PackageReference Include="xunit" Version="2.4.2" />
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
</PackageReference>
|
</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>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user