diff --git a/client/jobfile/reader.go b/client/jobfile/reader.go index 4f9bf6c..44f2997 100644 --- a/client/jobfile/reader.go +++ b/client/jobfile/reader.go @@ -1,8 +1,6 @@ package jobfile import ( - "encoding/base64" - "encoding/json" "errors" "fmt" "os" @@ -14,6 +12,9 @@ import ( "time" "github.com/gammadia/alfred/proto" + // Fork of github.com/Masterminds/sprig/v3 removing functions having 3rd party dependencies. List available here : + // https://github.com/go-task/slim-sprig/commit/4aa88173255771335225fa85e97341262276d42b?w=1#diff-5faaf3bff8320883fedc2b5e1828c8cea82467bd7d8357e1c824dafe50835bfb + "github.com/go-task/slim-sprig/v3" "github.com/samber/lo" "google.golang.org/protobuf/types/known/durationpb" "gopkg.in/yaml.v3" @@ -128,10 +129,9 @@ type TemplateData struct { func evaluateTemplate(source string, dir string, options ReadOptions) (string, error) { var userError error - tmpl, err := template.New("jobfile").Funcs(template.FuncMap{ - "base64": func(s string) string { - return base64.StdEncoding.EncodeToString([]byte(s)) - }, + + tmpl, err := template.New("jobfile").Funcs(sprig.FuncMap()).Funcs(template.FuncMap{ + // This one is better than sprig's fail() because it produces less noise in the error message. "error": func(err string) any { userError = errors.New(err) panic(nil) @@ -148,16 +148,6 @@ func evaluateTemplate(source string, dir string, options ReadOptions) (string, e return strings.TrimRight(string(output), "\n\r") } }, - "join": func(sep string, s []string) string { - return strings.Join(s, sep) - }, - "json": func(v any) (string, error) { - buf, err := json.Marshal(v) - return string(buf), err - }, - "lines": func(s string) []string { - return strings.Split(s, "\n") - }, "shell": func(script string) string { cmd := exec.Command("/bin/bash", "-euo", "pipefail", "-c", script) cmd.Dir = dir @@ -170,12 +160,6 @@ func evaluateTemplate(source string, dir string, options ReadOptions) (string, e return strings.TrimRight(string(output), "\n\r") } }, - "split": func(sep string, s string) []string { - return strings.Split(s, sep) - }, - "trim": func(s string) string { - return strings.TrimSpace(s) - }, }).Parse(source) if err != nil { return "", fmt.Errorf("failed to parse template: %w", err) diff --git a/go.mod b/go.mod index 4527f82..0bdc2e0 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/briandowns/spinner v1.23.0 github.com/docker/docker v24.0.7+incompatible github.com/fatih/color v1.15.0 + github.com/go-task/slim-sprig/v3 v3.0.0 github.com/gophercloud/gophercloud v1.7.0 github.com/rivo/tview v0.0.0-20231102183219-1b91b8131c43 github.com/rivo/uniseg v0.4.4 diff --git a/go.sum b/go.sum index c7ab613..4fbe105 100644 --- a/go.sum +++ b/go.sum @@ -90,6 +90,8 @@ github.com/gdamore/tcell/v2 v2.6.0/go.mod h1:be9omFATkdr0D9qewWW3d+MEvl5dha+Etb5 github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +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/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= diff --git a/hack/job.yaml b/hack/job.yaml index 625a7c3..5d36738 100644 --- a/hack/job.yaml +++ b/hack/job.yaml @@ -21,6 +21,6 @@ steps: - dockerfile: "job.dockerfile" context: "." tasks: - {{range (lines (shell "sloth instance --app tipee list -o json | jq -r '.[] | select(.features.tests) | .id' | tail -n 1"))}} + {{range (splitList "\n" (shell "sloth instance --app tipee list -o json | jq -r '.[] | select(.features.tests) | .id' | tail -n 5"))}} - {{.}} {{end}}