mirror of
https://github.com/jimeh/build-emacs-for-macos.git
synced 2026-02-19 07:16:39 +00:00
The description includes links to the Emacs source repo used, the git ref, commit, tarball download URL, and build log (GitHub Actions Run).
81 lines
1.7 KiB
Go
81 lines
1.7 KiB
Go
package release
|
|
|
|
import (
|
|
"bytes"
|
|
"os"
|
|
"strings"
|
|
"text/template"
|
|
)
|
|
|
|
var tplFuncs = template.FuncMap{
|
|
"indent": func(n int, s string) string {
|
|
pad := strings.Repeat(" ", n)
|
|
|
|
return pad + strings.ReplaceAll(s, "\n", "\n"+pad)
|
|
},
|
|
}
|
|
|
|
var bodyTpl = template.Must(template.New("body").Funcs(tplFuncs).Parse(`
|
|
{{- $t := "` + "`" + `" -}}
|
|
### Build Details
|
|
|
|
{{ with .SourceURL -}}
|
|
- Source: {{ . }}
|
|
{{- end }}
|
|
{{- if and .CommitSHA .CommitURL }}
|
|
- Commit: [{{ $t }}{{ .CommitSHA }}{{ $t }}]
|
|
{{- if .CommitURL }}({{ .CommitURL }}){{ end }}
|
|
{{- else if and .CommitSHA }}
|
|
- Commit: {{ $t }}{{ .CommitSHA }}{{ $t }}
|
|
{{- end }}
|
|
{{- with .TarballURL }}
|
|
- Tarball: {{ . }}
|
|
{{- end }}
|
|
{{- with .BuildLogURL }}
|
|
- Build Log: {{ . }} (available for 90 days)
|
|
{{- end }}`,
|
|
))
|
|
|
|
type bodyData struct {
|
|
SourceURL string
|
|
CommitSHA string
|
|
CommitURL string
|
|
BuildLogURL string
|
|
TarballURL string
|
|
}
|
|
|
|
func releaseBody(opts *PublishOptions) (string, error) {
|
|
src := opts.Source
|
|
|
|
if src.Repository == nil || src.Commit == nil {
|
|
return "", nil
|
|
}
|
|
|
|
data := &bodyData{
|
|
SourceURL: src.Repository.TreeURL(src.Ref),
|
|
CommitSHA: src.Commit.SHA,
|
|
CommitURL: src.Repository.CommitURL(src.Commit.SHA),
|
|
TarballURL: src.Repository.TarballURL(src.Commit.SHA),
|
|
}
|
|
|
|
// If available, use the exact value from the build plan.
|
|
if src.Tarball != nil {
|
|
data.TarballURL = src.Tarball.URL
|
|
}
|
|
|
|
// If running within GitHub Actions, provide link to build log.
|
|
if opts.Repository != nil {
|
|
if id := os.Getenv("GITHUB_RUN_ID"); id != "" {
|
|
data.BuildLogURL = opts.Repository.ActionRunURL(id)
|
|
}
|
|
}
|
|
|
|
var buf bytes.Buffer
|
|
err := bodyTpl.Execute(&buf, data)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return buf.String(), nil
|
|
}
|