Skip to content

Fix #222 - Basic raw implementation for DSL 1.0.0 #224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/Go-SDK-PR-Check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:
run: go test ./... -coverprofile=test_coverage.out -covermode=atomic

- name: Upload Coverage Report
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: Test Coverage Report
path: test_coverage.out
Expand All @@ -120,7 +120,7 @@ jobs:

- name: Upload JUnit Report
if: always()
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: Integration Test JUnit Report
path: ./integration-test-junit.xml
227 changes: 130 additions & 97 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Go SDK for Serverless Workflow

The Go SDK for Serverless Workflow provides the [specification types](https://github.com/serverlessworkflow/specification/blob/v1.0.0-alpha5/schema/workflow.yaml) defined by the Serverless Workflow DSL in Go, making it easy to parse, validate, and interact with workflows.
The Go SDK for Serverless Workflow provides strongly-typed structures for the [Serverless Workflow specification](https://github.com/serverlessworkflow/specification/blob/v1.0.0/schema/workflow.yaml). It simplifies parsing, validating, and interacting with workflows in Go. Starting from version `v3.1.0`, the SDK also includes a partial reference implementation, allowing users to execute workflows directly within their Go applications.

---

Expand All @@ -10,8 +10,11 @@ The Go SDK for Serverless Workflow provides the [specification types](https://gi
- [Releases](#releases)
- [Getting Started](#getting-started)
- [Installation](#installation)
- [Basic Usage](#basic-usage)
- [Parsing Workflow Files](#parsing-workflow-files)
- [Programmatic Workflow Creation](#programmatic-workflow-creation)
- [Reference Implementation](#reference-implementation)
- [Example: Running a Workflow](#example-running-a-workflow)
- [Slack Community](#slack-community)
- [Contributing](#contributing)
- [Code Style](#code-style)
Expand All @@ -22,160 +25,190 @@ The Go SDK for Serverless Workflow provides the [specification types](https://gi

## Status

The current status of features implemented in the SDK is listed below:
This table indicates the current state of implementation of various SDK features:

| Feature | Status |
|-------------------------------------------- | ------------------ |
| Parse workflow JSON and YAML definitions | :heavy_check_mark: |
| Programmatically build workflow definitions | :heavy_check_mark: |
| Validate workflow definitions (Schema) | :heavy_check_mark: |
| Validate workflow definitions (Integrity) | :no_entry_sign: |
| Generate workflow diagram (SVG) | :no_entry_sign: |
| Feature | Status |
|-------------------------------------------- |---------------------|
| Parse workflow JSON and YAML definitions | :heavy_check_mark: |
| Programmatically build workflow definitions | :heavy_check_mark: |
| Validate workflow definitions (Schema) | :heavy_check_mark: |
| Specification Implementation | :heavy_check_mark:* |
| Validate workflow definitions (Integrity) | :no_entry_sign: |
| Generate workflow diagram (SVG) | :no_entry_sign: |

> **Note**: *Implementation is partial; contributions are encouraged.

---

## Releases

| Latest Releases | Conformance to Spec Version |
|:--------------------------------------------------------------------------:|:------------------------------------------------------------------------:|
| [v1.0.0](https://github.com/serverlessworkflow/sdk-go/releases/tag/v1.0.0) | [v0.5](https://github.com/serverlessworkflow/specification/tree/0.5.x) |
| [v2.0.1](https://github.com/serverlessworkflow/sdk-go/releases/tag/v2.0.1) | [v0.6](https://github.com/serverlessworkflow/specification/tree/0.6.x) |
| [v2.1.2](https://github.com/serverlessworkflow/sdk-go/releases/tag/v2.1.2) | [v0.7](https://github.com/serverlessworkflow/specification/tree/0.7.x) |
| [v2.4.3](https://github.com/serverlessworkflow/sdk-go/releases/tag/v2.4.1) | [v0.8](https://github.com/serverlessworkflow/specification/tree/0.8.x) |
| [v3.0.0](https://github.com/serverlessworkflow/sdk-go/releases/tag/v3.0.0) | [v1.0.0](https://github.com/serverlessworkflow/specification/releases/tag/v1.0.0-alpha5) |
| Latest Releases | Conformance to Spec Version |
|:--------------------------------------------------------------------------:|:---------------------------------------------------------------------------------:|
| [v1.0.0](https://github.com/serverlessworkflow/sdk-go/releases/tag/v1.0.0) | [v0.5](https://github.com/serverlessworkflow/specification/tree/0.5.x) |
| [v2.0.1](https://github.com/serverlessworkflow/sdk-go/releases/tag/v2.0.1) | [v0.6](https://github.com/serverlessworkflow/specification/tree/0.6.x) |
| [v2.1.2](https://github.com/serverlessworkflow/sdk-go/releases/tag/v2.1.2) | [v0.7](https://github.com/serverlessworkflow/specification/tree/0.7.x) |
| [v2.4.3](https://github.com/serverlessworkflow/sdk-go/releases/tag/v2.4.1) | [v0.8](https://github.com/serverlessworkflow/specification/tree/0.8.x) |
| [v3.0.0](https://github.com/serverlessworkflow/sdk-go/releases/tag/v3.0.0) | [v1.0.0](https://github.com/serverlessworkflow/specification/releases/tag/v1.0.0) |

---

## Getting Started

### Installation

To use the SDK in your Go project, run the following command:

```shell
$ go get github.com/serverlessworkflow/sdk-go/v3
```

This will update your `go.mod` file to include the Serverless Workflow SDK as a dependency.

Import the SDK in your Go file:

```go
import "github.com/serverlessworkflow/sdk-go/v3/model"
```

You can now use the SDK types and functions, for example:
## Reference Implementation

```go
package main
The SDK provides a partial reference runner to execute your workflows:

import (
"github.com/serverlessworkflow/sdk-go/v3/builder"
"github.com/serverlessworkflow/sdk-go/v3/model"
)
### Example: Running a Workflow

func main() {
workflowBuilder := New().
SetDocument("1.0.0", "examples", "example-workflow", "1.0.0").
AddTask("task1", &model.CallHTTP{
TaskBase: model.TaskBase{
If: &model.RuntimeExpression{Value: "${condition}"},
},
Call: "http",
With: model.HTTPArguments{
Method: "GET",
Endpoint: model.NewEndpoint("http://example.com"),
},
})
workflow, _ := builder.Object(workflowBuilder)
// use your models
}
Below is a simple YAML workflow that sets a message and then prints it:

```yaml
document:
dsl: "1.0.0"
namespace: "examples"
name: "simple-workflow"
version: "1.0.0"
do:
- set:
message: "Hello from the Serverless Workflow SDK in Go!"
```

### Parsing Workflow Files
You can execute this workflow using the following Go program:

The Serverless Workflow Specification supports YAML and JSON files. Use the following example to parse a workflow file into a Go data structure:
Example of executing a workflow defined in YAML:

```go
package main

import (
"github.com/serverlessworkflow/sdk-go/v3/model"
"fmt"
"os"
"path/filepath"

"github.com/serverlessworkflow/sdk-go/v3/impl"
"github.com/serverlessworkflow/sdk-go/v3/parser"
)

func ParseWorkflow(filePath string) (*model.Workflow, error) {
workflow, err := parser.FromFile(filePath)
func RunWorkflow(workflowFilePath string, input map[string]interface{}) (interface{}, error) {
data, err := os.ReadFile(filepath.Clean(workflowFilePath))
if err != nil {
return nil, err
}
workflow, err := parser.FromYAMLSource(data)
if err != nil {
return nil, err
}
return workflow, nil
}
```

This `Workflow` structure can then be used programmatically in your application.
runner := impl.NewDefaultRunner(workflow)
output, err := runner.Run(input)
if err != nil {
return nil, err
}
return output, nil
}

### Programmatic Workflow Creation
func main() {
output, err := RunWorkflow("./myworkflow.yaml", map[string]interface{}{"shouldCall": true})
if err != nil {
panic(err)
}
fmt.Printf("Workflow completed with output: %v\n", output)
}
```

Support for building workflows programmatically is planned for future releases. Stay tuned for updates in upcoming versions.
### Implementation Roadmap

The table below lists the current state of this implementation. This table is a roadmap for the project based on the [DSL Reference doc](https://github.com/serverlessworkflow/specification/blob/v1.0.0/dsl-reference.md).

| Feature | State |
| ----------- | --------------- |
| Workflow Document | ✅ |
| Workflow Use | 🟡 |
| Workflow Schedule | ❌ |
| Task Call | ❌ |
| Task Do | ✅ |
| Task Emit | ❌ |
| Task For | ❌ |
| Task Fork | ❌ |
| Task Listen | ❌ |
| Task Raise | ✅ |
| Task Run | ❌ |
| Task Set | ✅ |
| Task Switch | ❌ |
| Task Try | ❌ |
| Task Wait | ❌ |
| Lifecycle Events | 🟡 |
| External Resource | ❌ |
| Authentication | ❌ |
| Catalog | ❌ |
| Extension | ❌ |
| Error | ✅ |
| Event Consumption Strategies | ❌ |
| Retry | ❌ |
| Input | ✅ |
| Output | ✅ |
| Export | ✅ |
| Timeout | ❌ |
| Duration | ❌ |
| Endpoint | ✅ |
| HTTP Response | ❌ |
| HTTP Request | ❌ |
| URI Template | ✅ |
| Container Lifetime | ❌ |
| Process Result | ❌ |
| AsyncAPI Server | ❌ |
| AsyncAPI Outbound Message | ❌ |
| AsyncAPI Subscription | ❌ |
| Workflow Definition Reference | ❌ |
| Subscription Iterator | ❌ |

We love contributions! Our aim is to have a complete implementation to serve as a reference or to become a project on its own to favor the CNCF Ecosystem.

If you are willing to help, please [file a sub-task](https://github.com/serverlessworkflow/sdk-go/issues/221) in this EPIC describing what you are planning to work on first.

---

## Slack Community

Join the conversation and connect with other contributors on the [CNCF Slack](https://communityinviter.com/apps/cloud-native/cncf). Find us in the `#serverless-workflow-sdk` channel and say hello! 🙋
Join our community on the CNCF Slack to collaborate, ask questions, and contribute:

[CNCF Slack Invite](https://communityinviter.com/apps/cloud-native/cncf)

Find us in the `#serverless-workflow-sdk` channel.

---

## Contributing

We welcome contributions to improve this SDK. Please refer to the sections below for guidance on maintaining project standards.
Your contributions are very welcome!

### Code Style

- Use `goimports` for import organization.
- Lint your code with:
- Format imports with `goimports`.
- Run static analysis using:

```bash
```shell
make lint
```

To automatically fix lint issues, use:
Automatically fix lint issues:

```bash
```shell
make lint params=--fix
```

Example lint error:

```bash
$ make lint
make addheaders
make fmt
./hack/go-lint.sh
util/floatstr/floatstr_test.go:19: File is not `goimports`-ed (goimports)
"k8s.io/apimachinery/pkg/util/yaml"
make: *** [lint] Error 1
```

### EditorConfig

For IntelliJ users, an example `.editorconfig` file is available [here](contrib/intellij.editorconfig). See the [Jetbrains documentation](https://www.jetbrains.com/help/idea/editorconfig.html) for usage details.
A sample `.editorconfig` for IntelliJ or GoLand users can be found [here](contrib/intellij.editorconfig).

### Known Issues

#### MacOS Issue:

On MacOS, you might encounter the following error:
- **MacOS Issue**: If you encounter `goimports: can't extract issues from gofmt diff output`, resolve it with:

```
goimports: can't extract issues from gofmt diff output
```shell
brew install diffutils
```

To resolve this, install `diffutils`:
---

```bash
brew install diffutils
```
Contributions are greatly appreciated! Check [this EPIC](https://github.com/serverlessworkflow/sdk-go/issues/221) and contribute to completing more features.

Happy coding!
6 changes: 3 additions & 3 deletions builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"errors"
"testing"

"github.com/go-playground/validator/v10"
validator "github.com/go-playground/validator/v10"
"github.com/serverlessworkflow/sdk-go/v3/model"
"github.com/serverlessworkflow/sdk-go/v3/test"

Expand Down Expand Up @@ -137,7 +137,7 @@ func TestBuilder_Validate(t *testing.T) {
Version: "1.0.0",
},
Do: &model.TaskList{
{
&model.TaskItem{
Key: "task1",
Task: &model.CallHTTP{
Call: "http",
Expand All @@ -155,7 +155,7 @@ func TestBuilder_Validate(t *testing.T) {

// Test validation failure
workflow.Do = &model.TaskList{
{
&model.TaskItem{
Key: "task2",
Task: &model.CallHTTP{
Call: "http",
Expand Down
Loading
Loading