revert: "convert gopkg.in/yaml.v3 to goccy/go-yaml (#5579)" (#5683)

Co-authored-by: PePe Amengual <2208324+jamengual@users.noreply.github.com>
This commit is contained in:
Bruno Schaatsbergen
2025-07-31 01:55:35 +02:00
committed by GitHub
parent be773b30a9
commit bcd6420db5
10 changed files with 26 additions and 59 deletions

View File

@@ -24,10 +24,10 @@ import (
"strings"
"testing"
yaml "github.com/goccy/go-yaml"
homedir "github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"gopkg.in/yaml.v3"
"github.com/runatlantis/atlantis/server"
"github.com/runatlantis/atlantis/server/events/vcs/testdata"

3
go.mod
View File

@@ -14,7 +14,6 @@ require (
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible
github.com/go-playground/validator/v10 v10.26.0
github.com/go-test/deep v1.1.1
github.com/goccy/go-yaml v1.17.1
github.com/gofri/go-github-ratelimit v1.1.1
github.com/golang-jwt/jwt/v5 v5.2.2
github.com/google/go-github/v71 v71.0.0
@@ -52,6 +51,7 @@ require (
go.uber.org/zap v1.27.0
golang.org/x/term v0.31.0
golang.org/x/text v0.24.0
gopkg.in/yaml.v3 v3.0.1
)
require (
@@ -141,5 +141,4 @@ require (
golang.org/x/time v0.8.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
google.golang.org/protobuf v1.36.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

2
go.sum
View File

@@ -170,8 +170,6 @@ github.com/go-test/deep v1.1.1 h1:0r/53hagsehfO4bzD2Pgr/+RgHqhmf+k1Bpse2cTu1U=
github.com/go-test/deep v1.1.1/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss=
github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
github.com/goccy/go-yaml v1.17.1 h1:LI34wktB2xEE3ONG/2Ar54+/HJVBriAGJ55PHls4YuY=
github.com/goccy/go-yaml v1.17.1/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
github.com/gofri/go-github-ratelimit v1.1.1 h1:5TCOtFf45M2PjSYU17txqbiYBEzjOuK1+OhivbW69W0=
github.com/gofri/go-github-ratelimit v1.1.1/go.mod h1:wGZlBbzHmIVjwDR3pZgKY7RBTV6gsQWxLVkpfwhcMJM=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=

View File

@@ -13,9 +13,9 @@ import (
validation "github.com/go-ozzo/ozzo-validation"
shlex "github.com/google/shlex"
yaml "github.com/goccy/go-yaml"
"github.com/runatlantis/atlantis/server/core/config/raw"
"github.com/runatlantis/atlantis/server/core/config/valid"
yaml "gopkg.in/yaml.v3"
)
// ParserValidator parses and validates server-side repo config files and
@@ -57,7 +57,8 @@ func (p *ParserValidator) ParseRepoCfg(absRepoDir string, globalCfg valid.Global
func (p *ParserValidator) ParseRepoCfgData(repoCfgData []byte, globalCfg valid.GlobalCfg, repoID string, branch string) (valid.RepoCfg, error) {
var rawConfig raw.RepoCfg
decoder := yaml.NewDecoder(bytes.NewReader(repoCfgData), yaml.Strict())
decoder := yaml.NewDecoder(bytes.NewReader(repoCfgData))
decoder.KnownFields(true)
err := decoder.Decode(&rawConfig)
if err != nil && !errors.Is(err, io.EOF) {
@@ -118,7 +119,8 @@ func (p *ParserValidator) ParseGlobalCfg(configFile string, defaultCfg valid.Glo
var rawCfg raw.GlobalCfg
decoder := yaml.NewDecoder(bytes.NewReader(configData), yaml.Strict())
decoder := yaml.NewDecoder(bytes.NewReader(configData))
decoder.KnownFields(true)
err = decoder.Decode(&rawCfg)
if err != nil && !errors.Is(err, io.EOF) {

View File

@@ -84,12 +84,12 @@ func TestParseCfgs_InvalidYAML(t *testing.T) {
{
"random characters",
"slkjds",
"string was used where mapping is expected",
"yaml: unmarshal errors:\n line 1: cannot unmarshal !!str `slkjds` into",
},
{
"just a colon",
":",
"unexpected key name",
"yaml: did not find expected key",
},
}
@@ -670,12 +670,7 @@ projects:
version: 3
projects:
- unknown: value`,
expErr: `[4:3] unknown field "unknown"
2 | version: 3
3 | projects:
> 4 | - unknown: value
^
`,
expErr: "yaml: unmarshal errors:\n line 4: field unknown not found in type raw.Project",
},
{
description: "referencing workflow that doesn't exist",
@@ -1277,11 +1272,8 @@ func TestParseGlobalCfg(t *testing.T) {
expErr: "file <tmp> was empty",
},
"invalid fields": {
input: "invalid: key",
expErr: `[1:1] unknown field "invalid"
> 1 | invalid: key
^
`,
input: "invalid: key",
expErr: "yaml: unmarshal errors:\n line 1: field invalid not found in type raw.GlobalCfg",
},
"no id specified": {
input: `repos:

View File

@@ -3,11 +3,11 @@ package raw_test
import (
"testing"
yaml "github.com/goccy/go-yaml"
"github.com/hashicorp/go-version"
"github.com/runatlantis/atlantis/server/core/config/raw"
"github.com/runatlantis/atlantis/server/core/config/valid"
. "github.com/runatlantis/atlantis/testing"
yaml "gopkg.in/yaml.v3"
)
func TestPolicySetsConfig_YAMLMarshalling(t *testing.T) {

View File

@@ -6,7 +6,7 @@ import (
"errors"
yaml "github.com/goccy/go-yaml"
"gopkg.in/yaml.v3"
)
// Bool is a helper routine that allocates a new bool value
@@ -23,7 +23,8 @@ func String(v string) *string { return &v }
// Helper function to unmarshal from strings
func unmarshalString(in string, out interface{}) error {
decoder := yaml.NewDecoder(strings.NewReader(in), yaml.Strict())
decoder := yaml.NewDecoder(strings.NewReader(in))
decoder.KnownFields(true)
err := decoder.Decode(out)
if errors.Is(err, io.EOF) {

View File

@@ -45,10 +45,7 @@ func TestConfig_UnmarshalYAML(t *testing.T) {
Projects: nil,
Workflows: nil,
},
expErr: `[1:1] unknown field "invalid"
> 1 | invalid: key
^
`,
expErr: "yaml: unmarshal errors:\n line 1: field invalid not found in type raw.RepoCfg",
},
{
description: "version set to 2",
@@ -94,11 +91,7 @@ func TestConfig_UnmarshalYAML(t *testing.T) {
Projects: nil,
Workflows: nil,
},
expErr: `[2:6] mapping was used where sequence is expected
1 | projects:
> 2 | key: value
^
`,
expErr: "yaml: unmarshal errors:\n line 2: cannot unmarshal !!map into []raw.Project",
},
{
description: "projects with a scalar",
@@ -108,10 +101,7 @@ func TestConfig_UnmarshalYAML(t *testing.T) {
Projects: nil,
Workflows: nil,
},
expErr: `[1:11] string was used where sequence is expected
> 1 | projects: value
^
`,
expErr: "yaml: unmarshal errors:\n line 1: cannot unmarshal !!str `value` into []raw.Project",
},
{
description: "automerge not a boolean",
@@ -121,11 +111,7 @@ func TestConfig_UnmarshalYAML(t *testing.T) {
Projects: nil,
Workflows: nil,
},
expErr: `[2:12] cannot unmarshal string into Go struct field RepoCfg.Automerge of type bool
1 | version: 3
> 2 | automerge: notabool
^
`,
expErr: "yaml: unmarshal errors:\n line 2: cannot unmarshal !!str `notabool` into bool",
},
{
description: "parallel apply not a boolean",
@@ -135,11 +121,8 @@ func TestConfig_UnmarshalYAML(t *testing.T) {
Projects: nil,
Workflows: nil,
},
expErr: `[2:17] cannot unmarshal string into Go struct field RepoCfg.ParallelApply of type bool
1 | version: 3
> 2 | parallel_apply: notabool
^
`},
expErr: "yaml: unmarshal errors:\n line 2: cannot unmarshal !!str `notabool` into bool",
},
{
description: "should use values if set",
input: `

View File

@@ -3,10 +3,10 @@ package raw_test
import (
"testing"
yaml "github.com/goccy/go-yaml"
"github.com/runatlantis/atlantis/server/core/config/raw"
"github.com/runatlantis/atlantis/server/core/config/valid"
. "github.com/runatlantis/atlantis/testing"
yaml "gopkg.in/yaml.v3"
)
func TestStepConfig_YAMLMarshalling(t *testing.T) {
@@ -148,11 +148,7 @@ key: value`,
key:
- value:
another: map`,
expErr: `[3:2] sequence was used where mapping is expected
2 | key:
> 3 | - value:
^
4 | another: map`,
expErr: "yaml: unmarshal errors:\n line 3: cannot unmarshal !!seq into map[string]interface {}",
},
}

View File

@@ -3,10 +3,10 @@ package raw_test
import (
"testing"
yaml "github.com/goccy/go-yaml"
"github.com/runatlantis/atlantis/server/core/config/raw"
"github.com/runatlantis/atlantis/server/core/config/valid"
. "github.com/runatlantis/atlantis/testing"
yaml "gopkg.in/yaml.v3"
)
func TestWorkflowHook_YAMLMarshalling(t *testing.T) {
@@ -47,11 +47,7 @@ key: value`,
key:
value:
another: map`,
expErr: `[3:8] cannot unmarshal map[string]interface {} into Go value of type string
2 | key:
> 3 | value:
^
4 | another: map`,
expErr: "yaml: unmarshal errors:\n line 3: cannot unmarshal !!map into string",
},
}