mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-10 03:47:03 +02:00
fix: Compile template at startup
Fail as fast as possible.
This commit is contained in:
parent
3e05553418
commit
21aa07766c
@ -9,7 +9,7 @@ import (
|
|||||||
"github.com/goreleaser/goreleaser/internal/artifact"
|
"github.com/goreleaser/goreleaser/internal/artifact"
|
||||||
)
|
)
|
||||||
|
|
||||||
const bodyTemplate = `{{ .ReleaseNotes }}
|
const bodyTemplateText = `{{ .ReleaseNotes }}
|
||||||
|
|
||||||
{{- if .DockerImages }}
|
{{- if .DockerImages }}
|
||||||
|
|
||||||
@ -23,6 +23,12 @@ const bodyTemplate = `{{ .ReleaseNotes }}
|
|||||||
Automated with [GoReleaser](https://github.com/goreleaser)
|
Automated with [GoReleaser](https://github.com/goreleaser)
|
||||||
Built with {{ .GoVersion }}`
|
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) {
|
func describeBody(ctx *context.Context) (bytes.Buffer, error) {
|
||||||
/* #nosec */
|
/* #nosec */
|
||||||
bts, err := exec.CommandContext(ctx, "go", "version").CombinedOutput()
|
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) {
|
func describeBodyVersion(ctx *context.Context, version string) (bytes.Buffer, error) {
|
||||||
var out bytes.Buffer
|
var out bytes.Buffer
|
||||||
var template = template.Must(template.New("release").Parse(bodyTemplate))
|
|
||||||
var dockers []string
|
var dockers []string
|
||||||
for _, a := range ctx.Artifacts.Filter(artifact.ByType(artifact.DockerImage)).List() {
|
for _, a := range ctx.Artifacts.Filter(artifact.ByType(artifact.DockerImage)).List() {
|
||||||
dockers = append(dockers, a.Name)
|
dockers = append(dockers, a.Name)
|
||||||
}
|
}
|
||||||
err := template.Execute(&out, struct {
|
err := bodyTemplate.Execute(&out, struct {
|
||||||
ReleaseNotes, GoVersion string
|
ReleaseNotes, GoVersion string
|
||||||
DockerImages []string
|
DockerImages []string
|
||||||
}{
|
}{
|
||||||
|
Loading…
Reference in New Issue
Block a user