瀏覽代碼

build: handle multiple general release notes

Jakob Borg 4 月之前
父節點
當前提交
905e5ec07f
共有 2 個文件被更改,包括 24 次插入12 次删除
  1. 3 0
      relnotes/README.md
  2. 21 12
      script/relnotes.go

+ 3 - 0
relnotes/README.md

@@ -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
script/relnotes.go

@@ -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(addl)
-	}
-	fmt.Println(notes)
+	fmt.Println(strings.Join(notes, "\n\n"))
 }
 }
 
 
 // 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))
-	if os.IsNotExist(err) {
-		return "", nil
+	for {
+		file := fmt.Sprintf("relnotes/%s.md", ver)
+		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
 }
 }