1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/pipeline/release/body.go
2017-12-17 23:11:17 -02:00

52 lines
1.2 KiB
Go

package release
import (
"bytes"
"os/exec"
"text/template"
"github.com/goreleaser/goreleaser/context"
"github.com/goreleaser/goreleaser/internal/artifact"
)
const bodyTemplate = `{{ .ReleaseNotes }}
{{- if .DockerImages }}
## Docker images
{{ range $element := .DockerImages }}
- ` + "`docker pull {{ . -}}`" + `
{{- end -}}
{{- end }}
---
Automated with [GoReleaser](https://github.com/goreleaser)
Built with {{ .GoVersion }}`
func describeBody(ctx *context.Context) (bytes.Buffer, error) {
/* #nosec */
bts, err := exec.Command("go", "version").CombinedOutput()
if err != nil {
return bytes.Buffer{}, err
}
return describeBodyVersion(ctx, string(bts))
}
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 {
ReleaseNotes, GoVersion string
DockerImages []string
}{
ReleaseNotes: ctx.ReleaseNotes,
GoVersion: version,
DockerImages: dockers,
})
return out, err
}