diff --git a/go.sum b/go.sum index 7436e82..8035122 100644 --- a/go.sum +++ b/go.sum @@ -53,6 +53,7 @@ github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAm github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/vinzenz/yaml v0.0.0-20170920082545-91409cdd725d h1:3wDi6J5APMqaHBVPuVd7RmHD2gRTfqbdcVSpCNoUWtk= github.com/vinzenz/yaml v0.0.0-20170920082545-91409cdd725d/go.mod h1:mb5taDqMnJiZNRQ3+02W2IFG+oEz1+dTuCXkp4jpkfo= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= diff --git a/yaml/converter/legacy/internal/config.go b/yaml/converter/legacy/internal/config.go index de2ddd1..bce1f94 100644 --- a/yaml/converter/legacy/internal/config.go +++ b/yaml/converter/legacy/internal/config.go @@ -39,6 +39,13 @@ type Config struct { // Convert converts the yaml configuration file from // the legacy format to the 1.0+ format. func Convert(d []byte) ([]byte, error) { + // hack: this is a hack to support teams migrating + // from 0.8 to 1.0 that are using yaml merge keys. + // it can be removed in a future version. + if hasMergeKeys(d) { + d, _ = expandMergeKeys(d) + } + from := new(Config) err := yaml.Unmarshal(d, from) diff --git a/yaml/converter/legacy/internal/yaml.go b/yaml/converter/legacy/internal/yaml.go new file mode 100644 index 0000000..1e4f32a --- /dev/null +++ b/yaml/converter/legacy/internal/yaml.go @@ -0,0 +1,28 @@ +// Copyright 2019 Drone.IO Inc. All rights reserved. +// Use of this source code is governed by the Drone Non-Commercial License +// that can be found in the LICENSE file. + +package yaml + +import ( + "bytes" + + "github.com/vinzenz/yaml" +) + +// this is a helper function that expands merge keys +func expandMergeKeys(b []byte) ([]byte, error) { + v := map[interface{}]interface{}{} + if err := yaml.Unmarshal(b, v); err != nil { + return b, err + } + o, err := yaml.Marshal(v) + if err != nil { + return b, err + } + return o, nil +} + +func hasMergeKeys(b []byte) bool { + return bytes.Contains(b, []byte("<<:")) +}