Skip to content

Commit d89ba5e

Browse files
Merge pull request #2591 from dmcgowan/update-release-script
Update release script
2 parents 29eab28 + 69e7c77 commit d89ba5e

4 files changed

Lines changed: 98 additions & 5 deletions

File tree

.mailmap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Abhinandan Prativadi <[email protected]> abhi <[email protected]>
33
Akihiro Suda <[email protected]> Akihiro Suda <[email protected]>
44
Andrei Vagin <[email protected]> Andrei Vagin <[email protected]>
55
Frank Yang <[email protected]> frank yang <[email protected]>
6+
7+
John Howard <[email protected]> John Howard <[email protected]>
68
Justin Terry <[email protected]> Justin Terry (VM) <[email protected]>
79
Justin Terry <[email protected]> Justin <[email protected]>
810
Kenfe-Mickaël Laventure <[email protected]> Kenfe-Mickael Laventure <[email protected]>

cmd/containerd-release/main.go

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ import (
2424
"path/filepath"
2525
"regexp"
2626
"sort"
27+
"strings"
2728
"text/tabwriter"
2829
"text/template"
30+
"unicode"
2931

3032
"github.com/pkg/errors"
3133
"github.com/sirupsen/logrus"
@@ -84,6 +86,7 @@ type release struct {
8486
Changes []projectChange
8587
Contributors []string
8688
Dependencies []dependency
89+
Tag string
8790
Version string
8891
Downloads []download
8992
}
@@ -105,16 +108,29 @@ This tool should be ran from the root of the project repository for a new releas
105108
Usage: "show debug output",
106109
},
107110
cli.StringFlag{
108-
Name: "template,t",
111+
Name: "tag,t",
112+
Usage: "tag name for the release, defaults to release file name",
113+
},
114+
cli.StringFlag{
115+
Name: "template",
109116
Usage: "template filepath to use in place of the default",
110117
Value: defaultTemplateFile,
111118
},
119+
cli.BoolFlag{
120+
Name: "linkify,l",
121+
Usage: "add links to changelog",
122+
},
112123
}
113124
app.Action = func(context *cli.Context) error {
114125
var (
115126
releasePath = context.Args().First()
116-
tag = parseTag(releasePath)
127+
tag = context.String("tag")
128+
linkify = context.Bool("linkify")
117129
)
130+
if tag == "" {
131+
tag = parseTag(releasePath)
132+
}
133+
version := strings.TrimLeft(tag, "v")
118134
if context.Bool("debug") {
119135
logrus.SetLevel(logrus.DebugLevel)
120136
}
@@ -139,6 +155,11 @@ This tool should be ran from the root of the project repository for a new releas
139155
if err != nil {
140156
return err
141157
}
158+
if linkify {
159+
if err := linkifyChanges(changes, githubCommitLink(r.GithubRepo), githubPRLink(r.GithubRepo)); err != nil {
160+
return err
161+
}
162+
}
142163
if err := addContributors(r.Previous, r.Commit, contributors); err != nil {
143164
return err
144165
}
@@ -210,6 +231,16 @@ This tool should be ran from the root of the project repository for a new releas
210231
if err := addContributors(dep.Previous, dep.Commit, contributors); err != nil {
211232
return errors.Wrapf(err, "failed to get authors for %s", name)
212233
}
234+
if linkify {
235+
if !strings.HasPrefix(dep.Name, "github.com/") {
236+
logrus.Debugf("linkify only supported for Github, skipping %s", dep.Name)
237+
} else {
238+
ghname := dep.Name[11:]
239+
if err := linkifyChanges(changes, githubCommitLink(ghname), githubPRLink(ghname)); err != nil {
240+
return err
241+
}
242+
}
243+
}
213244

214245
projectChanges = append(projectChanges, projectChange{
215246
Name: name,
@@ -226,7 +257,11 @@ This tool should be ran from the root of the project repository for a new releas
226257
r.Contributors = orderContributors(contributors)
227258
r.Dependencies = updatedDeps
228259
r.Changes = projectChanges
229-
r.Version = tag
260+
r.Tag = tag
261+
r.Version = version
262+
263+
// Remove trailing new lines
264+
r.Preface = strings.TrimRightFunc(r.Preface, unicode.IsSpace)
230265

231266
tmpl, err := getTemplate(context)
232267
if err != nil {

cmd/containerd-release/template.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ package main
1818

1919
const (
2020
defaultTemplateFile = "TEMPLATE"
21-
releaseNotes = `Welcome to the {{.Version}} release of {{.ProjectName}}!
22-
{{if .PreRelease -}}
21+
releaseNotes = `{{.ProjectName}} {{.Version}}
22+
23+
Welcome to the {{.Tag}} release of {{.ProjectName}}!
24+
{{- if .PreRelease }}
2325
*This is a pre-release of {{.ProjectName}}*
2426
{{- end}}
2527

cmd/containerd-release/util.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"os"
2626
"os/exec"
2727
"path/filepath"
28+
"regexp"
2829
"sort"
2930
"strings"
3031

@@ -113,6 +114,26 @@ func getChangelog(previous, commit string) ([]byte, error) {
113114
return git("log", "--oneline", gitChangeDiff(previous, commit))
114115
}
115116

117+
func linkifyChanges(c []change, commit, msg func(change) (string, error)) error {
118+
for i := range c {
119+
commitLink, err := commit(c[i])
120+
if err != nil {
121+
return err
122+
}
123+
124+
description, err := msg(c[i])
125+
if err != nil {
126+
return err
127+
}
128+
129+
c[i].Commit = fmt.Sprintf("[`%s`](%s)", c[i].Commit, commitLink)
130+
c[i].Description = description
131+
132+
}
133+
134+
return nil
135+
}
136+
116137
func parseChangelog(changelog []byte) ([]change, error) {
117138
var (
118139
changes []change
@@ -282,3 +303,36 @@ func getTemplate(context *cli.Context) (string, error) {
282303
}
283304
return string(data), nil
284305
}
306+
307+
func githubCommitLink(repo string) func(change) (string, error) {
308+
return func(c change) (string, error) {
309+
full, err := git("rev-parse", c.Commit)
310+
if err != nil {
311+
return "", err
312+
}
313+
commit := strings.TrimSpace(string(full))
314+
315+
return fmt.Sprintf("https://github.com/%s/commit/%s", repo, commit), nil
316+
}
317+
}
318+
319+
func githubPRLink(repo string) func(change) (string, error) {
320+
r := regexp.MustCompile("^Merge pull request #[0-9]+")
321+
return func(c change) (string, error) {
322+
var err error
323+
message := r.ReplaceAllStringFunc(c.Description, func(m string) string {
324+
idx := strings.Index(m, "#")
325+
pr := m[idx+1:]
326+
327+
// TODO: Validate links using github API
328+
// TODO: Validate PR merged as commit hash
329+
link := fmt.Sprintf("https://github.com/%s/pull/%s", repo, pr)
330+
331+
return fmt.Sprintf("%s [#%s](%s)", m[:idx], pr, link)
332+
})
333+
if err != nil {
334+
return "", err
335+
}
336+
return message, nil
337+
}
338+
}

0 commit comments

Comments
 (0)