Skip to content

Commit

Permalink
chore: add goreleaser
Browse files Browse the repository at this point in the history
  • Loading branch information
pancsta committed Mar 4, 2024
1 parent a214113 commit bc3ba88
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 4 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/releaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: goreleaser

on:
push:
tags:
- 'v*'

permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
-
name: Set up Go
uses: actions/setup-go@v4
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion .github_changelog_generator
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ usernames-as-github-logins=true
pr-label=
since-tag=v0.1.0
user=pancsta
project=asyncmachine-go
project=asyncmachine-go
unreleased=false
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ go.work

# local dev
/.dev
/dist
/docs/cookbook.md
/tools/am-dbg/am-dbg
/*.log
49 changes: 49 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# .goreleaser.yml

builds:
-
id: "am-dbg"
env:
- CGO_ENABLED=0
- GO111MODULE=on
goos:
- linux
- darwin
- windows
goarch:
- amd64
- arm64
main: ./tools/am-dbg/main.go
binary: am-dbg

archives:
-
id: "archive"
format: tar.gz
name_template: "am-dbg_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
files: [""]

checksum:
name_template: 'checksums.txt'

release:
github:
owner: pancsta
name: asyncmachine-go
draft: true
replace_existing_draft: true

changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
- '^chore:'
- '^refactor:'
- '^style:'
- '^ci:'
- '^perf:'
- '^revert:'
snapshot:
name_template: "{{ .Tag }}-next"
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changelog

## [v0.3.1](https://github.com/pancsta/asyncmachine-go/tree/v0.3.1) (2024-03-04)

- feat: add version param [\#23](https://github.com/pancsta/asyncmachine-go/pull/23) (@pancsta)
- feat: complete TUI debugger iteration 3 [\#22](https://github.com/pancsta/asyncmachine-go/pull/22) (@pancsta)
- feat: TUI debugger iteration 2 [\#21](https://github.com/pancsta/asyncmachine-go/pull/21) (@pancsta)
- feat: add TUI debugger [\#20](https://github.com/pancsta/asyncmachine-go/pull/20) (@pancsta)
- feat: add telemetry via net/rpc [\#19](https://github.com/pancsta/asyncmachine-go/pull/19) (@pancsta)
- feat: add support for state groups for the Remove relation [\#17](https://github.com/pancsta/asyncmachine-go/pull/17) (@pancsta)
- fix: add more locks [\#16](https://github.com/pancsta/asyncmachine-go/pull/16) (@pancsta)
- feat: prevent empty remove mutations [\#15](https://github.com/pancsta/asyncmachine-go/pull/15) (@pancsta)
- feat: add VerifyStates for early state names assert [\#14](https://github.com/pancsta/asyncmachine-go/pull/14) (@pancsta)
- docs: add debugger readme img [\#13](https://github.com/pancsta/asyncmachine-go/pull/13) (@pancsta)
- docs: add ToC, cheatsheet [\#12](https://github.com/pancsta/asyncmachine-go/pull/12) (@pancsta)
- docs: align with the v0.2.0 release [\#11](https://github.com/pancsta/asyncmachine-go/pull/11) (@pancsta)

## [v0.2.1](https://github.com/pancsta/asyncmachine-go/tree/v0.2.1) (2024-01-18)

- fix: prevent double handlerDone notif [\#10](https://github.com/pancsta/asyncmachine-go/pull/10) (@pancsta)
Expand Down
53 changes: 50 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,51 @@ func HandleFileProcessingTask(ctx context.Context, t *asynq.Task) error {
}
```

## Usage

- Declarative

```go
// randomly reject the mutation
func (h *Handlers) ProcessingFileEnter(e *am.Event) bool {
rand.Seed(time.Now().UnixNano())
randomBool := rand.Intn(2) == 0
return randomBool
}
// cause side effects if accepted
func (h *Handlers) ProcessingFileState(e *am.Event) {
mach := e.Machine
stateCtx := mach.GetStateCtx("ProcessingFile")
go func() {
if stateCtx.Err() != nil {
return
}
err := processFile(h.DownloadedName, stateCtx)
if err != nil {
mach.AddErr(err)
return
}
mach.Add("FileProcessed", nil)
}
}
```

- Imperative

```go
// change the state
mach.Add(am.S{"DownloadingFile"},
am.A{"filename": filename})
// wait for completed
select {
case <-time.After(5 * time.Second):
return mach, errors.New("timeout")
case <-mach.WhenErr(nil):
return mach, mach.Err
case <-mach.When(am.S{"FileUploaded"}, nil):
}
```

## Documentation

- [API godoc](https://godoc.org/github.com/pancsta/asyncmachine-go/pkg/machine)
Expand All @@ -148,11 +193,13 @@ func HandleFileProcessingTask(ctx context.Context, t *asynq.Task) error {

![TUI Debugger](assets/am-dbg.png)

### Installation
### Installing `am-dbg`

[Download a release binary](https://github.com/pancsta/asyncmachine-go/releases/latest) or use `go install`:

`go install github.com/pancsta/asyncmachine-go/tools/am-dbg@latest`

### Usage
### Using `am-dbg`

Set up telemetry:

Expand All @@ -161,7 +208,7 @@ import (
"github.com/pancsta/asyncmachine-go/pkg/telemetry"
)
// ...
err := telemetry.MonitorTransitions(machine, telemetry.RpcHost)
err := telemetry.MonitorTransitions(mach, telemetry.RpcHost)
```

Run `am-dbg`:
Expand Down
5 changes: 5 additions & 0 deletions examples/temporal-fileprocessing/fileprocessing.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ func (h *MachineHandlers) ProcessingFileState(e *am.Event) {
// Using machine's context directly will conflict with retry logic (if any).
stateCtx := e.Machine.GetStateCtx("ProcessingFile")
go func() {
// assert context
if stateCtx.Err() != nil {
e.Machine.Log("processFileActivity canceled.")
return
}
// read downloaded file
data, err := os.ReadFile(h.DownloadedName)
if err != nil {
Expand Down

0 comments on commit bc3ba88

Please sign in to comment.