• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

snowplow / sql-runner / 15063404311

16 May 2025 07:46AM UTC coverage: 27.73% (+1.0%) from 26.721%
15063404311

push

github

jbeemster
Prepared for release

353 of 1273 relevant lines covered (27.73%)

2.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.78
/sql_runner/yaml_utils.go
1
// Copyright (c) 2015-2025 Snowplow Analytics Ltd. All rights reserved.
2
//
3
// This program is licensed to you under the Apache License Version 2.0,
4
// and you may not use this file except in compliance with the Apache License Version 2.0.
5
// You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
6
//
7
// Unless required by applicable law or agreed to in writing,
8
// software distributed under the Apache License Version 2.0 is distributed on an
9
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
// See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
11
package main
12

13
import (
14
        "bytes"
15
        "fmt"
16
        "regexp"
17
        "strings"
18
        "text/template"
19

20
        "github.com/goccy/go-yaml"
21
)
22

23
var (
24
        // Remove the prepended :s
25
        rubyYamlRegex = regexp.MustCompile("^(\\s*-?\\s*):?(.*)$")
26
)
27

28
// Parses a playbook.yml to return the targets
29
// to execute against and the steps to execute
30
func parsePlaybookYaml(playbookBytes []byte, variables map[string]string) (*Playbook, error) {
8✔
31
        // Define and initialize the Playbook struct
8✔
32
        var playbook Playbook = NewPlaybook()
8✔
33

8✔
34
        // Clean up the YAML
8✔
35
        cleaned := cleanYaml(playbookBytes)
8✔
36

8✔
37
        // Run the yaml through the template engine
8✔
38
        str, err := fillPlaybookTemplate(string(cleaned[:]), variables)
8✔
39
        if err != nil {
8✔
40
                return nil, fmt.Errorf("error filling playbook template")
×
41
        }
×
42

43
        // Unmarshal the yaml into the playbook
44
        if err = yaml.Unmarshal([]byte(str), &playbook); err != nil {
8✔
45
                return nil, fmt.Errorf("error unmarshalling playbook yaml")
×
46
        }
×
47

48
        return &playbook, nil
8✔
49
}
50

51
// Because our StorageLoader's YAML file has elements with
52
// : prepended (bad decision to make things easier from
53
// our Ruby code).
54
func cleanYaml(rawYaml []byte) []byte {
11✔
55
        var lines []string
11✔
56
        var buffer bytes.Buffer
11✔
57

11✔
58
        lines = strings.Split(string(rawYaml), "\n")
11✔
59

11✔
60
        for _, line := range lines {
131✔
61
                buffer.WriteString(rubyYamlRegex.ReplaceAllString(line, "${1}${2}\n"))
120✔
62
        }
120✔
63
        return buffer.Bytes()
11✔
64
}
65

66
func fillPlaybookTemplate(playbookStr string, variables map[string]string) (string, error) {
8✔
67
        t, err := template.New("playbook").Funcs(TemplFuncs).Parse(playbookStr)
8✔
68
        if err != nil {
8✔
69
                return "", err
×
70
        }
×
71

72
        var filled bytes.Buffer
8✔
73
        if err := t.Execute(&filled, variables); err != nil {
8✔
74
                return "", err
×
75
        }
×
76

77
        return filled.String(), err
8✔
78
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc