Skip to content
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

revert: library swap to goccy #144

Merged
merged 2 commits into from
Feb 4, 2021
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
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ module github.com/go-vela/types
go 1.15

require (
github.com/buildkite/yaml v0.0.0-20181016232759-0caa5f0796e3
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/distribution v2.7.1+incompatible
github.com/drone/envsubst v1.0.2
github.com/ghodss/yaml v1.0.0
github.com/goccy/go-yaml v1.8.5
github.com/kr/pretty v0.2.0 // indirect
github.com/lib/pq v1.9.0
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/stretchr/testify v1.6.1 // indirect
golang.org/x/sys v0.0.0-20200409092240-59c9f1ba88fa // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
github.com/buildkite/yaml v0.0.0-20181016232759-0caa5f0796e3 h1:q+sMKdA6L8LyGVudTkpGoC73h6ak2iWSPFiFo/pFOU8=
github.com/buildkite/yaml v0.0.0-20181016232759-0caa5f0796e3/go.mod h1:5hCug3EZaHXU3FdCA3gJm0YTNi+V+ooA2qNTiVpky4A=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/docker/distribution v2.7.1+incompatible h1:a5mlkVzth6W5A4fOsS3D2EO5BUmsJpcB+cRlLU7cSug=
github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/drone/envsubst v1.0.2 h1:dpYLMAspQHW0a8dZpLRKe9jCNvIGZPhCPrycZzIHdqo=
github.com/drone/envsubst v1.0.2/go.mod h1:bkZbnc/2vh1M12Ecn7EYScpI4YGYU0etwLJICOWi8Z0=
github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg=
Expand Down Expand Up @@ -35,8 +35,6 @@ github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
58 changes: 0 additions & 58 deletions yaml/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@

package yaml

import (
"errors"
"fmt"
"strings"
)

// Build is the yaml representation of a build for a pipeline.
// nolint:lll // jsonschema will cause long lines
type Build struct {
Expand All @@ -22,55 +16,3 @@ type Build struct {
Steps StepSlice `yaml:"steps,omitempty" json:"steps,omitempty" jsonschema:"oneof_required=steps,description=Provide sequential execution instructions.\nReference: https://go-vela.github.io/docs/concepts/pipeline/steps/"`
Templates TemplateSlice `yaml:"templates,omitempty" json:"templates,omitempty" jsonschema:"description=Provide the name of templates to expand.\nReference: https://go-vela.github.io/docs/concepts/pipeline/templates/"`
}

// Validate lints if the build configuration is valid.
func (b *Build) Validate(pipeline []byte) error {
invalid := errors.New("invalid pipeline found")

// check a version is provided
if len(b.Version) == 0 {
invalid = fmt.Errorf("%w: %s", invalid, "no version provided")
}

// check that stages or steps are provided
if len(b.Stages) == 0 && len(b.Steps) == 0 {
invalid = fmt.Errorf("%w: %s", invalid, "no stages or steps provided")
}

// check that stages and steps aren't provided
if len(b.Stages) > 0 && len(b.Steps) > 0 {
invalid = fmt.Errorf("%w: %s", invalid, "stages and steps provided")
}

// validate the secrets block provided
err := b.Secrets.Validate(pipeline)
if err != nil {
invalid = fmt.Errorf("%v: %w", invalid, err)
}

// validate the services block provided
err = b.Services.Validate(pipeline)
if err != nil {
invalid = fmt.Errorf("%v: %w", invalid, err)
}

// validate the stages block provided
if len(b.Stages) > 0 {
err = b.Stages.Validate(pipeline)
if err != nil {
invalid = fmt.Errorf("%v: %w", invalid, err)
}
}

// validate the steps block provided
err = b.Steps.Validate(pipeline)
if err != nil {
invalid = fmt.Errorf("%v: %w", invalid, err)
}

if !strings.EqualFold(invalid.Error(), "invalid pipeline found") {
return invalid
}

return nil
}
55 changes: 1 addition & 54 deletions yaml/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"reflect"
"testing"

"github.com/buildkite/yaml"
"github.com/go-vela/types/raw"
"github.com/goccy/go-yaml"
)

func TestYaml_Build_UnmarshalYAML(t *testing.T) {
Expand Down Expand Up @@ -454,56 +454,3 @@ func TestYaml_Build_UnmarshalYAML(t *testing.T) {
}
}
}

func TestYaml_Build_Validate(t *testing.T) {
// setup tests
tests := []struct {
name string
file string
wantErr bool
}{
{
name: "success: valid steps pipeline",
file: "testdata/build/validate/step.yml",
wantErr: false,
},
{
name: "failure: bad version yaml tag",
file: "testdata/build/validate/bad_version.yml",
wantErr: true,
},
{
name: "failure: bad pipeline (no steps/stages)",
file: "testdata/build/validate/bad_version.yml",
wantErr: true,
},

{
name: "failure: bad pipeline (both steps/stages)",
file: "testdata/build/validate/bad_version.yml",
wantErr: true,
},
}

// run tests
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
b := new(Build)

pipeline, err := ioutil.ReadFile(test.file)
if err != nil {
t.Errorf("Reading file for Validate returned err: %v", err)
}

err = yaml.Unmarshal(pipeline, b)

if err != nil {
t.Errorf("Validate returned err: %v", err)
}

if err := b.Validate(pipeline); (err != nil) != test.wantErr {
t.Errorf("Validate is %v, want %v", err, test.wantErr)
}
})
}
}
2 changes: 1 addition & 1 deletion yaml/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/go-vela/types/pipeline"

"github.com/goccy/go-yaml"
"github.com/buildkite/yaml"
)

func TestYaml_Metadata_ToPipeline(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion yaml/ruleset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"reflect"
"testing"

"github.com/buildkite/yaml"
"github.com/go-vela/types/pipeline"
"github.com/goccy/go-yaml"
)

func TestYaml_Ruleset_ToPipeline(t *testing.T) {
Expand Down
Loading