From 21aa07766c8f4afe7358199c1d818340e1b41931 Mon Sep 17 00:00:00 2001 From: Harmen Date: Thu, 1 Feb 2018 14:37:30 +0100 Subject: [PATCH] fix: Compile template at startup Fail as fast as possible. --- pipeline/release/body.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pipeline/release/body.go b/pipeline/release/body.go index 75c6ab2d8..06d047220 100644 --- a/pipeline/release/body.go +++ b/pipeline/release/body.go @@ -9,7 +9,7 @@ import ( "github.com/goreleaser/goreleaser/internal/artifact" ) -const bodyTemplate = `{{ .ReleaseNotes }} +const bodyTemplateText = `{{ .ReleaseNotes }} {{- if .DockerImages }} @@ -23,6 +23,12 @@ const bodyTemplate = `{{ .ReleaseNotes }} Automated with [GoReleaser](https://github.com/goreleaser) Built with {{ .GoVersion }}` +var bodyTemplate *template.Template + +func init() { + bodyTemplate = template.Must(template.New("release").Parse(bodyTemplateText)) +} + func describeBody(ctx *context.Context) (bytes.Buffer, error) { /* #nosec */ bts, err := exec.CommandContext(ctx, "go", "version").CombinedOutput() @@ -34,12 +40,11 @@ func describeBody(ctx *context.Context) (bytes.Buffer, error) { func describeBodyVersion(ctx *context.Context, version string) (bytes.Buffer, error) { var out bytes.Buffer - var template = template.Must(template.New("release").Parse(bodyTemplate)) var dockers []string for _, a := range ctx.Artifacts.Filter(artifact.ByType(artifact.DockerImage)).List() { dockers = append(dockers, a.Name) } - err := template.Execute(&out, struct { + err := bodyTemplate.Execute(&out, struct { ReleaseNotes, GoVersion string DockerImages []string }{