From 39a1e0efa310e683e75b999fdb71deb8157039de Mon Sep 17 00:00:00 2001 From: Starnop Date: Thu, 13 Jun 2019 09:04:52 +0000 Subject: [PATCH] feature: update it to use by df Signed-off-by: Starnop --- cmd/release-tool/README.md | 47 ++++++++ cmd/release-tool/main.go | 200 +++++++++++++++++------------------ cmd/release-tool/template.go | 22 ++-- cmd/release-tool/util.go | 1 + script/release-template.toml | 23 ++++ 5 files changed, 180 insertions(+), 113 deletions(-) create mode 100644 cmd/release-tool/README.md create mode 100644 script/release-template.toml diff --git a/cmd/release-tool/README.md b/cmd/release-tool/README.md new file mode 100644 index 0000000..3d196dc --- /dev/null +++ b/cmd/release-tool/README.md @@ -0,0 +1,47 @@ +# README + +## How to use it to help create a release + +### Step 1 + +Use `go build` to compile project. + +### Step 2 + +Create a release file, and this is a template + +```toml +# commit to be tagged for new release +commit = "HEAD" + +project_name = "Dragonfly" +github_repo = "dragonflyoss/Dragonfly" +match_deps = "^github.com/(dragonflyoss/[a-zA-Z0-9-]+)$" + +# previous release +previous = "v0.3.0" + +# whether this is a pre-release version +pre_release = false + +preface = """\ +This is a text preface text. +""" + +supernode_image = "https://hub.docker.com/r/dragonflyoss/supernode/tags" +df_client_image = "https://hub.docker.com/r/dragonflyoss/dfclient/tags" + +breaking_changes = """\ +* This is a break item 1. +* This is a break item 2. +""" +``` + +### Step 3 + +Use this command to generate a release note. + +```shell +VERSION="v0.4.0" +release-tool -n -d -t $VERSION release-template.toml > $VERSION.note +``` diff --git a/cmd/release-tool/main.go b/cmd/release-tool/main.go index c190d0e..ccfe975 100644 --- a/cmd/release-tool/main.go +++ b/cmd/release-tool/main.go @@ -18,18 +18,12 @@ package main import ( "fmt" - "io/ioutil" "os" - "path" - "path/filepath" - "regexp" - "sort" "strings" "text/tabwriter" "text/template" "unicode" - "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/urfave/cli" ) @@ -69,14 +63,17 @@ type projectRename struct { } type release struct { - ProjectName string `toml:"project_name"` - GithubRepo string `toml:"github_repo"` - Commit string `toml:"commit"` - Previous string `toml:"previous"` - PreRelease bool `toml:"pre_release"` - Preface string `toml:"preface"` - Notes map[string]note `toml:"notes"` - BreakingChanges map[string]change `toml:"breaking"` + ProjectName string `toml:"project_name"` + GithubRepo string `toml:"github_repo"` + Commit string `toml:"commit"` + Previous string `toml:"previous"` + PreRelease bool `toml:"pre_release"` + Preface string `toml:"preface"` + Notes map[string]note `toml:"notes"` + BreakingChanges string `toml:"breaking_changes"` + + SupernodeImage string `toml:"supernode_image"` + DfClientImage string `toml:"df_client_image"` // dependency options MatchDeps string `toml:"match_deps"` @@ -140,12 +137,6 @@ This tool should be ran from the root of the project repository for a new releas } logrus.Infof("Welcome to the %s release tool...", r.ProjectName) - mailmapPath, err := filepath.Abs(".mailmap") - if err != nil { - return errors.Wrap(err, "failed to resolve mailmap") - } - gitConfigs["mailmap.file"] = mailmapPath - var ( contributors = map[contributor]int{} projectChanges = []projectChange{} @@ -169,93 +160,94 @@ This tool should be ran from the root of the project repository for a new releas }) logrus.Infof("creating new release %s with %d new changes...", tag, len(changes)) - rd, err := fileFromRev(r.Commit, vendorConf) - if err != nil { - return err - } - previous, err := getPreviousDeps(r.Previous) - if err != nil { - return err - } - deps, err := parseDependencies(rd) - if err != nil { - return err - } - renameDependencies(previous, r.RenameDeps) - updatedDeps := updatedDeps(previous, deps) - - sort.Slice(updatedDeps, func(i, j int) bool { - return updatedDeps[i].Name < updatedDeps[j].Name - }) - - if r.MatchDeps != "" && len(updatedDeps) > 0 { - re, err := regexp.Compile(r.MatchDeps) - if err != nil { - return errors.Wrap(err, "unable to compile 'match_deps' regexp") - } - td, err := ioutil.TempDir("", "tmp-clone-") - if err != nil { - return errors.Wrap(err, "unable to create temp clone directory") - } - defer os.RemoveAll(td) - - cwd, err := os.Getwd() - if err != nil { - return errors.Wrap(err, "unable to get cwd") - } - for _, dep := range updatedDeps { - matches := re.FindStringSubmatch(dep.Name) - if matches == nil { - continue - } - logrus.Debugf("Matched dependency %s with %s", dep.Name, r.MatchDeps) - var name string - if len(matches) < 2 { - name = path.Base(dep.Name) - } else { - name = matches[1] - } - if err := os.Chdir(td); err != nil { - return errors.Wrap(err, "unable to chdir to temp clone directory") - } - git("clone", dep.CloneURL, name) - - if err := os.Chdir(name); err != nil { - return errors.Wrapf(err, "unable to chdir to cloned %s directory", name) - } - - changes, err := changelog(dep.Previous, dep.Commit) - if err != nil { - return errors.Wrapf(err, "failed to get changelog for %s", name) - } - if err := addContributors(dep.Previous, dep.Commit, contributors); err != nil { - 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{ - Name: name, - Changes: changes, - }) - - } - if err := os.Chdir(cwd); err != nil { - return errors.Wrap(err, "unable to chdir to previous cwd") - } - } + // rd, err := fileFromRev(r.Commit, vendorConf) + // if err != nil { + // logrus.Errorf("failed to ", args ...interface{}) + // return err + // } + // previous, err := getPreviousDeps(r.Previous) + // if err != nil { + // return err + // } + // deps, err := parseDependencies(rd) + // if err != nil { + // return err + // } + // renameDependencies(previous, r.RenameDeps) + // updatedDeps := updatedDeps(previous, deps) + + // sort.Slice(updatedDeps, func(i, j int) bool { + // return updatedDeps[i].Name < updatedDeps[j].Name + // }) + + // if r.MatchDeps != "" && len(updatedDeps) > 0 { + // re, err := regexp.Compile(r.MatchDeps) + // if err != nil { + // return errors.Wrap(err, "unable to compile 'match_deps' regexp") + // } + // td, err := ioutil.TempDir("", "tmp-clone-") + // if err != nil { + // return errors.Wrap(err, "unable to create temp clone directory") + // } + // defer os.RemoveAll(td) + + // cwd, err := os.Getwd() + // if err != nil { + // return errors.Wrap(err, "unable to get cwd") + // } + // for _, dep := range updatedDeps { + // matches := re.FindStringSubmatch(dep.Name) + // if matches == nil { + // continue + // } + // logrus.Debugf("Matched dependency %s with %s", dep.Name, r.MatchDeps) + // var name string + // if len(matches) < 2 { + // name = path.Base(dep.Name) + // } else { + // name = matches[1] + // } + // if err := os.Chdir(td); err != nil { + // return errors.Wrap(err, "unable to chdir to temp clone directory") + // } + // git("clone", dep.CloneURL, name) + + // if err := os.Chdir(name); err != nil { + // return errors.Wrapf(err, "unable to chdir to cloned %s directory", name) + // } + + // changes, err := changelog(dep.Previous, dep.Commit) + // if err != nil { + // return errors.Wrapf(err, "failed to get changelog for %s", name) + // } + // if err := addContributors(dep.Previous, dep.Commit, contributors); err != nil { + // 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{ + // Name: name, + // Changes: changes, + // }) + + // } + // if err := os.Chdir(cwd); err != nil { + // return errors.Wrap(err, "unable to chdir to previous cwd") + // } + // } // update the release fields with generated data r.Contributors = orderContributors(contributors) - r.Dependencies = updatedDeps + // r.Dependencies = updatedDeps r.Changes = projectChanges r.Tag = tag r.Version = version diff --git a/cmd/release-tool/template.go b/cmd/release-tool/template.go index a1da2d2..f23d550 100644 --- a/cmd/release-tool/template.go +++ b/cmd/release-tool/template.go @@ -27,8 +27,18 @@ Welcome to the {{.Tag}} release of {{.ProjectName}}! {{.Preface}} -Please try out the release binaries and report any issues at -https://github.com/{{.GithubRepo}}/issues. +### Images +--- +{{- if .SupernodeImage }} +* Supernode Image Link: [supernode:{{.Version}}]({{.SupernodeImage}}) +{{- end}} +{{- if .DfClientImage }} +* Supernode Image Link: [dfclient:{{.Version}}]({{.DfClientImage}}) +{{- end}} + +### Breaking Changes +--- +{{.BreakingChanges}} {{- range $note := .Notes}} @@ -38,6 +48,7 @@ https://github.com/{{.GithubRepo}}/issues. {{- end}} ### Contributors +--- {{range $contributor := .Contributors}} * {{$contributor}} {{- end -}} @@ -49,12 +60,5 @@ https://github.com/{{.GithubRepo}}/issues. * {{$change.Commit}} {{$change.Description}} {{- end}} {{- end}} - -### Dependency Changes - -Previous release can be found at [{{.Previous}}](https://github.com/{{.GithubRepo}}/releases/tag/{{.Previous}}) -{{range $dep := .Dependencies}} -* **{{$dep.Name}}** {{if $dep.Previous}}{{$dep.Previous}} -> {{$dep.Commit}}{{else}}{{$dep.Commit}} **_new_**{{end}} -{{- end}} ` ) diff --git a/cmd/release-tool/util.go b/cmd/release-tool/util.go index 77ef305..db54db8 100644 --- a/cmd/release-tool/util.go +++ b/cmd/release-tool/util.go @@ -98,6 +98,7 @@ func getPreviousDeps(previous string) ([]dependency, error) { func changelog(previous, commit string) ([]change, error) { raw, err := getChangelog(previous, commit) if err != nil { + logrus.Infof("failed to get change log previous(%s) commit(%s): %v", previous, commit, err) return nil, err } return parseChangelog(raw) diff --git a/script/release-template.toml b/script/release-template.toml new file mode 100644 index 0000000..ca0e155 --- /dev/null +++ b/script/release-template.toml @@ -0,0 +1,23 @@ +# commit to be tagged for new release +commit = "HEAD" + +project_name = "Dragonfly" +github_repo = "dragonflyoss/Dragonfly" +match_deps = "^github.com/(dragonflyoss/[a-zA-Z0-9-]+)$" + +# previous release +previous = "v0.3.0" + +pre_release = false + +preface = """\ +This is a text preface text. +""" + +supernode_image = "https://hub.docker.com/r/dragonflyoss/supernode/tags" +df_client_image = "https://hub.docker.com/r/dragonflyoss/dfclient/tags" + +breaking_changes = """\ +* This is a break item 1. +* This is a break item 2. +"""