Merge pull request #2591 from dmcgowan/update-release-script
Update release script
This commit is contained in:
commit
d89ba5ee08
2
.mailmap
2
.mailmap
@ -3,6 +3,8 @@ Abhinandan Prativadi <abhi@docker.com> abhi <abhi@docker.com>
|
|||||||
Akihiro Suda <suda.akihiro@lab.ntt.co.jp> Akihiro Suda <suda.kyoto@gmail.com>
|
Akihiro Suda <suda.akihiro@lab.ntt.co.jp> Akihiro Suda <suda.kyoto@gmail.com>
|
||||||
Andrei Vagin <avagin@virtuozzo.com> Andrei Vagin <avagin@openvz.org>
|
Andrei Vagin <avagin@virtuozzo.com> Andrei Vagin <avagin@openvz.org>
|
||||||
Frank Yang <yyb196@gmail.com> frank yang <yyb196@gmail.com>
|
Frank Yang <yyb196@gmail.com> frank yang <yyb196@gmail.com>
|
||||||
|
Jie Zhang <iamkadisi@163.com> kadisi <iamkadisi@163.com>
|
||||||
|
John Howard <john.howard@microsoft.com> John Howard <jhoward@microsoft.com>
|
||||||
Justin Terry <juterry@microsoft.com> Justin Terry (VM) <juterry@microsoft.com>
|
Justin Terry <juterry@microsoft.com> Justin Terry (VM) <juterry@microsoft.com>
|
||||||
Justin Terry <juterry@microsoft.com> Justin <jterry75@users.noreply.github.com>
|
Justin Terry <juterry@microsoft.com> Justin <jterry75@users.noreply.github.com>
|
||||||
Kenfe-Mickaël Laventure <mickael.laventure@gmail.com> Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
|
Kenfe-Mickaël Laventure <mickael.laventure@gmail.com> Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
|
||||||
|
@ -24,8 +24,10 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
"unicode"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -84,6 +86,7 @@ type release struct {
|
|||||||
Changes []projectChange
|
Changes []projectChange
|
||||||
Contributors []string
|
Contributors []string
|
||||||
Dependencies []dependency
|
Dependencies []dependency
|
||||||
|
Tag string
|
||||||
Version string
|
Version string
|
||||||
Downloads []download
|
Downloads []download
|
||||||
}
|
}
|
||||||
@ -105,16 +108,29 @@ This tool should be ran from the root of the project repository for a new releas
|
|||||||
Usage: "show debug output",
|
Usage: "show debug output",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "template,t",
|
Name: "tag,t",
|
||||||
|
Usage: "tag name for the release, defaults to release file name",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "template",
|
||||||
Usage: "template filepath to use in place of the default",
|
Usage: "template filepath to use in place of the default",
|
||||||
Value: defaultTemplateFile,
|
Value: defaultTemplateFile,
|
||||||
},
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "linkify,l",
|
||||||
|
Usage: "add links to changelog",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
app.Action = func(context *cli.Context) error {
|
app.Action = func(context *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
releasePath = context.Args().First()
|
releasePath = context.Args().First()
|
||||||
tag = parseTag(releasePath)
|
tag = context.String("tag")
|
||||||
|
linkify = context.Bool("linkify")
|
||||||
)
|
)
|
||||||
|
if tag == "" {
|
||||||
|
tag = parseTag(releasePath)
|
||||||
|
}
|
||||||
|
version := strings.TrimLeft(tag, "v")
|
||||||
if context.Bool("debug") {
|
if context.Bool("debug") {
|
||||||
logrus.SetLevel(logrus.DebugLevel)
|
logrus.SetLevel(logrus.DebugLevel)
|
||||||
}
|
}
|
||||||
@ -139,6 +155,11 @@ This tool should be ran from the root of the project repository for a new releas
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if linkify {
|
||||||
|
if err := linkifyChanges(changes, githubCommitLink(r.GithubRepo), githubPRLink(r.GithubRepo)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
if err := addContributors(r.Previous, r.Commit, contributors); err != nil {
|
if err := addContributors(r.Previous, r.Commit, contributors); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -210,6 +231,16 @@ This tool should be ran from the root of the project repository for a new releas
|
|||||||
if err := addContributors(dep.Previous, dep.Commit, contributors); err != nil {
|
if err := addContributors(dep.Previous, dep.Commit, contributors); err != nil {
|
||||||
return errors.Wrapf(err, "failed to get authors for %s", name)
|
return errors.Wrapf(err, "failed to get authors for %s", name)
|
||||||
}
|
}
|
||||||
|
if linkify {
|
||||||
|
if !strings.HasPrefix(dep.Name, "github.com/") {
|
||||||
|
logrus.Debugf("linkify only supported for Github, skipping %s", dep.Name)
|
||||||
|
} else {
|
||||||
|
ghname := dep.Name[11:]
|
||||||
|
if err := linkifyChanges(changes, githubCommitLink(ghname), githubPRLink(ghname)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
projectChanges = append(projectChanges, projectChange{
|
projectChanges = append(projectChanges, projectChange{
|
||||||
Name: name,
|
Name: name,
|
||||||
@ -226,7 +257,11 @@ This tool should be ran from the root of the project repository for a new releas
|
|||||||
r.Contributors = orderContributors(contributors)
|
r.Contributors = orderContributors(contributors)
|
||||||
r.Dependencies = updatedDeps
|
r.Dependencies = updatedDeps
|
||||||
r.Changes = projectChanges
|
r.Changes = projectChanges
|
||||||
r.Version = tag
|
r.Tag = tag
|
||||||
|
r.Version = version
|
||||||
|
|
||||||
|
// Remove trailing new lines
|
||||||
|
r.Preface = strings.TrimRightFunc(r.Preface, unicode.IsSpace)
|
||||||
|
|
||||||
tmpl, err := getTemplate(context)
|
tmpl, err := getTemplate(context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -18,8 +18,10 @@ package main
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
defaultTemplateFile = "TEMPLATE"
|
defaultTemplateFile = "TEMPLATE"
|
||||||
releaseNotes = `Welcome to the {{.Version}} release of {{.ProjectName}}!
|
releaseNotes = `{{.ProjectName}} {{.Version}}
|
||||||
{{if .PreRelease -}}
|
|
||||||
|
Welcome to the {{.Tag}} release of {{.ProjectName}}!
|
||||||
|
{{- if .PreRelease }}
|
||||||
*This is a pre-release of {{.ProjectName}}*
|
*This is a pre-release of {{.ProjectName}}*
|
||||||
{{- end}}
|
{{- end}}
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -113,6 +114,26 @@ func getChangelog(previous, commit string) ([]byte, error) {
|
|||||||
return git("log", "--oneline", gitChangeDiff(previous, commit))
|
return git("log", "--oneline", gitChangeDiff(previous, commit))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func linkifyChanges(c []change, commit, msg func(change) (string, error)) error {
|
||||||
|
for i := range c {
|
||||||
|
commitLink, err := commit(c[i])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
description, err := msg(c[i])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
c[i].Commit = fmt.Sprintf("[`%s`](%s)", c[i].Commit, commitLink)
|
||||||
|
c[i].Description = description
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func parseChangelog(changelog []byte) ([]change, error) {
|
func parseChangelog(changelog []byte) ([]change, error) {
|
||||||
var (
|
var (
|
||||||
changes []change
|
changes []change
|
||||||
@ -282,3 +303,36 @@ func getTemplate(context *cli.Context) (string, error) {
|
|||||||
}
|
}
|
||||||
return string(data), nil
|
return string(data), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func githubCommitLink(repo string) func(change) (string, error) {
|
||||||
|
return func(c change) (string, error) {
|
||||||
|
full, err := git("rev-parse", c.Commit)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
commit := strings.TrimSpace(string(full))
|
||||||
|
|
||||||
|
return fmt.Sprintf("https://github.com/%s/commit/%s", repo, commit), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func githubPRLink(repo string) func(change) (string, error) {
|
||||||
|
r := regexp.MustCompile("^Merge pull request #[0-9]+")
|
||||||
|
return func(c change) (string, error) {
|
||||||
|
var err error
|
||||||
|
message := r.ReplaceAllStringFunc(c.Description, func(m string) string {
|
||||||
|
idx := strings.Index(m, "#")
|
||||||
|
pr := m[idx+1:]
|
||||||
|
|
||||||
|
// TODO: Validate links using github API
|
||||||
|
// TODO: Validate PR merged as commit hash
|
||||||
|
link := fmt.Sprintf("https://github.com/%s/pull/%s", repo, pr)
|
||||||
|
|
||||||
|
return fmt.Sprintf("%s [#%s](%s)", m[:idx], pr, link)
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return message, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user