2017-04-19 16:59:26 -03:00
|
|
|
package release
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2023-06-05 13:05:28 -03:00
|
|
|
"os"
|
2017-07-04 09:28:26 -03:00
|
|
|
"text/template"
|
2017-04-19 16:59:26 -03:00
|
|
|
|
2024-05-26 15:02:57 -03:00
|
|
|
"github.com/goreleaser/goreleaser/v2/internal/artifact"
|
|
|
|
"github.com/goreleaser/goreleaser/v2/internal/tmpl"
|
|
|
|
"github.com/goreleaser/goreleaser/v2/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 }}
|
|
|
|
{{- with .Footer }}{{ "\n" }}{{ . }}{{ end }}
|
2018-04-01 15:24:59 -03:00
|
|
|
`
|
2017-04-19 16:59:26 -03:00
|
|
|
|
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
|
2024-03-17 15:16:50 -03:00
|
|
|
fields := tmpl.Fields{}
|
|
|
|
|
|
|
|
checksums := ctx.Artifacts.Filter(artifact.ByType(artifact.Checksum))
|
|
|
|
|
|
|
|
checksumsList := checksums.List()
|
|
|
|
switch len(checksumsList) {
|
|
|
|
case 0:
|
|
|
|
// do nothing
|
|
|
|
case 1:
|
|
|
|
bts, err := os.ReadFile(checksumsList[0].Path)
|
2023-06-05 13:05:28 -03:00
|
|
|
if err != nil {
|
|
|
|
return out, err
|
|
|
|
}
|
2024-03-17 15:16:50 -03:00
|
|
|
fields["Checksums"] = string(bts)
|
|
|
|
default:
|
|
|
|
checkMap := map[string]string{}
|
|
|
|
for _, check := range checksumsList {
|
|
|
|
bts, err := os.ReadFile(check.Path)
|
|
|
|
if err != nil {
|
|
|
|
return out, err
|
|
|
|
}
|
|
|
|
checkMap[artifact.ExtraOr(*check, artifact.ExtraChecksumOf, "")] = string(bts)
|
|
|
|
}
|
|
|
|
fields["Checksums"] = checkMap
|
2023-06-05 13:05:28 -03:00
|
|
|
}
|
|
|
|
|
2024-03-17 15:16:50 -03:00
|
|
|
t := tmpl.New(ctx).WithExtraFields(fields)
|
2021-07-03 09:42:54 -07:00
|
|
|
|
2021-11-30 21:13:35 -03:00
|
|
|
header, err := t.Apply(ctx.Config.Release.Header)
|
2021-07-03 09:42:54 -07:00
|
|
|
if err != nil {
|
|
|
|
return out, err
|
|
|
|
}
|
2021-11-30 21:13:35 -03:00
|
|
|
footer, err := t.Apply(ctx.Config.Release.Footer)
|
2021-07-03 09:42:54 -07:00
|
|
|
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
|
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-04-19 16:59:26 -03:00
|
|
|
})
|
|
|
|
return out, err
|
|
|
|
}
|