diff --git a/go.mod b/go.mod index a2abfc312..d01db3634 100644 --- a/go.mod +++ b/go.mod @@ -38,7 +38,7 @@ require ( golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 golang.org/x/sync v0.0.0-20210220032951-036812b2e83c gopkg.in/mail.v2 v2.3.1 - gopkg.in/yaml.v2 v2.4.0 + gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b ) require ( @@ -147,5 +147,5 @@ require ( google.golang.org/protobuf v1.27.1 // indirect gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect gopkg.in/warnings.v0 v0.1.2 // indirect - gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/internal/pipe/effectiveconfig/config.go b/internal/pipe/effectiveconfig/config.go index 5b4280c49..10fefa4b1 100644 --- a/internal/pipe/effectiveconfig/config.go +++ b/internal/pipe/effectiveconfig/config.go @@ -5,8 +5,8 @@ import ( "path/filepath" "github.com/apex/log" + "github.com/goreleaser/goreleaser/internal/yaml" "github.com/goreleaser/goreleaser/pkg/context" - yaml "gopkg.in/yaml.v2" ) // Pipe that writes the effective config file to dist. diff --git a/internal/pipe/krew/krew.go b/internal/pipe/krew/krew.go index fecbbd416..39222e969 100644 --- a/internal/pipe/krew/krew.go +++ b/internal/pipe/krew/krew.go @@ -19,9 +19,9 @@ import ( "github.com/goreleaser/goreleaser/internal/commitauthor" "github.com/goreleaser/goreleaser/internal/pipe" "github.com/goreleaser/goreleaser/internal/tmpl" + "github.com/goreleaser/goreleaser/internal/yaml" "github.com/goreleaser/goreleaser/pkg/config" "github.com/goreleaser/goreleaser/pkg/context" - "gopkg.in/yaml.v2" ) const ( diff --git a/internal/pipe/krew/testdata/TestFullManifest.yaml b/internal/pipe/krew/testdata/TestFullManifest.yaml index 03ec7d004..8cbb9eb77 100644 --- a/internal/pipe/krew/testdata/TestFullManifest.yaml +++ b/internal/pipe/krew/testdata/TestFullManifest.yaml @@ -5,48 +5,48 @@ metadata: spec: version: v0.1.3 platforms: - - bin: test - uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_x86_64.tar.gz - sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68 - selector: - matchLabels: - os: darwin - arch: amd64 - - bin: test - uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_arm64.tar.gz - sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68 - selector: - matchLabels: - os: darwin - arch: arm64 - - bin: test - uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_x86_64.tar.gz - sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67 - selector: - matchLabels: - os: linux - arch: amd64 - - bin: test - uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm6.tar.gz - sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67 - selector: - matchLabels: - os: linux - arch: arm - - bin: test - uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm64.tar.gz - sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67 - selector: - matchLabels: - os: linux - arch: arm64 - - bin: test.exe - uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_windows_amd64.zip - sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67 - selector: - matchLabels: - os: windows - arch: amd64 + - bin: test + uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_x86_64.tar.gz + sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68 + selector: + matchLabels: + os: darwin + arch: amd64 + - bin: test + uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_arm64.tar.gz + sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68 + selector: + matchLabels: + os: darwin + arch: arm64 + - bin: test + uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_x86_64.tar.gz + sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67 + selector: + matchLabels: + os: linux + arch: amd64 + - bin: test + uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm6.tar.gz + sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67 + selector: + matchLabels: + os: linux + arch: arm + - bin: test + uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm64.tar.gz + sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67 + selector: + matchLabels: + os: linux + arch: arm64 + - bin: test.exe + uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_windows_amd64.zip + sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67 + selector: + matchLabels: + os: windows + arch: amd64 shortDescription: Short desc homepage: https://google.com caveats: some caveat diff --git a/internal/pipe/krew/testdata/TestFullPipe/default.yaml b/internal/pipe/krew/testdata/TestFullPipe/default.yaml index 9aedb504e..d3d181a4c 100644 --- a/internal/pipe/krew/testdata/TestFullPipe/default.yaml +++ b/internal/pipe/krew/testdata/TestFullPipe/default.yaml @@ -5,13 +5,13 @@ metadata: spec: version: v1.0.1 platforms: - - bin: name - uri: https://dummyhost/download/v1.0.1/bin.tar.gz - sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 - selector: - matchLabels: - os: darwin - arch: amd64 + - bin: name + uri: https://dummyhost/download/v1.0.1/bin.tar.gz + sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 + selector: + matchLabels: + os: darwin + arch: amd64 shortDescription: short desc honk homepage: https://github.com/goreleaser description: A run pipe test krew manifest and FOO=foo_is_bar diff --git a/internal/pipe/krew/testdata/TestFullPipe/default_gitlab.yaml b/internal/pipe/krew/testdata/TestFullPipe/default_gitlab.yaml index c83995674..ead09fc9f 100644 --- a/internal/pipe/krew/testdata/TestFullPipe/default_gitlab.yaml +++ b/internal/pipe/krew/testdata/TestFullPipe/default_gitlab.yaml @@ -5,13 +5,13 @@ metadata: spec: version: v1.0.1 platforms: - - bin: name - uri: https://dummyhost/download/v1.0.1/bin.tar.gz - sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 - selector: - matchLabels: - os: darwin - arch: amd64 + - bin: name + uri: https://dummyhost/download/v1.0.1/bin.tar.gz + sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 + selector: + matchLabels: + os: darwin + arch: amd64 shortDescription: short desc honk homepage: https://gitlab.com/goreleaser description: A run pipe test krew manifest and FOO=foo_is_bar diff --git a/internal/pipe/krew/testdata/TestRunPipeForMultipleArmVersions/multiple_armv5.yaml b/internal/pipe/krew/testdata/TestRunPipeForMultipleArmVersions/multiple_armv5.yaml index 52f885882..0ae3e60f3 100644 --- a/internal/pipe/krew/testdata/TestRunPipeForMultipleArmVersions/multiple_armv5.yaml +++ b/internal/pipe/krew/testdata/TestRunPipeForMultipleArmVersions/multiple_armv5.yaml @@ -5,27 +5,27 @@ metadata: spec: version: v1.0.1 platforms: - - bin: foo - uri: https://dummyhost/download/v1.0.1/bin.tar.gz - sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 - selector: - matchLabels: - os: darwin - arch: amd64 - - bin: foo - uri: https://dummyhost/download/v1.0.1/armv5.tar.gz - sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 - selector: - matchLabels: - os: linux - arch: arm - - bin: foo - uri: https://dummyhost/download/v1.0.1/arm64.tar.gz - sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 - selector: - matchLabels: - os: linux - arch: arm64 + - bin: foo + uri: https://dummyhost/download/v1.0.1/bin.tar.gz + sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 + selector: + matchLabels: + os: darwin + arch: amd64 + - bin: foo + uri: https://dummyhost/download/v1.0.1/armv5.tar.gz + sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 + selector: + matchLabels: + os: linux + arch: arm + - bin: foo + uri: https://dummyhost/download/v1.0.1/arm64.tar.gz + sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 + selector: + matchLabels: + os: linux + arch: arm64 shortDescription: Short desc homepage: https://github.com/goreleaser description: A run pipe test krew manifest and FOO=foo_is_bar diff --git a/internal/pipe/krew/testdata/TestRunPipeForMultipleArmVersions/multiple_armv6.yaml b/internal/pipe/krew/testdata/TestRunPipeForMultipleArmVersions/multiple_armv6.yaml index b99664ec4..50096a409 100644 --- a/internal/pipe/krew/testdata/TestRunPipeForMultipleArmVersions/multiple_armv6.yaml +++ b/internal/pipe/krew/testdata/TestRunPipeForMultipleArmVersions/multiple_armv6.yaml @@ -5,27 +5,27 @@ metadata: spec: version: v1.0.1 platforms: - - bin: foo - uri: https://dummyhost/download/v1.0.1/bin.tar.gz - sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 - selector: - matchLabels: - os: darwin - arch: amd64 - - bin: foo - uri: https://dummyhost/download/v1.0.1/armv6.tar.gz - sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 - selector: - matchLabels: - os: linux - arch: arm - - bin: foo - uri: https://dummyhost/download/v1.0.1/arm64.tar.gz - sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 - selector: - matchLabels: - os: linux - arch: arm64 + - bin: foo + uri: https://dummyhost/download/v1.0.1/bin.tar.gz + sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 + selector: + matchLabels: + os: darwin + arch: amd64 + - bin: foo + uri: https://dummyhost/download/v1.0.1/armv6.tar.gz + sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 + selector: + matchLabels: + os: linux + arch: arm + - bin: foo + uri: https://dummyhost/download/v1.0.1/arm64.tar.gz + sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 + selector: + matchLabels: + os: linux + arch: arm64 shortDescription: Short desc homepage: https://github.com/goreleaser description: A run pipe test krew manifest and FOO=foo_is_bar diff --git a/internal/pipe/krew/testdata/TestRunPipeForMultipleArmVersions/multiple_armv7.yaml b/internal/pipe/krew/testdata/TestRunPipeForMultipleArmVersions/multiple_armv7.yaml index 98f57ee31..eff01a0a0 100644 --- a/internal/pipe/krew/testdata/TestRunPipeForMultipleArmVersions/multiple_armv7.yaml +++ b/internal/pipe/krew/testdata/TestRunPipeForMultipleArmVersions/multiple_armv7.yaml @@ -5,27 +5,27 @@ metadata: spec: version: v1.0.1 platforms: - - bin: foo - uri: https://dummyhost/download/v1.0.1/bin.tar.gz - sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 - selector: - matchLabels: - os: darwin - arch: amd64 - - bin: foo - uri: https://dummyhost/download/v1.0.1/armv7.tar.gz - sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 - selector: - matchLabels: - os: linux - arch: arm - - bin: foo - uri: https://dummyhost/download/v1.0.1/arm64.tar.gz - sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 - selector: - matchLabels: - os: linux - arch: arm64 + - bin: foo + uri: https://dummyhost/download/v1.0.1/bin.tar.gz + sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 + selector: + matchLabels: + os: darwin + arch: amd64 + - bin: foo + uri: https://dummyhost/download/v1.0.1/armv7.tar.gz + sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 + selector: + matchLabels: + os: linux + arch: arm + - bin: foo + uri: https://dummyhost/download/v1.0.1/arm64.tar.gz + sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 + selector: + matchLabels: + os: linux + arch: arm64 shortDescription: Short desc homepage: https://github.com/goreleaser description: A run pipe test krew manifest and FOO=foo_is_bar diff --git a/internal/pipe/krew/testdata/TestRunPipeNameTemplate.yaml b/internal/pipe/krew/testdata/TestRunPipeNameTemplate.yaml index cda6f051d..24c2ef3a8 100644 --- a/internal/pipe/krew/testdata/TestRunPipeNameTemplate.yaml +++ b/internal/pipe/krew/testdata/TestRunPipeNameTemplate.yaml @@ -5,12 +5,12 @@ metadata: spec: version: v1.0.1 platforms: - - bin: foo - uri: https://dummyhost/download/v1.0.1/bin.tar.gz - sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 - selector: - matchLabels: - os: darwin - arch: amd64 + - bin: foo + uri: https://dummyhost/download/v1.0.1/bin.tar.gz + sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 + selector: + matchLabels: + os: darwin + arch: amd64 shortDescription: Short desc description: Some desc diff --git a/internal/pipe/krew/testdata/TestRunPipeUniversalBinary.yaml b/internal/pipe/krew/testdata/TestRunPipeUniversalBinary.yaml index 281b2030f..612c1ed2f 100644 --- a/internal/pipe/krew/testdata/TestRunPipeUniversalBinary.yaml +++ b/internal/pipe/krew/testdata/TestRunPipeUniversalBinary.yaml @@ -5,19 +5,19 @@ metadata: spec: version: v1.0.1 platforms: - - bin: unibin - uri: https://dummyhost/download/v1.0.1/unibin.tar.gz - sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 - selector: - matchLabels: - os: darwin - arch: amd64 - - bin: unibin - uri: https://dummyhost/download/v1.0.1/unibin.tar.gz - sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 - selector: - matchLabels: - os: darwin - arch: arm64 + - bin: unibin + uri: https://dummyhost/download/v1.0.1/unibin.tar.gz + sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 + selector: + matchLabels: + os: darwin + arch: amd64 + - bin: unibin + uri: https://dummyhost/download/v1.0.1/unibin.tar.gz + sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 + selector: + matchLabels: + os: darwin + arch: arm64 shortDescription: Short desc description: Some desc diff --git a/internal/pipe/krew/testdata/TestRunPipeUniversalBinaryNotReplacing.yaml b/internal/pipe/krew/testdata/TestRunPipeUniversalBinaryNotReplacing.yaml index 09c7ad9ce..355785869 100644 --- a/internal/pipe/krew/testdata/TestRunPipeUniversalBinaryNotReplacing.yaml +++ b/internal/pipe/krew/testdata/TestRunPipeUniversalBinaryNotReplacing.yaml @@ -5,19 +5,19 @@ metadata: spec: version: v1.0.1 platforms: - - bin: unibin - uri: https://dummyhost/download/v1.0.1/unibin_amd64.tar.gz - sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 - selector: - matchLabels: - os: darwin - arch: amd64 - - bin: unibin - uri: https://dummyhost/download/v1.0.1/unibin_amd64.tar.gz - sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 - selector: - matchLabels: - os: darwin - arch: arm64 + - bin: unibin + uri: https://dummyhost/download/v1.0.1/unibin_amd64.tar.gz + sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 + selector: + matchLabels: + os: darwin + arch: amd64 + - bin: unibin + uri: https://dummyhost/download/v1.0.1/unibin_amd64.tar.gz + sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 + selector: + matchLabels: + os: darwin + arch: arm64 shortDescription: Short desc description: Some desc diff --git a/internal/pipe/krew/testdata/TestSimple.yaml b/internal/pipe/krew/testdata/TestSimple.yaml index f37a82444..9a4f7cfc3 100644 --- a/internal/pipe/krew/testdata/TestSimple.yaml +++ b/internal/pipe/krew/testdata/TestSimple.yaml @@ -5,48 +5,48 @@ metadata: spec: version: v0.1.3 platforms: - - bin: test - uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_x86_64.tar.gz - sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68 - selector: - matchLabels: - os: darwin - arch: amd64 - - bin: test - uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_arm64.tar.gz - sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68 - selector: - matchLabels: - os: darwin - arch: arm64 - - bin: test - uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_x86_64.tar.gz - sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67 - selector: - matchLabels: - os: linux - arch: amd64 - - bin: test - uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm6.tar.gz - sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67 - selector: - matchLabels: - os: linux - arch: arm - - bin: test - uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm64.tar.gz - sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67 - selector: - matchLabels: - os: linux - arch: arm64 - - bin: test.exe - uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_windows_amd64.zip - sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67 - selector: - matchLabels: - os: windows - arch: amd64 + - bin: test + uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_x86_64.tar.gz + sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68 + selector: + matchLabels: + os: darwin + arch: amd64 + - bin: test + uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_Darwin_arm64.tar.gz + sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c68 + selector: + matchLabels: + os: darwin + arch: arm64 + - bin: test + uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_Linux_x86_64.tar.gz + sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67 + selector: + matchLabels: + os: linux + arch: amd64 + - bin: test + uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm6.tar.gz + sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67 + selector: + matchLabels: + os: linux + arch: arm + - bin: test + uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_Arm64.tar.gz + sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67 + selector: + matchLabels: + os: linux + arch: arm64 + - bin: test.exe + uri: https://github.com/caarlos0/test/releases/download/v0.1.3/test_windows_amd64.zip + sha256: 1633f61598ab0791e213135923624eb342196b3494909c91899bcd0560f84c67 + selector: + matchLabels: + os: windows + arch: amd64 shortDescription: Short desc homepage: https://google.com caveats: some caveat diff --git a/internal/pipe/snapcraft/snapcraft.go b/internal/pipe/snapcraft/snapcraft.go index b386ed262..30df4c70b 100644 --- a/internal/pipe/snapcraft/snapcraft.go +++ b/internal/pipe/snapcraft/snapcraft.go @@ -12,7 +12,7 @@ import ( "strings" "github.com/apex/log" - "gopkg.in/yaml.v2" + "github.com/goreleaser/goreleaser/internal/yaml" "github.com/goreleaser/goreleaser/internal/artifact" "github.com/goreleaser/goreleaser/internal/gio" diff --git a/internal/pipe/snapcraft/snapcraft_test.go b/internal/pipe/snapcraft/snapcraft_test.go index 78fdddc4e..7041acaa1 100644 --- a/internal/pipe/snapcraft/snapcraft_test.go +++ b/internal/pipe/snapcraft/snapcraft_test.go @@ -10,10 +10,10 @@ import ( "github.com/goreleaser/goreleaser/internal/gio" "github.com/goreleaser/goreleaser/internal/pipe" "github.com/goreleaser/goreleaser/internal/testlib" + "github.com/goreleaser/goreleaser/internal/yaml" "github.com/goreleaser/goreleaser/pkg/config" "github.com/goreleaser/goreleaser/pkg/context" "github.com/stretchr/testify/require" - "gopkg.in/yaml.v2" ) func TestDescription(t *testing.T) { @@ -273,7 +273,7 @@ func TestRunPipeMetadata(t *testing.T) { RestartDelay: "42ms", Slots: []string{"foo_slot"}, Sockets: map[string]interface{}{ - "sock": map[interface{}]interface{}{ + "sock": map[string]interface{}{ "listen-stream": "$SNAP_COMMON/socket", "socket-group": "socket-group", "socket-mode": 0o640, @@ -287,7 +287,7 @@ func TestRunPipeMetadata(t *testing.T) { WatchdogTimeout: "45ms", }, }, metadata.Apps) - require.Equal(t, map[interface{}]interface{}{"read": []interface{}{"$HOME/test"}}, metadata.Plugs["personal-files"]) + require.Equal(t, map[string]interface{}{"read": []interface{}{"$HOME/test"}}, metadata.Plugs["personal-files"]) require.Equal(t, "$SNAP_DATA/etc", metadata.Layout["/etc/testprojectname"].Bind) } diff --git a/internal/yaml/yaml.go b/internal/yaml/yaml.go new file mode 100644 index 000000000..a876a2a1b --- /dev/null +++ b/internal/yaml/yaml.go @@ -0,0 +1,52 @@ +// Package yaml wraps gopkg.in/yaml.v3 and helps transition from v2. +package yaml + +import ( + "bytes" + "errors" + "io" + + yaml "gopkg.in/yaml.v3" +) + +// UnmarshalStrict unmarshals a YAML document with strict behavior (only declared fields are tolerated). +func UnmarshalStrict(in []byte, out interface{}) error { + decoder := yaml.NewDecoder(bytes.NewReader(in)) + decoder.KnownFields(true) + + return handleErr(decoder.Decode(out)) +} + +// Unmarshal some struct as a YAML document, without strict behavior. +func Unmarshal(in []byte, out interface{}) error { + decoder := yaml.NewDecoder(bytes.NewReader(in)) + decoder.KnownFields(false) + + return handleErr(decoder.Decode(out)) +} + +// Marshal some struct as a YAML document. +func Marshal(in interface{}) ([]byte, error) { + b := new(bytes.Buffer) + encoder := yaml.NewEncoder(b) + encoder.SetIndent(2) // default is 4 + + if err := encoder.Encode(in); err != nil { + encoder.Close() + + return nil, err + } + + encoder.Close() + + return b.Bytes(), nil +} + +// handleErr mutes io.EOF errors for backward-compatibility. +func handleErr(err error) error { + if err != nil && !errors.Is(err, io.EOF) { + return err + } + + return nil +} diff --git a/internal/yaml/yaml_test.go b/internal/yaml/yaml_test.go new file mode 100644 index 000000000..842490308 --- /dev/null +++ b/internal/yaml/yaml_test.go @@ -0,0 +1,264 @@ +package yaml + +import ( + "bytes" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestYAMLMarshalError(t *testing.T) { + t.Parallel() + + type yamlMarshalError struct { + BoolValue bool `yaml:"bool_value"` + FuncValue func() `yaml:"func_value"` + } + + v := yamlMarshalError{ + BoolValue: true, + FuncValue: func() {}, + } + + require.Panics(t, func() { + _, _ = Marshal(v) + }) +} + +func TestYAML(t *testing.T) { + t.Parallel() + + type ( + yamlKey struct { + BoolValue bool `yaml:"bool_value"` + NumberValue float64 `yaml:"number_value"` + StringValue string `yaml:"string_value"` + } + yamlObject struct { + Array []string `yaml:"array"` + Key yamlKey `yaml:"key"` + } + yamlReceiver struct { + Object yamlObject `yaml:"object"` + } + + interfaceOrObject struct { + obj yamlReceiver + iface interface{} + } + ) + + for _, toPin := range []struct { + Title string + InputYAML []byte + ExpectedYAML []byte // optional: when marshaled YAML is expected to differ from raw input (e.g. on bool flags) + Expected interfaceOrObject // maybe either untyped interface{} or yamlObject struct with struct tags + ExpectError bool + WantsStrict bool // apply Strict mode + }{ + { + Title: "happy path, untyped", + InputYAML: testYAMLObject(), + Expected: interfaceOrObject{ + iface: map[string]interface{}{ + "object": map[string]interface{}{ + "key": map[string]interface{}{ + "string_value": "This is a doc.\nOn multiple lines.\n", + "bool_value": "y", + "number_value": 10.23, + }, + "array": []interface{}{"x", "y"}, + }, + }, + }, + }, + { + Title: "happy path strict, untyped", + InputYAML: testYAMLObject(), + WantsStrict: true, + Expected: interfaceOrObject{ + iface: map[string]interface{}{ + "object": map[string]interface{}{ + "key": map[string]interface{}{ + "string_value": "This is a doc.\nOn multiple lines.\n", + "bool_value": "y", + "number_value": 10.23, + }, + "array": []interface{}{"x", "y"}, + }, + }, + }, + }, + { + Title: "happy path strict, explicit target", + InputYAML: testYAMLObject(), + ExpectedYAML: testYAMLObjectBool(), + WantsStrict: true, + Expected: interfaceOrObject{ + iface: nil, + obj: yamlReceiver{ + Object: yamlObject{ + Key: yamlKey{ + StringValue: "This is a doc.\nOn multiple lines.\n", + BoolValue: true, + NumberValue: 10.23, + }, + Array: []string{"x", "y"}, + }, + }, + }, + }, + { + Title: "happy path non-strict, explicit target", + InputYAML: testYAMLObjectNonStrict(), + ExpectedYAML: testYAMLObjectBool(), + WantsStrict: false, + Expected: interfaceOrObject{ + iface: nil, + obj: yamlReceiver{ + Object: yamlObject{ + Key: yamlKey{ + StringValue: "This is a doc.\nOn multiple lines.\n", + BoolValue: true, + NumberValue: 10.23, + }, + Array: []string{"x", "y"}, + }, + }, + }, + }, + { + Title: "happy path strict, explicit target: unknown field failure", + InputYAML: testYAMLObjectNonStrict(), + ExpectedYAML: testYAMLObjectBool(), + WantsStrict: true, + ExpectError: true, + Expected: interfaceOrObject{ + iface: nil, + obj: yamlReceiver{ + Object: yamlObject{ + Key: yamlKey{ + StringValue: "This is a doc.\nOn multiple lines.\n", + BoolValue: true, + NumberValue: 10.23, + }, + Array: []string{"x", "y"}, + }, + }, + }, + }, + } { + testCase := toPin + + t.Run(testCase.Title, func(t *testing.T) { + t.Parallel() + + var ( + err error + b, expectedOutput []byte + ) + iface := testCase.Expected.iface + obj := testCase.Expected.obj + + expectedInput := toPlainYaml(testCase.InputYAML) + + if testCase.WantsStrict { + if iface != nil { + err = UnmarshalStrict(expectedInput, &iface) + } else { + err = UnmarshalStrict(expectedInput, &obj) + } + } else { + if iface != nil { + err = Unmarshal(expectedInput, &iface) + } else { + err = Unmarshal(expectedInput, &obj) + } + } + + if testCase.ExpectError { + require.Error(t, err) + + return + } + + require.NoError(t, err) + + if iface != nil { + require.EqualValues(t, testCase.Expected.iface, iface) + + b, err = Marshal(iface) + require.NoError(t, err) + } else { + require.EqualValues(t, testCase.Expected.obj, obj) + + b, err = Marshal(obj) + require.NoError(t, err) + } + + if testCase.ExpectedYAML == nil { + expectedOutput = expectedInput + } else { + expectedOutput = toPlainYaml(testCase.ExpectedYAML) + } + + require.EqualValues(t, expectedOutput, b) + }) + } +} + +func toPlainYaml(in []byte) []byte { + // ensure we got legit yaml for go strings that may have been reindented using tabs, or leading new CR in source. + return bytes.ReplaceAll( + bytes.TrimLeft(in, "\n\r"), + []byte("\t"), bytes.Repeat([]byte(" "), 4), + ) +} + +func testYAMLObject() []byte { + return []byte(` +object: + array: + - x + - "y" + key: + bool_value: "y" + number_value: 10.23 + string_value: | + This is a doc. + On multiple lines. +`) +} + +func testYAMLObjectBool() []byte { + // same object, but the "y" YAML for bool has been marshaled as "true" + return []byte(` +object: + array: + - x + - "y" + key: + bool_value: true + number_value: 10.23 + string_value: | + This is a doc. + On multiple lines. +`) +} + +func testYAMLObjectNonStrict() []byte { + // same object, but with an extra unknown value + return []byte(` +object: + array: + - x + - "y" + key: + bool_value: true + number_value: 10.23 + string_value: | + This is a doc. + On multiple lines. + unknown: 'wrong' +`) +} diff --git a/pkg/config/config.go b/pkg/config/config.go index 899dc05e4..15e63d0dd 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -11,8 +11,8 @@ import ( "github.com/alecthomas/jsonschema" "github.com/apex/log" + "github.com/goreleaser/goreleaser/internal/yaml" "github.com/goreleaser/nfpm/v2/files" - yaml "gopkg.in/yaml.v2" ) // GitHubURLs holds the URLs to be used when using github enterprise. diff --git a/pkg/config/config_archive_files_test.go b/pkg/config/config_archive_files_test.go index 24b63179b..b6b13f9c9 100644 --- a/pkg/config/config_archive_files_test.go +++ b/pkg/config/config_archive_files_test.go @@ -5,8 +5,8 @@ import ( "testing" "time" + "github.com/goreleaser/goreleaser/internal/yaml" "github.com/stretchr/testify/require" - yaml "gopkg.in/yaml.v2" ) func TestArchiveFiles_justString(t *testing.T) { diff --git a/pkg/config/config_array_test.go b/pkg/config/config_array_test.go index 59753d316..a4cd70caf 100644 --- a/pkg/config/config_array_test.go +++ b/pkg/config/config_array_test.go @@ -3,8 +3,8 @@ package config import ( "testing" + "github.com/goreleaser/goreleaser/internal/yaml" "github.com/stretchr/testify/require" - yaml "gopkg.in/yaml.v2" ) type Unmarshaled struct { diff --git a/pkg/config/config_build_hook_test.go b/pkg/config/config_build_hook_test.go index 442747cbe..a6b21fdd9 100644 --- a/pkg/config/config_build_hook_test.go +++ b/pkg/config/config_build_hook_test.go @@ -3,8 +3,8 @@ package config import ( "testing" + "github.com/goreleaser/goreleaser/internal/yaml" "github.com/stretchr/testify/require" - yaml "gopkg.in/yaml.v2" ) func TestBuildHook_justString(t *testing.T) {