feat(release): generate the GitHub release body from the changelog (#2987)

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Valentin Maerten
2026-08-21 15:31:52 +02:00
committed by GitHub
parent dd4463ec60
commit 30c998136d
6 changed files with 141 additions and 3 deletions

48
cmd/release/notes.go Normal file
View File

@@ -0,0 +1,48 @@
package main
import (
"fmt"
"io"
"os"
"strings"
"github.com/Masterminds/semver/v3"
)
func notes(w io.Writer) error {
version, err := getVersion(versionFile)
if err != nil {
return err
}
b, err := os.ReadFile(changelogSource)
if err != nil {
return err
}
section := changelogSection(string(b), version)
if section == "" {
return nil
}
_, err = fmt.Fprintln(w, section)
return err
}
func changelogSection(changelog string, version *semver.Version) string {
heading := fmt.Sprintf("## v%s ", version)
var section []string
var found bool
for line := range strings.SplitSeq(changelog, "\n") {
if strings.HasPrefix(line, "## ") {
if found {
break
}
found = strings.HasPrefix(line, heading)
continue
}
if found {
section = append(section, line)
}
}
return strings.TrimSpace(strings.Join(section, "\n"))
}