Skip to content

Commit

Permalink
Merge pull request #231 from budimanjojo/220
Browse files Browse the repository at this point in the history
fix(substitute): fix issue parsing env file with yaml document delimiter
  • Loading branch information
budimanjojo authored Nov 24, 2023
2 parents 2ecca8f + 3bf40ee commit afa87b0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/substitute/envsubst.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ func LoadEnvFromFiles(files []string) error {
return fmt.Errorf("trying to decrypt %s with sops: %s", file, err)
}

// See: https://github.com/budimanjojo/talhelper/issues/220
env = stripYAMLDocDelimiter(env)
if err := LoadEnv(env); err != nil {
return fmt.Errorf("trying to load env from %s: %s", file, err)
}
Expand Down Expand Up @@ -86,3 +88,8 @@ func stripYamlComment(file []byte) []byte {

return final.Bytes()
}

// stripYAMLDocDelimiter replace YAML document delimiter with empty line
func stripYAMLDocDelimiter(src []byte) []byte {
return bytes.ReplaceAll(src, []byte("---\n"), []byte("\n"))
}
1 change: 1 addition & 0 deletions pkg/substitute/testdata/file1.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
---
env1: hello
env2: invalid value
1 change: 1 addition & 0 deletions pkg/substitute/testdata/file2.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
---
env2: world
env3: this is value

0 comments on commit afa87b0

Please sign in to comment.