Skip to content

Commit

Permalink
fix: a new implement
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkgos committed Jul 1, 2023
1 parent 13817de commit 2216f93
Show file tree
Hide file tree
Showing 25 changed files with 951 additions and 680 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ updates:
interval: "daily"
commit-message:
prefix: "chore"
include: "scope"
include: "scope"
19 changes: 10 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: Tests
on:
push:
paths-ignore:
- '**.md'
- "**.md"
pull_request:
paths-ignore:
- '**.md'
- "**.md"

env:
GO111MODULE: on
Expand All @@ -18,17 +18,18 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
go-version: ["1.18.x", "1.19.x"]
os: [ubuntu-latest, macos-latest, windows-latest]
go-version: ["1.20.x"]
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
cache: false

- name: Check out code into the Go module directory
uses: actions/checkout@v3.5.3
uses: actions/checkout@v3

- name: Print Go environment
id: vars
Expand All @@ -40,18 +41,18 @@ jobs:
printf "\n\nSystem environment:\n\n"
env
# Calculate the short SHA1 hash of the git commit
echo "::set-output name=short_sha::$(git rev-parse --short HEAD)"
echo "::set-output name=go_cache::$(go env GOCACHE)"
echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "go_cache=$(go env GOCACHE)" >> $GITHUB_OUTPUT
- name: Cache go modules
uses: actions/cache@v3
with:
path: |
${{ steps.vars.outputs.go_cache }}
${{ steps.vars.outputs.GO_CACHE }}
~/go/pkg/mod
key: ${{ runner.os }}-${{ matrix.go-version }}-go-ci-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-${{ matrix.go-version }}-go-ci
${{ runner.os }}-${{ matrix.go-version }}-go-ci-
- name: Unit test
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3.5.3
uses: actions/checkout@v3
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
name: GolangCi-Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3.5.3
- uses: actions/checkout@v3
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with: # BUG: typecheck error when enable all
Expand Down
11 changes: 6 additions & 5 deletions .github/workflows/pr_review_dog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Reviewdog
on:
pull_request:
paths-ignore:
- '**.md'
- "**.md"

jobs:
golangci-lint:
Expand All @@ -14,12 +14,13 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.18.x'
go-version: "1.20.x"

- name: Check out code into the Go module directory
uses: actions/checkout@v3.5.3
uses: actions/checkout@v3

- name: golangci-lint
uses: reviewdog/action-golangci-lint@v2
with:
golangci_lint_flags: "-E goimports -E gocritic -E misspell"
with: # BUG: typecheck error when enable all
args: --disable-all -E goimports,misspell,whitespace
version: latest
6 changes: 3 additions & 3 deletions examples/alternate.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import (
)

func main() {
f := fsm.New(
f := fsm.NewSafeFsm(
"idle",
fsm.Transforms[string, string]{
fsm.NewTransition([]fsm.Transform[string, string]{
{Event: "scan", Src: []string{"idle"}, Dst: "scanning"},
{Event: "working", Src: []string{"scanning"}, Dst: "scanning"},
{Event: "situation", Src: []string{"scanning"}, Dst: "scanning"},
{Event: "situation", Src: []string{"idle"}, Dst: "idle"},
{Event: "finish", Src: []string{"scanning"}, Dst: "idle"},
},
}),
)
fmt.Println(f.Current())

Expand Down
6 changes: 3 additions & 3 deletions examples/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
)

func main() {
fsm1 := fsm.New(
fsm1 := fsm.NewSafeFsm(
"idle",
fsm.Transforms[string, string]{
fsm.NewTransition([]fsm.Transform[string, string]{
{Event: "produce", Src: []string{"idle"}, Dst: "idle"},
{Event: "consume", Src: []string{"idle"}, Dst: "idle"},
},
}),
)
fmt.Println(fsm1.Current())

Expand Down
8 changes: 4 additions & 4 deletions examples/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ const (
)

func main() {
f := fsm.New(
f := fsm.NewSafeFsm(
IsClosed,
[]fsm.Transform[MyEvent, MyState]{
fsm.NewTransition([]fsm.Transform[MyEvent, MyState]{
{Event: Open, Src: []MyState{IsClosed}, Dst: IsOpen},
{Event: Close, Src: []MyState{IsOpen}, Dst: IsClosed},
},
}),
)
fmt.Println(f.Current())
err := f.Trigger(Open)
Expand All @@ -65,7 +65,7 @@ func main() {
// closed
// opened
// closed
fmt.Println(fsm.Visualize[MyEvent, MyState](f))
fmt.Println(fsm.VisualizeGraphviz[MyEvent, MyState](f))
// digraph fsm {
// "closed" -> "opened" [ label = "open" ];
// "opened" -> "closed" [ label = "close" ];
Expand Down
6 changes: 3 additions & 3 deletions examples/sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
)

func main() {
fsm1 := fsm.New[string, string](
fsm1 := fsm.NewSafeFsm[string, string](
"closed",
fsm.Transforms[string, string]{
fsm.NewTransition([]fsm.Transform[string, string]{
{Event: "open", Src: []string{"closed"}, Dst: "open"},
{Event: "close", Src: []string{"open"}, Dst: "closed"},
},
}),
)
fmt.Println(fsm1.Current())

Expand Down
Loading

0 comments on commit 2216f93

Please sign in to comment.