Skip to content

Commit 82eaaf0

Browse files
committed
Update version bumper script for new format
1 parent 48dc1a4 commit 82eaaf0

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

scripts/vbumper/main.go

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"bytes"
2626
"errors"
2727
"flag"
28+
"fmt"
2829
"html/template"
2930
"io/ioutil"
3031
"log"
@@ -90,6 +91,11 @@ func updateChangelog() (oldVersion string, _ error) {
9091
return "", err
9192
}
9293

94+
newLog, err = insertChangesLink(newLog, oldVersion, *_version)
95+
if err != nil {
96+
return "", err
97+
}
98+
9399
if *_skipChangelog {
94100
return oldVersion, nil
95101
}
@@ -98,24 +104,23 @@ func updateChangelog() (oldVersion string, _ error) {
98104
}
99105

100106
func insertNewChangelog(contents string) (string, string, error) {
101-
prevVersionHeader := strings.Index(contents, "\n# ")
107+
prevVersionHeader := strings.Index(contents, "\n## [")
102108
if prevVersionHeader < 0 {
103109
return "", "", errors.New("failed to find version header in changelog")
104110
}
105111

106112
// Skip the newline
107113
prevVersionHeader++
108114
versionLine := contents[prevVersionHeader:]
109-
prevVersionEnd := strings.Index(versionLine, "(")
110-
prevVersionTag := strings.TrimSpace(versionLine[1 : prevVersionEnd-1])
115+
prevVersionEnd := strings.Index(versionLine, "]")
116+
prevVersion := strings.TrimSpace(versionLine[4:prevVersionEnd])
111117

112-
newChanges, err := getNewChangelog(prevVersionTag)
118+
// The version tag has a "v" prefix.
119+
newChanges, err := getNewChangelog("v" + prevVersion)
113120
if err != nil {
114121
return "", "", err
115122
}
116123

117-
// Strip the 'v' prefix.
118-
prevVersion := prevVersionTag[1:]
119124
newContents := contents[:prevVersionHeader] + newChanges + contents[prevVersionHeader:]
120125
return newContents, prevVersion, nil
121126
}
@@ -144,7 +149,8 @@ func getNewChangelog(prevVersion string) (string, error) {
144149
}
145150

146151
var _changeTmpl = template.Must(template.New("changelog").Parse(
147-
`# v{{ .Version }} ({{ .Date }})
152+
`## [{{ .Version }}] - {{ .Date }}
153+
### Changed
148154
{{ range .Changes }}
149155
* {{ . -}}
150156
{{ end }}
@@ -170,3 +176,27 @@ func getChanges(prevVersion string) ([]string, error) {
170176
}
171177
return newLines, nil
172178
}
179+
180+
func insertChangesLink(contents, prevVersion, version string) (string, error) {
181+
linksMarker := strings.Index(contents, "(Version Links)")
182+
if linksMarker == -1 {
183+
return "", errors.New("failed to find marker for version links section")
184+
}
185+
186+
newLine := strings.IndexByte(contents[linksMarker:], '\n')
187+
if newLine < 0 {
188+
return "", errors.New("failed to find newline after version links section")
189+
}
190+
191+
insertAt := linksMarker + newLine + 1
192+
193+
linkBlock := fmt.Sprintf("[%v]: %v\n", version, getChangesLink(prevVersion, version))
194+
newContents := contents[:insertAt] + linkBlock + contents[insertAt:]
195+
return newContents, nil
196+
}
197+
198+
func getChangesLink(prevVersion, curVersion string) string {
199+
// Example link:
200+
// https://github.com/uber/tchannel-go/compare/v1.8.0...v1.8.1
201+
return fmt.Sprintf("https://github.com/uber/tchannel-go/compare/v%v...v%v", prevVersion, curVersion)
202+
}

0 commit comments

Comments
 (0)