Skip to content

Commit 1e982b6

Browse files
authored
Merge branch 'serverlessworkflow:main' into #181/bug/fix
2 parents 92e4a48 + 7219d5c commit 1e982b6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+4206
-213
lines changed

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@ lint:
1414

1515
.PHONY: test
1616
coverage="false"
17-
test: deepcopy
17+
18+
test: deepcopy buildergen
1819
make lint
1920
@go test ./...
2021

21-
.PHONY: deepcopy
22+
.PHONY: deepcopy buildergen
2223
deepcopy: $(DEEPCOPY_GEN) ## Download deepcopy-gen locally if necessary.
2324
./hack/deepcopy-gen.sh deepcopy
2425

26+
buildergen: $(BUILDER_GEN) ## Download builder-gen locally if necessary.
27+
./hack/builder-gen.sh buildergen
28+
2529
.PHONY: kube-integration
2630
kube-integration: controller-gen
2731
$(CONTROLLER_GEN) rbac:roleName=manager-role crd:allowDangerousTypes=true webhook paths="./..." output:crd:artifacts:config=config/crd/bases

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Current status of features implemented in the SDK is listed in the table below:
3333
| [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) |
3434
| [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) |
3535
| [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) |
36-
| [v2.2.3](https://github.com/serverlessworkflow/sdk-go/releases/tag/v2.2.2) | [v0.8](https://github.com/serverlessworkflow/specification/tree/0.8.x) |
36+
| [v2.2.5](https://github.com/serverlessworkflow/sdk-go/releases/tag/v2.2.5) | [v0.8](https://github.com/serverlessworkflow/specification/tree/0.8.x) |
3737

3838
## How to use
3939

builder/builder.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright 2023 The Serverless Workflow Specification Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package builder
16+
17+
import (
18+
"encoding/json"
19+
20+
"sigs.k8s.io/yaml"
21+
22+
"github.com/serverlessworkflow/sdk-go/v2/model"
23+
val "github.com/serverlessworkflow/sdk-go/v2/validator"
24+
)
25+
26+
func New() *model.WorkflowBuilder {
27+
return model.NewWorkflowBuilder()
28+
}
29+
30+
func Yaml(builder *model.WorkflowBuilder) ([]byte, error) {
31+
data, err := Json(builder)
32+
if err != nil {
33+
return nil, err
34+
}
35+
return yaml.JSONToYAML(data)
36+
}
37+
38+
func Json(builder *model.WorkflowBuilder) ([]byte, error) {
39+
workflow, err := Object(builder)
40+
if err != nil {
41+
return nil, err
42+
}
43+
return json.Marshal(workflow)
44+
}
45+
46+
func Object(builder *model.WorkflowBuilder) (*model.Workflow, error) {
47+
workflow := builder.Build()
48+
ctx := model.NewValidatorContext(&workflow)
49+
if err := val.GetValidator().StructCtx(ctx, workflow); err != nil {
50+
return nil, err
51+
}
52+
return &workflow, nil
53+
}
54+
55+
func Validate(object interface{}) error {
56+
ctx := model.NewValidatorContext(object)
57+
if err := val.GetValidator().StructCtx(ctx, object); err != nil {
58+
return val.WorkflowError(err)
59+
}
60+
return nil
61+
}

builder/builder_test.go

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
// Copyright 2023 The Serverless Workflow Specification Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package builder
16+
17+
import (
18+
"testing"
19+
20+
"github.com/pkg/errors"
21+
"github.com/stretchr/testify/assert"
22+
23+
"github.com/serverlessworkflow/sdk-go/v2/model"
24+
val "github.com/serverlessworkflow/sdk-go/v2/validator"
25+
)
26+
27+
func prepareBuilder() *model.WorkflowBuilder {
28+
builder := New().Key("key test").ID("id test")
29+
30+
builder.AddFunctions().Name("function name").Operation("http://test")
31+
builder.AddFunctions().Name("function name2").Operation("http://test")
32+
33+
function3 := builder.AddFunctions().Name("function name2").Operation("http://test")
34+
builder.RemoveFunctions(function3)
35+
36+
state1 := builder.AddStates().
37+
Name("state").
38+
Type(model.StateTypeInject)
39+
state1.End().Terminate(true)
40+
41+
inject := state1.InjectState()
42+
inject.Data(map[string]model.Object{
43+
"test": model.FromMap(map[string]any{}),
44+
})
45+
46+
return builder
47+
}
48+
49+
func TestValidate(t *testing.T) {
50+
state1 := model.NewStateBuilder().
51+
Name("state").
52+
Type(model.StateTypeInject)
53+
state1.End().Terminate(true)
54+
err := Validate(state1)
55+
assert.NoError(t, err)
56+
57+
state2 := model.NewStateBuilder().
58+
Type(model.StateTypeInject)
59+
state2.End().Terminate(true)
60+
err = Validate(state2.Build())
61+
if assert.Error(t, err) {
62+
var workflowErrors val.WorkflowErrors
63+
if errors.As(err, &workflowErrors) {
64+
assert.Equal(t, "state.name is required", workflowErrors[0].Error())
65+
} else {
66+
// Handle other error types if necessary
67+
t.Errorf("Unexpected error: %v", err)
68+
}
69+
}
70+
}
71+
72+
func TestObject(t *testing.T) {
73+
workflow, err := Object(prepareBuilder())
74+
if assert.NoError(t, err) {
75+
assert.Equal(t, "key test", workflow.Key)
76+
assert.Equal(t, "id test", workflow.ID)
77+
assert.Equal(t, "0.8", workflow.SpecVersion)
78+
assert.Equal(t, "jq", workflow.ExpressionLang.String())
79+
assert.Equal(t, 2, len(workflow.Functions))
80+
81+
assert.Equal(t, "function name", workflow.Functions[0].Name)
82+
assert.Equal(t, "function name2", workflow.Functions[1].Name)
83+
}
84+
}
85+
86+
func TestJson(t *testing.T) {
87+
data, err := Json(prepareBuilder())
88+
if assert.NoError(t, err) {
89+
d := `{"id":"id test","key":"key test","version":"","specVersion":"0.8","expressionLang":"jq","states":[{"name":"state","type":"inject","end":{"terminate":true},"data":{"test":{}}}],"functions":[{"name":"function name","operation":"http://test","type":"rest"},{"name":"function name2","operation":"http://test","type":"rest"}]}`
90+
assert.Equal(t, d, string(data))
91+
}
92+
}
93+
94+
func TestYaml(t *testing.T) {
95+
data, err := Yaml(prepareBuilder())
96+
if assert.NoError(t, err) {
97+
d := `expressionLang: jq
98+
functions:
99+
- name: function name
100+
operation: http://test
101+
type: rest
102+
- name: function name2
103+
operation: http://test
104+
type: rest
105+
id: id test
106+
key: key test
107+
specVersion: "0.8"
108+
states:
109+
- data:
110+
test: {}
111+
end:
112+
terminate: true
113+
name: state
114+
type: inject
115+
version: ""
116+
`
117+
118+
assert.Equal(t, d, string(data))
119+
}
120+
}

code-of-conduct.md

Lines changed: 9 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,11 @@
1-
## CNCF Community Code of Conduct v1.0
1+
# Code of Conduct
22

3-
Other languages available:
4-
- [Chinese/中文](https://github.com/cncf/foundation/blob/master/code-of-conduct-languages/zh.md)
5-
- [German/Deutsch](https://github.com/cncf/foundation/blob/master/code-of-conduct-languages/de.md)
6-
- [Spanish/Español](https://github.com/cncf/foundation/blob/master/code-of-conduct-languages/es.md)
7-
- [French/Français](https://github.com/cncf/foundation/blob/master/code-of-conduct-languages/fr.md)
8-
- [Italian/Italiano](https://github.com/cncf/foundation/blob/master/code-of-conduct-languages/it.md)
9-
- [Japanese/日本語](https://github.com/cncf/foundation/blob/master/code-of-conduct-languages/jp.md)
10-
- [Korean/한국어](https://github.com/cncf/foundation/blob/master/code-of-conduct-languages/ko.md)
11-
- [Ukrainian/Українська](https://github.com/cncf/foundation/blob/master/code-of-conduct-languages/uk.md)
12-
- [Russian/Русский](https://github.com/cncf/foundation/blob/master/code-of-conduct-languages/ru.md)
13-
- [Portuguese/Português](https://github.com/cncf/foundation/blob/master/code-of-conduct-languages/pt.md)
14-
- [Arabic/العربية](https://github.com/cncf/foundation/blob/master/code-of-conduct-languages/ar.md)
15-
- [Polish/Polski](https://github.com/cncf/foundation/blob/master/code-of-conduct-languages/pl.md)
3+
We follow the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/main/code-of-conduct.md).
164

17-
### Contributor Code of Conduct
18-
19-
As contributors and maintainers of this project, and in the interest of fostering
20-
an open and welcoming community, we pledge to respect all people who contribute
21-
through reporting issues, posting feature requests, updating documentation,
22-
submitting pull requests or patches, and other activities.
23-
24-
We are committed to making participation in this project a harassment-free experience for
25-
everyone, regardless of level of experience, gender, gender identity and expression,
26-
sexual orientation, disability, personal appearance, body size, race, ethnicity, age,
27-
religion, or nationality.
28-
29-
Examples of unacceptable behavior by participants include:
30-
31-
* The use of sexualized language or imagery
32-
* Personal attacks
33-
* Trolling or insulting/derogatory comments
34-
* Public or private harassment
35-
* Publishing others' private information, such as physical or electronic addresses,
36-
without explicit permission
37-
* Other unethical or unprofessional conduct.
38-
39-
Project maintainers have the right and responsibility to remove, edit, or reject
40-
comments, commits, code, wiki edits, issues, and other contributions that are not
41-
aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers
42-
commit themselves to fairly and consistently applying these principles to every aspect
43-
of managing this project. Project maintainers who do not follow or enforce the Code of
44-
Conduct may be permanently removed from the project team.
45-
46-
This code of conduct applies both within project spaces and in public spaces
47-
when an individual is representing the project or its community.
48-
49-
Instances of abusive, harassing, or otherwise unacceptable behavior in Kubernetes may be reported by contacting the [Kubernetes Code of Conduct Committee](https://git.k8s.io/community/committee-code-of-conduct) via [email protected]. For other projects, please contact a CNCF project maintainer or our mediator, Mishi Choudhary via [email protected].
50-
51-
This Code of Conduct is adapted from the Contributor Covenant
52-
(<http://contributor-covenant.org>), version 1.2.0, available at
53-
<http://contributor-covenant.org/version/1/2/0/>
54-
55-
### CNCF Events Code of Conduct
56-
57-
CNCF events are governed by the Linux Foundation [Code of Conduct](https://events.linuxfoundation.org/code-of-conduct/) available on the event page.
58-
This is designed to be compatible with the above policy and also includes more details on responding to incidents.
5+
<!-- TODO: Decide who will handle Code of Conduct reports and replace [INSERT EMAIL ADDRESS]
6+
with an email address in the paragraph below. We recommend using a mailing list to handle reports.
7+
If your project isn't prepared to handle reports, remove the project email address and just have
8+
reporters send to [email protected].
9+
-->
10+
Please contact the [CNCF Code of Conduct Committee](mailto:[email protected])
11+
in order to report violations of the Code of Conduct.

go.mod

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ go 1.19
55
require (
66
github.com/go-playground/validator/v10 v10.11.1
77
github.com/pkg/errors v0.9.1
8-
github.com/senseyeio/duration v0.0.0-20180430131211-7c2a214ada46
8+
github.com/relvacode/iso8601 v1.3.0
9+
github.com/sosodev/duration v1.2.0
910
github.com/stretchr/testify v1.8.0
1011
gopkg.in/yaml.v3 v3.0.1
1112
k8s.io/apimachinery v0.26.2
@@ -25,10 +26,10 @@ require (
2526
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
2627
github.com/modern-go/reflect2 v1.0.2 // indirect
2728
github.com/pmezard/go-difflib v1.0.0 // indirect
28-
golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d // indirect
29-
golang.org/x/net v0.7.0 // indirect
30-
golang.org/x/sys v0.5.0 // indirect
31-
golang.org/x/text v0.7.0 // indirect
29+
golang.org/x/crypto v0.15.0 // indirect
30+
golang.org/x/net v0.18.0 // indirect
31+
golang.org/x/sys v0.14.0 // indirect
32+
golang.org/x/text v0.14.0 // indirect
3233
gopkg.in/inf.v0 v0.9.1 // indirect
3334
gopkg.in/yaml.v2 v2.4.0 // indirect
3435
k8s.io/klog/v2 v2.80.2-0.20221028030830-9ae4992afb54 // indirect

go.sum

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
4545
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
4646
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4747
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
48+
github.com/relvacode/iso8601 v1.3.0 h1:HguUjsGpIMh/zsTczGN3DVJFxTU/GX+MMmzcKoMO7ko=
49+
github.com/relvacode/iso8601 v1.3.0/go.mod h1:FlNp+jz+TXpyRqgmM7tnzHHzBnz776kmAH2h3sZCn0I=
4850
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
4951
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
5052
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
51-
github.com/senseyeio/duration v0.0.0-20180430131211-7c2a214ada46 h1:Dz0HrI1AtNSGCE8LXLLqoZU4iuOJXPWndenCsZfstA8=
52-
github.com/senseyeio/duration v0.0.0-20180430131211-7c2a214ada46/go.mod h1:is8FVkzSi7PYLWEXT5MgWhglFsyyiW8ffxAoJqfuFZo=
53+
github.com/sosodev/duration v1.2.0 h1:pqK/FLSjsAADWY74SyWDCjOcd5l7H8GSnnOGEB9A1Us=
54+
github.com/sosodev/duration v1.2.0/go.mod h1:RQIBBX0+fMLc/D9+Jb/fwvVmo0eZvDDEERAikUR6SDg=
5355
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
5456
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
5557
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
@@ -67,8 +69,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
6769
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
6870
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
6971
golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
70-
golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d h1:3qF+Z8Hkrw9sOhrFHti9TlB1Hkac1x+DNRkv0XQiFjo=
71-
golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
72+
golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA=
73+
golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g=
7274
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
7375
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
7476
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
@@ -79,8 +81,8 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY
7981
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
8082
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
8183
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
82-
golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
83-
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
84+
golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg=
85+
golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ=
8486
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
8587
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
8688
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -94,8 +96,8 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
9496
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
9597
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
9698
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
97-
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
98-
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
99+
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
100+
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
99101
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
100102
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
101103
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=

0 commit comments

Comments
 (0)