build: handle multiple general release notes

This commit is contained in:
Jakob Borg
2025-05-26 16:27:23 +02:00
parent 4075b886d0
commit 905e5ec07f
2 changed files with 24 additions and 12 deletions
+3
View File
@@ -16,3 +16,6 @@ example:
The release notes will also be included in candidate releases (e.g. The release notes will also be included in candidate releases (e.g.
v1.2.3-rc.1). v1.2.3-rc.1).
Additional notes will also be loaded from `v1.2.md` and `v1.md`, if they
exist.
+21 -12
View File
@@ -43,29 +43,38 @@ func main() {
log.Fatalln("Must set $GITHUB_TOKEN") log.Fatalln("Must set $GITHUB_TOKEN")
} }
addl, err := additionalNotes(*ver) notes, err := additionalNotes(*ver)
if err != nil { if err != nil {
log.Fatalln("Gathering additional notes:", err) log.Fatalln("Gathering additional notes:", err)
} }
notes, err := generatedNotes(*ver, *branch, *prevVer) gh, err := generatedNotes(*ver, *branch, *prevVer)
if err != nil { if err != nil {
log.Fatalln("Gathering github notes:", err) log.Fatalln("Gathering github notes:", err)
} }
notes = append(notes, gh)
if addl != "" { fmt.Println(strings.Join(notes, "\n\n"))
fmt.Println(addl)
}
fmt.Println(notes)
} }
// Load potential additional release notes from within the repo // Load potential additional release notes from within the repo
func additionalNotes(newVer string) (string, error) { func additionalNotes(newVer string) ([]string, error) {
var notes []string
ver, _, _ := strings.Cut(newVer, "-") ver, _, _ := strings.Cut(newVer, "-")
bs, err := os.ReadFile(fmt.Sprintf("relnotes/%s.md", ver)) for {
if os.IsNotExist(err) { file := fmt.Sprintf("relnotes/%s.md", ver)
return "", nil if bs, err := os.ReadFile(file); err == nil {
notes = append(notes, strings.TrimSpace(string(bs)))
} else if !os.IsNotExist(err) {
return nil, err
}
if idx := strings.LastIndex(ver, "."); idx > 0 {
ver = ver[:idx]
} else {
break
}
} }
return string(bs), err return notes, nil
} }
// Load generated release notes (list of pull requests and contributors) // Load generated release notes (list of pull requests and contributors)
@@ -105,5 +114,5 @@ func generatedNotes(newVer, targetCommit, prevVer string) (string, error) {
if err := json.NewDecoder(res.Body).Decode(&resJSON); err != nil { if err := json.NewDecoder(res.Body).Decode(&resJSON); err != nil {
return "", err return "", err
} }
return resJSON.Body, nil return strings.TrimSpace(resJSON.Body), nil
} }