mirror of
https://github.com/syncthing/syncthing.git
synced 2025-12-23 22:18:14 -05:00
Merge branch 'main' into v2
* main: build: use specific token for pushing release tags fix(gui): update `uncamel()` to handle strings like 'IDs' (fixes #10128) (#10131) refactor: use slices package for sort (#10132) build: process for automatic release tags (#10133) chore(gui, man, authors): update docs, translations, and contributors
This commit is contained in:
109
script/relnotes.go
Normal file
109
script/relnotes.go
Normal file
@@ -0,0 +1,109 @@
|
||||
// Copyright (C) 2025 The Syncthing Authors.
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
//go:build ignore
|
||||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"cmp"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
githubToken = os.Getenv("GITHUB_TOKEN")
|
||||
githubRepo = cmp.Or(os.Getenv("GITHUB_REPOSITORY"), "syncthing/syncthing")
|
||||
)
|
||||
|
||||
func main() {
|
||||
ver := flag.String("new-ver", "", "New version tag")
|
||||
prevVer := flag.String("prev-ver", "", "Previous version tag")
|
||||
branch := flag.String("branch", "HEAD", "Branch to release from")
|
||||
flag.Parse()
|
||||
|
||||
log.SetOutput(os.Stderr)
|
||||
|
||||
if *ver == "" {
|
||||
log.Fatalln("Must set --new-ver")
|
||||
}
|
||||
if githubToken == "" {
|
||||
log.Fatalln("Must set $GITHUB_TOKEN")
|
||||
}
|
||||
|
||||
addl, err := additionalNotes(*ver)
|
||||
if err != nil {
|
||||
log.Fatalln("Gathering additional notes:", err)
|
||||
}
|
||||
notes, err := generatedNotes(*ver, *branch, *prevVer)
|
||||
if err != nil {
|
||||
log.Fatalln("Gathering github notes:", err)
|
||||
}
|
||||
|
||||
if addl != "" {
|
||||
fmt.Println(addl)
|
||||
}
|
||||
fmt.Println(notes)
|
||||
}
|
||||
|
||||
// Load potential additional release notes from within the repo
|
||||
func additionalNotes(newVer string) (string, error) {
|
||||
ver, _, _ := strings.Cut(newVer, "-")
|
||||
bs, err := os.ReadFile(fmt.Sprintf("relnotes/%s.md", ver))
|
||||
if os.IsNotExist(err) {
|
||||
return "", nil
|
||||
}
|
||||
return string(bs), err
|
||||
}
|
||||
|
||||
// Load generated release notes (list of pull requests and contributors)
|
||||
// from GitHub.
|
||||
func generatedNotes(newVer, targetCommit, prevVer string) (string, error) {
|
||||
fields := map[string]string{
|
||||
"tag_name": newVer,
|
||||
"target_commitish": targetCommit,
|
||||
"previous_tag_name": prevVer,
|
||||
}
|
||||
bs, err := json.Marshal(fields)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
req, err := http.NewRequest(http.MethodPost, "https://api.github.com/repos/"+githubRepo+"/releases/generate-notes", bytes.NewReader(bs)) //nolint:noctx
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
req.Header.Set("Accept", "application/vnd.github+json")
|
||||
req.Header.Set("Authorization", "Bearer "+githubToken)
|
||||
req.Header.Set("X-Github-Api-Version", "2022-11-28")
|
||||
res, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if res.StatusCode != http.StatusOK {
|
||||
bs, _ := io.ReadAll(res.Body)
|
||||
log.Print(string(bs))
|
||||
return "", errors.New(res.Status) //nolint:err113
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
var resJSON struct {
|
||||
Body string
|
||||
}
|
||||
if err := json.NewDecoder(res.Body).Decode(&resJSON); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return resJSON.Body, nil
|
||||
}
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"regexp"
|
||||
"sort"
|
||||
"slices"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -93,7 +93,7 @@ func main() {
|
||||
}
|
||||
|
||||
func saveValidLangs(langs []string) {
|
||||
sort.Strings(langs)
|
||||
slices.Sort(langs)
|
||||
fd, err := os.Create("valid-langs.js")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"regexp"
|
||||
"sort"
|
||||
"slices"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -116,7 +116,7 @@ func reformatLanguageCode(origCode string) string {
|
||||
}
|
||||
|
||||
func saveValidLangs(langs []string) {
|
||||
sort.Strings(langs)
|
||||
slices.Sort(langs)
|
||||
fd, err := os.Create("valid-langs.js")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
||||
Reference in New Issue
Block a user