Skip to content

Commit b8cc56d

Browse files
author
Nigel Mukandi
committed
CI
1 parent 048bbb2 commit b8cc56d

File tree

5 files changed

+129
-58
lines changed

5 files changed

+129
-58
lines changed

.github/workflows/main.yaml

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,66 @@
1-
name: Main Pipeline
1+
name: main
22

33
on:
44
push:
55
branches:
66
- main
7-
7+
workflow_dispatch:
8+
89
jobs:
910
test:
1011
runs-on: ubuntu-latest
1112
steps:
12-
- name: Checkout code
13-
uses: actions/checkout@v3
13+
- name: checkout code
14+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
1415

15-
- name: Setup .NET
16-
uses: actions/setup-dotnet@v3
16+
- name: setup dotnet environment
17+
uses: actions/setup-dotnet@d4c94342e560b34958eacfc5d055d21461ed1c5d
1718
with:
1819
dotnet-version: '9.0'
1920

20-
- name: Restore dependencies
21+
- run: dotnet --info
22+
23+
- name: restore dependencies
2124
run: dotnet restore
2225

23-
- name: Run test
24-
run: dotnet test --no-restore --verbosity normal
26+
- name: build
27+
run: dotnet build --configuration Release
28+
29+
- name: run test
30+
run: dotnet test --configuration Release --no-restore --no-build --verbosity normal
2531

26-
publish:
32+
publish-artifacts:
2733
runs-on: ubuntu-latest
34+
name: publish artifacts
2835
needs: test
2936
steps:
30-
- name: Checkout code
31-
uses: actions/checkout@v3
32-
33-
- name: Setup .NET
34-
uses: actions/setup-dotnet@v3
37+
- name: checkout code
38+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
39+
with:
40+
fetch-depth: 1
41+
42+
- name: setup dotnet environment
43+
uses: actions/setup-dotnet@d4c94342e560b34958eacfc5d055d21461ed1c5d
3544
with:
3645
dotnet-version: '9.0'
3746

38-
- name: Set up NuGet environment
39-
env:
40-
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
41-
run: |
42-
echo "::add-mask::$NUGET_API_KEY"
43-
44-
# - name: Deploy to NuGet
45-
# run: dotnet nuget push <package-name.nupkg> --api-key $NUGET_API_KEY --source https://api.nuget.org/v3/index.json
46-
#
47-
# - name: Cleanup built artifacts
48-
# run: dotnet clean
47+
- run: dotnet --info
48+
49+
- name: restore dependencies
50+
run: dotnet restore
51+
52+
- name: extract package version from csproj
53+
run: |
54+
BASE_VERSION=$(grep -oPm1 "(?<=<Version>)[^<]+" **/*.csproj)
55+
echo "BASE_VERSION=$BASE_VERSION" >> $GITHUB_ENV
56+
echo "Detected base version: $BASE_VERSION"
57+
58+
- name: generate nuget package
59+
run: dotnet pack --configuration Release --output artifacts
4960

50-
61+
- name: upload artifact
62+
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4
63+
with:
64+
name: artifact
65+
path: artifacts/
66+

.github/workflows/publish.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: release
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
release:
8+
runs-on: ubuntu-latest
9+
name: release
10+
steps:
11+
- name: download artifacts
12+
uses: actions/download-artifact@v6
Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Pull Request Pipeline
1+
name: pull request
22
on:
33
pull_request:
44
branches:
@@ -8,16 +8,21 @@ jobs:
88
test:
99
runs-on: ubuntu-latest
1010
steps:
11-
- name: Checkout code
12-
uses: actions/checkout@v3
11+
- name: checkout repository
12+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
1313

14-
- name: Setup .NET
15-
uses: actions/setup-dotnet@v3
14+
- name: setup dotnet environment
15+
uses: actions/setup-dotnet@d4c94342e560b34958eacfc5d055d21461ed1c5d
1616
with:
1717
dotnet-version: '9.0'
18-
19-
- name: Restore dependencies
18+
19+
- run: dotnet --info
20+
21+
- name: restore dependencies
2022
run: dotnet restore
23+
24+
- name: build
25+
run: dotnet build --configuration Release
2126

22-
- name: Run test
23-
run: dotnet test --no-restore --verbosity normal
27+
- name: run test
28+
run: dotnet test --configuration Release --no-restore --no-build --verbosity normal
Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,32 @@
11
namespace FiniteStateMachine;
22

3+
/// <summary>
4+
/// Builder class for creating a finite state machine.
5+
/// </summary>
6+
/// <typeparam name="TState">Type representing the states of the machine.</typeparam>
7+
/// <typeparam name="TTrigger">Enum type representing triggers to cause transitions.</typeparam>
38
public sealed class FiniteStateMachineBuilder<TState, TTrigger>
49
where TTrigger : Enum
510
where TState : notnull
611
{
712
private readonly TState _initialState;
813
private readonly Dictionary<TState, Dictionary<TTrigger, TState>> _transitions = new();
9-
14+
15+
/// <summary>
16+
/// Initializes a new instance of the <see cref="FiniteStateMachineBuilder{TState, TTrigger}"/> class.
17+
/// </summary>
18+
/// <param name="initialState">The initial state of the state machine.</param>
1019
internal FiniteStateMachineBuilder(TState initialState)
1120
{
1221
_initialState = initialState;
1322
}
14-
23+
24+
/// <summary>
25+
/// Defines a state and its possible transitions.
26+
/// </summary>
27+
/// <param name="state">The state to configure.</param>
28+
/// <param name="configure">An action to configure the state transitions.</param>
29+
/// <returns>A reference to the current builder instance.</returns>
1530
public FiniteStateMachineBuilder<TState, TTrigger> State(
1631
TState state,
1732
Action<StateConfiguration<TState, TTrigger>> configure)
@@ -21,7 +36,11 @@ public FiniteStateMachineBuilder<TState, TTrigger> State(
2136
_transitions.Add(state, cfg.Transitions);
2237
return this;
2338
}
24-
39+
40+
/// <summary>
41+
/// Builds and returns the configured state machine.
42+
/// </summary>
43+
/// <returns>A new state machine configured with specified states and transitions.</returns>
2544
public StateMachine<TState, TTrigger> Build()
2645
{
2746
var rules = GetTransitionRules();
@@ -30,41 +49,25 @@ public StateMachine<TState, TTrigger> Build()
3049

3150
private Dictionary<RuleKey<TState, TTrigger>, Rule<TState, TTrigger>> GetTransitionRules()
3251
{
33-
Dictionary<RuleKey<TState,TTrigger>,Rule<TState,TTrigger>> rules = [];
52+
var rules = new Dictionary<RuleKey<TState, TTrigger>, Rule<TState, TTrigger>>();
3453
foreach (var (fromState, transitions) in _transitions)
3554
{
3655
foreach (var (trigger, targetState) in transitions)
3756
{
3857
var ruleKey = new RuleKey<TState, TTrigger>
3958
{
4059
From = fromState,
41-
Trigger = trigger,
60+
Trigger = trigger
4261
};
4362
var rule = new Rule<TState, TTrigger>
4463
{
4564
From = fromState,
4665
To = targetState,
47-
Trigger = trigger,
66+
Trigger = trigger
4867
};
4968
rules.Add(ruleKey, rule);
5069
}
5170
}
5271
return rules;
5372
}
54-
}
55-
56-
public sealed class StateConfiguration<TState, TTrigger> where TTrigger : Enum
57-
{
58-
private readonly TState _state;
59-
internal Dictionary<TTrigger, TState> Transitions { get; } = new();
60-
61-
internal StateConfiguration(TState state)
62-
{
63-
_state = state;
64-
}
65-
66-
public TransitionConfiguration<TState, TTrigger> On(TTrigger trigger)
67-
{
68-
return new TransitionConfiguration<TState, TTrigger>(this, trigger);
69-
}
7073
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
namespace FiniteStateMachine;
2+
3+
/// <summary>
4+
/// Configuration class for defining transitions from a specific state.
5+
/// </summary>
6+
/// <typeparam name="TState">Type representing the states.</typeparam>
7+
/// <typeparam name="TTrigger">Enum type representing triggers.</typeparam>
8+
public sealed class StateConfiguration<TState, TTrigger> where TTrigger : Enum
9+
{
10+
private readonly TState _state;
11+
12+
/// <summary>
13+
/// Gets the transitions defined for the current state.
14+
/// </summary>
15+
internal Dictionary<TTrigger, TState> Transitions { get; } = new();
16+
17+
/// <summary>
18+
/// Initializes a new instance of the <see cref="StateConfiguration{TState, TTrigger}"/> class.
19+
/// </summary>
20+
/// <param name="state">The state to configure.</param>
21+
internal StateConfiguration(TState state)
22+
{
23+
_state = state;
24+
}
25+
26+
/// <summary>
27+
/// Starts the configuration of a transition for a given trigger.
28+
/// </summary>
29+
/// <param name="trigger">The trigger that causes a transition.</param>
30+
/// <returns>A configuration object to setup the transition.</returns>
31+
public TransitionConfiguration<TState, TTrigger> On(TTrigger trigger)
32+
{
33+
return new TransitionConfiguration<TState, TTrigger>(this, trigger);
34+
}
35+
}

0 commit comments

Comments
 (0)