2017-04-19 16:59:26 -03:00
|
|
|
package release
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2021-06-08 11:11:27 -03:00
|
|
|
"strings"
|
2017-07-04 09:28:26 -03:00
|
|
|
"text/template"
|
2017-04-19 16:59:26 -03:00
|
|
|
|
2017-12-17 23:11:17 -02:00
|
|
|
"github.com/goreleaser/goreleaser/internal/artifact"
|
2021-07-03 09:42:54 -07:00
|
|
|
"github.com/goreleaser/goreleaser/internal/tmpl"
|
2018-08-14 23:50:20 -03:00
|
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
2017-04-19 16:59:26 -03:00
|
|
|
)
|
|
|
|
|
2021-05-30 21:53:40 -03:00
|
|
|
const bodyTemplateText = `{{ with .Header }}{{ . }}{{ "\n" }}{{ end }}
|
|
|
|
{{- .ReleaseNotes }}
|
2017-04-19 16:59:26 -03:00
|
|
|
|
2018-04-01 13:27:57 -03:00
|
|
|
{{- with .DockerImages }}
|
2017-09-16 15:31:20 -03:00
|
|
|
|
2017-12-05 18:19:18 -02:00
|
|
|
## Docker images
|
2018-04-01 13:27:57 -03:00
|
|
|
{{ range $element := . }}
|
2017-12-05 18:19:18 -02:00
|
|
|
- ` + "`docker pull {{ . -}}`" + `
|
|
|
|
{{- end -}}
|
2018-04-01 15:24:59 -03:00
|
|
|
{{- end }}
|
2021-05-30 21:53:40 -03:00
|
|
|
{{- with .Footer }}{{ "\n" }}{{ . }}{{ end }}
|
2018-04-01 15:24:59 -03:00
|
|
|
`
|
2017-04-19 16:59:26 -03:00
|
|
|
|
2021-06-08 11:11:27 -03:00
|
|
|
func isLatest(img string) bool {
|
|
|
|
return strings.HasSuffix(img, ":latest") || !strings.Contains(img, ":")
|
|
|
|
}
|
|
|
|
|
2017-04-19 17:12:12 -03:00
|
|
|
func describeBody(ctx *context.Context) (bytes.Buffer, error) {
|
2017-09-16 15:31:20 -03:00
|
|
|
var out bytes.Buffer
|
2018-07-04 00:42:24 -07:00
|
|
|
// nolint:prealloc
|
2017-12-17 23:11:17 -02:00
|
|
|
var dockers []string
|
2020-11-29 14:33:31 -03:00
|
|
|
for _, a := range ctx.Artifacts.Filter(artifact.ByType(artifact.DockerManifest)).List() {
|
2021-06-08 11:11:27 -03:00
|
|
|
if isLatest(a.Name) {
|
|
|
|
continue
|
|
|
|
}
|
2020-11-29 14:33:31 -03:00
|
|
|
dockers = append(dockers, a.Name)
|
|
|
|
}
|
2020-11-30 21:53:36 -03:00
|
|
|
if len(dockers) == 0 {
|
|
|
|
for _, a := range ctx.Artifacts.Filter(artifact.ByType(artifact.DockerImage)).List() {
|
2021-06-08 11:11:27 -03:00
|
|
|
if isLatest(a.Name) {
|
|
|
|
continue
|
|
|
|
}
|
2020-11-30 21:53:36 -03:00
|
|
|
dockers = append(dockers, a.Name)
|
|
|
|
}
|
2017-12-17 23:11:17 -02:00
|
|
|
}
|
2021-07-03 09:42:54 -07:00
|
|
|
|
|
|
|
header, err := tmpl.New(ctx).Apply(ctx.Config.Release.Header)
|
|
|
|
if err != nil {
|
|
|
|
return out, err
|
|
|
|
}
|
|
|
|
footer, err := tmpl.New(ctx).Apply(ctx.Config.Release.Footer)
|
|
|
|
if err != nil {
|
|
|
|
return out, err
|
|
|
|
}
|
|
|
|
|
2021-04-25 14:20:49 -03:00
|
|
|
bodyTemplate := template.Must(template.New("release").Parse(bodyTemplateText))
|
2021-07-03 09:42:54 -07:00
|
|
|
err = bodyTemplate.Execute(&out, struct {
|
2021-05-30 21:53:40 -03:00
|
|
|
Header string
|
|
|
|
Footer string
|
2018-04-01 13:27:57 -03:00
|
|
|
ReleaseNotes string
|
|
|
|
DockerImages []string
|
2017-04-19 16:59:26 -03:00
|
|
|
}{
|
2021-07-03 09:42:54 -07:00
|
|
|
Header: header,
|
|
|
|
Footer: footer,
|
2017-04-19 17:05:10 -03:00
|
|
|
ReleaseNotes: ctx.ReleaseNotes,
|
2017-12-17 23:11:17 -02:00
|
|
|
DockerImages: dockers,
|
2017-04-19 16:59:26 -03:00
|
|
|
})
|
|
|
|
return out, err
|
|
|
|
}
|