Skip to content

Commit 4322bfb

Browse files
Introducing GitHub Actions to check Go SDK PRs (#9)
1 parent 1405d56 commit 4322bfb

File tree

11 files changed

+172
-14
lines changed

11 files changed

+172
-14
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Copyright 2020 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+
name: Go SDK PR Checks
16+
on:
17+
pull_request:
18+
paths-ignore:
19+
- "**.md"
20+
- "hack/**"
21+
- "LICENSE"
22+
- "Makefile"
23+
branches:
24+
- master
25+
env:
26+
GO_VERSION: 1.14
27+
jobs:
28+
basic_checks:
29+
name: Basic Checks
30+
runs-on: ubuntu-latest
31+
env:
32+
GOLANG_LINT_VERSION: v1.27.0
33+
steps:
34+
- name: Checkout Code
35+
uses: actions/checkout@v2
36+
- name: Setup Go ${{ env.GO_VERSION }}
37+
uses: actions/setup-go@v2
38+
with:
39+
go-version: ${{ env.GO_VERSION }}
40+
id: go
41+
- name: Cache dependencies
42+
uses: actions/cache@v2
43+
with:
44+
path: ~/go/pkg/mod/cache
45+
key: ${{ runner.os }}-go-cache-${{ hashFiles('**/go.sum') }}
46+
restore-keys: |
47+
${{ runner.os }}-go-cache-
48+
- name: Check Headers
49+
run: |
50+
make addheaders
51+
changed_files=$(git status -s | grep -v 'go.mod\|go.sum' || :)
52+
[[ -z "$changed_files" ]] || (printf "Some files are missing the headers: \n$changed_files\n Did you run 'make lint' before sending the PR" && exit 1)
53+
- name: Check Formatting
54+
run: |
55+
make fmt
56+
changed_files=$(git status -s | grep -v 'go.mod\|go.sum' || :)
57+
[[ -z "$changed_files" ]] || (printf "Some files are not formatted properly: \n$changed_files\n Did you run 'make test' before sending the PR?" && exit 1)
58+
- name: Install golinters
59+
run: |
60+
go get -u golang.org/x/lint/golint
61+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin $GOLANG_LINT_VERSION
62+
- name: Check lint
63+
run: |
64+
make lint
65+
- name: Install cover
66+
run: go get golang.org/x/tools/cmd/cover
67+
- run: go mod tidy
68+
- name: Validate codcov yaml file
69+
run: curl -vvv --data-binary @codecov.yml https://codecov.io/validate
70+
- name: Run Unit Tests
71+
run: |
72+
./hack/go-test.sh "true"
73+
- name: Upload results to codecov
74+
uses: codecov/codecov-action@v1
75+
with:
76+
file: ./test_coverage.txt
77+
flags: sdk-go
78+
name: sdk-go
79+
fail_ci_if_error: true

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
bin
22
.idea
3+
*.out

Makefile

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,18 @@ addheaders:
66
@which addlicense > /dev/null || go get -u github.com/google/addlicense
77
@addlicense -c "The Serverless Workflow Specification Authors" -l apache .
88

9-
test:
10-
make addheaders
9+
fmt:
1110
go vet ./...
1211
go fmt ./...
13-
go test ./...
12+
13+
lint:
14+
go mod tidy
15+
make addheaders
16+
make fmt
17+
./hack/go-lint.sh
18+
19+
.PHONY: test
20+
coverage="false"
21+
test:
22+
make lint
23+
./hack/go-test.sh

codecov.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2020 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+
comment:
16+
require_changes: true
17+
coverage:
18+
status:
19+
project:
20+
sdk-go:
21+
target: auto
22+
base: auto
23+
threshold: 5%

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ module github.com/serverlessworkflow/sdk-go
33
go 1.14
44

55
require (
6-
github.com/mitchellh/mapstructure v1.3.3
76
github.com/stretchr/testify v1.6.1
87
gopkg.in/yaml.v2 v2.3.0 // indirect
98
sigs.k8s.io/yaml v1.2.0

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8
22
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
33
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
44
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5-
github.com/mitchellh/mapstructure v1.3.3 h1:SzB1nHZ2Xi+17FP0zVQBHIZqvwRN9408fJO8h+eeNA8=
6-
github.com/mitchellh/mapstructure v1.3.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
75
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
86
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
97
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=

hack/go-lint.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
# Copyright 2020 The Serverless Workflow Specification Authors
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
golint ./... | tee -a golint_errors
17+
if [ -s golint_errors ] ; then
18+
code=1
19+
fi
20+
rm -f golint_errors
21+
# The command in or will fetch the latest tag available for golangci-lint and install in $GOPATH/bin/
22+
command -v golangci-lint > /dev/null || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "$(go env GOPATH)/bin"
23+
golangci-lint run ./... --enable golint --timeout 2m0s
24+
25+
exit ${code:0}

hack/go-test.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
# Copyright 2020 The Serverless Workflow Specification Authors
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
17+
declare coverage=$1
18+
19+
if [[ "${coverage}" == "true" ]]; then
20+
go test ./... -coverprofile=test_coverage.out -covermode=atomic
21+
else
22+
go test ./...
23+
fi

model/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ var actionsModelMapping = map[string]func(state map[string]interface{}) State{
3434
// WorkflowCommon describes the partial Workflow definition that does not rely on generic interfaces
3535
// to make it easy for custom unmarshalers implementations to unmarshal the common data structure.
3636
type WorkflowCommon struct {
37-
Id string `json:"id"`
37+
ID string `json:"id"`
3838
Name string `json:"name"`
3939
Description string `json:"description,omitempty"`
4040
Version string `json:"version"`

parser/parser.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ import (
2525
)
2626

2727
const (
28-
extJson = ".json"
29-
extYaml = ".yaml"
30-
extYml = ".yml"
28+
extJSON = ".json"
29+
extYAML = ".yaml"
30+
extYML = ".yml"
3131
)
3232

33-
var supportedExt = []string{extYaml, extYml, extJson}
33+
var supportedExt = []string{extYAML, extYML, extJSON}
3434

3535
// FromYAMLSource parses the given Serverless Workflow YAML source into the Workflow type.
3636
func FromYAMLSource(source []byte) (workflow *model.Workflow, err error) {
@@ -59,7 +59,7 @@ func FromFile(path string) (*model.Workflow, error) {
5959
if err != nil {
6060
return nil, err
6161
}
62-
if strings.HasSuffix(path, extYaml) || strings.HasSuffix(path, extYml) {
62+
if strings.HasSuffix(path, extYAML) || strings.HasSuffix(path, extYML) {
6363
return FromYAMLSource(fileBytes)
6464
}
6565
return FromJSONSource(fileBytes)

parser/parser_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ import (
2323
func TestFromFile(t *testing.T) {
2424
files := map[string]func(*testing.T, *model.Workflow){
2525
"./testdata/greetings.sw.json": func(t *testing.T, w *model.Workflow) {
26-
assert.Equal(t, "greeting", w.Id)
26+
assert.Equal(t, "greeting", w.ID)
2727
assert.IsType(t, &model.Operationstate{}, w.States[0])
2828
},
2929
"./testdata/greetings.sw.yaml": func(t *testing.T, w *model.Workflow) {
3030
assert.IsType(t, &model.Operationstate{}, w.States[0])
31-
assert.Equal(t, "greeting", w.Id)
31+
assert.Equal(t, "greeting", w.ID)
3232
assert.NotEmpty(t, w.States[0].(*model.Operationstate).Actions)
3333
assert.NotNil(t, w.States[0].(*model.Operationstate).Actions[0].FunctionRef)
3434
},

0 commit comments

Comments
 (0)