From 4f6c82a5a017e65baa37ebfcb4bbef76cffa1571 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sat, 1 Nov 2025 21:08:01 +0100 Subject: [PATCH] Switch yaml parsing to goccy/go-yaml go-yaml/yaml has been deprecated by its maintainer; Move to goccy/go-yaml, which is an actively maintained from a scratch yaml implementation in pure go. It should able to parse all yaml file go-yaml could, and more. As an extra benefit its errors are a lot better. Fixes: #592 Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --- actions/recipe.go | 4 ++-- actions/recipe_test.go | 4 ++-- go.mod | 2 +- go.sum | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/actions/recipe.go b/actions/recipe.go index 0ae1d47..4d0f448 100644 --- a/actions/recipe.go +++ b/actions/recipe.go @@ -90,8 +90,8 @@ import ( "fmt" "github.com/go-debos/debos" "github.com/go-task/slim-sprig/v3" + "github.com/goccy/go-yaml" "github.com/google/uuid" - "gopkg.in/yaml.v2" "log" "path" "reflect" @@ -298,7 +298,7 @@ func (r *Recipe) Parse(file string, printRecipe bool, dump bool, templateVars .. log.Printf("%s", data) } - if err := yaml.Unmarshal(data.Bytes(), &r); err != nil { + if err := yaml.Unmarshal(data.Bytes(), r); err != nil { return err } diff --git a/actions/recipe_test.go b/actions/recipe_test.go index 5739c08..f69baf4 100644 --- a/actions/recipe_test.go +++ b/actions/recipe_test.go @@ -87,7 +87,7 @@ architecture: arm64 }, // Test of wrong syntax in Yaml {`wrong`, - "yaml: unmarshal errors:\n line 1: cannot unmarshal !!str `wrong` into actions.Recipe", + "[1:1] string was used where mapping is expected\n> 1 | wrong\n ^\n", }, // Test if no actions listed {` @@ -294,7 +294,7 @@ actions: `, recipeArmhf, "", - "yaml: unmarshal errors:\n line 8: cannot unmarshal !!seq into map[string]string", + "[8:7] sequence was used where mapping is expected\n 5 | - action: recipe\n 6 | recipe: armhf.yaml\n 7 | variables:\n> 8 | - foo\n ^\n", }, } diff --git a/go.mod b/go.mod index a19634d..d72d013 100644 --- a/go.mod +++ b/go.mod @@ -8,11 +8,11 @@ require ( github.com/freddierice/go-losetup/v2 v2.0.1 github.com/go-debos/fakemachine v0.0.12 github.com/go-task/slim-sprig/v3 v3.0.0 + github.com/goccy/go-yaml v1.18.0 github.com/google/uuid v1.6.0 github.com/jessevdk/go-flags v1.6.1 github.com/sjoerdsimons/ostree-go v0.0.0-20201014091107-8fae757256f8 github.com/stretchr/testify v1.11.1 - gopkg.in/yaml.v2 v2.4.0 ) require ( diff --git a/go.sum b/go.sum index e11afa5..c1edeff 100644 --- a/go.sum +++ b/go.sum @@ -12,6 +12,8 @@ github.com/go-debos/fakemachine v0.0.12 h1:NbOFyWnc8xamXDgat/WrXym9LQn4P4gJ1/sWz github.com/go-debos/fakemachine v0.0.12/go.mod h1:vv6ZYmaY8qofwdZF3BZJW6xvb2fxUuKX59bQdGu6sRI= github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= +github.com/goccy/go-yaml v1.18.0 h1:8W7wMFS12Pcas7KU+VVkaiCng+kG8QiFeFwzFb+rwuw= +github.com/goccy/go-yaml v1.18.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= @@ -34,7 +36,5 @@ golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=