diff options
author | Bjørn Erik Pedersen <[email protected]> | 2021-12-02 22:08:52 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2021-12-03 17:02:20 +0100 |
commit | 24a893cf838b87e670e9c2a653611c55241ee68c (patch) | |
tree | 35f35300da5e14c74162a112f4c4f1951877e974 /releaser | |
parent | bf1564bd2cc60cd0c14744148b1defd18360e91f (diff) | |
download | hugo-24a893cf838b87e670e9c2a653611c55241ee68c.tar.gz hugo-24a893cf838b87e670e9c2a653611c55241ee68c.zip |
releaser: Rework and simplify to use GitHub only for release notes
Diffstat (limited to 'releaser')
-rw-r--r-- | releaser/git.go | 69 | ||||
-rw-r--r-- | releaser/releasenotes_writer.go | 97 | ||||
-rw-r--r-- | releaser/releasenotes_writer_test.go | 10 | ||||
-rw-r--r-- | releaser/releaser.go | 28 |
4 files changed, 27 insertions, 177 deletions
diff --git a/releaser/git.go b/releaser/git.go index a03a48e99..831a0bc04 100644 --- a/releaser/git.go +++ b/releaser/git.go @@ -34,12 +34,10 @@ const ( ) type changeLog struct { - Version string - Enhancements map[string]gitInfos - Fixes map[string]gitInfos - Notes gitInfos - All gitInfos - Docs gitInfos + Version string + Notes gitInfos + All gitInfos + Docs gitInfos // Overall stats Repo *gitHubRepo @@ -48,66 +46,19 @@ type changeLog struct { } func newChangeLog(infos, docInfos gitInfos) *changeLog { - return &changeLog{ - Enhancements: make(map[string]gitInfos), - Fixes: make(map[string]gitInfos), - All: infos, - Docs: docInfos, - } -} - -func (l *changeLog) addGitInfo(isFix bool, info gitInfo, category string) { - var ( - infos gitInfos - found bool - segment map[string]gitInfos - ) - - if category == notesChanges { - l.Notes = append(l.Notes, info) - return - } else if isFix { - segment = l.Fixes - } else { - segment = l.Enhancements - } - - infos, found = segment[category] - if !found { - infos = gitInfos{} + log := &changeLog{ + Docs: docInfos, } - infos = append(infos, info) - segment[category] = infos -} - -func gitInfosToChangeLog(infos, docInfos gitInfos) *changeLog { - log := newChangeLog(infos, docInfos) for _, info := range infos { - los := strings.ToLower(info.Subject) - isFix := strings.Contains(los, "fix") - category := otherChanges - // TODO(bep) improve - if regexp.MustCompile("(?i)deprecate").MatchString(los) { - category = notesChanges - } else if regexp.MustCompile("(?i)tpl|tplimpl:|layout").MatchString(los) { - category = templateChanges - } else if regexp.MustCompile("(?i)hugolib:").MatchString(los) { - category = coreChanges - } else if regexp.MustCompile("(?i)out(put)?:|media:|Output|Media").MatchString(los) { - category = outChanges - } - - // Trim package prefix. - colonIdx := strings.Index(info.Subject, ":") - if colonIdx != -1 && colonIdx < (len(info.Subject)/2) { - info.Subject = info.Subject[colonIdx+1:] + if regexp.MustCompile("(?i)deprecate").MatchString(info.Subject) { + log.Notes = append(log.Notes, info) } + log.All = append(log.All, info) info.Subject = strings.TrimSpace(info.Subject) - log.addGitInfo(isFix, info, category) } return log @@ -255,7 +206,7 @@ func getGitInfosBefore(ref, tag, repo, repoPath string, remote bool) (gitInfos, } // Ignore autogenerated commits etc. in change log. This is a regexp. -const ignoredCommits = "releaser?:|snapcraft:|Merge commit|Squashed" +const ignoredCommits = "snapcraft:|Merge commit|Squashed" func gitLogBefore(ref, tag, repoPath string) (string, error) { var prevTag string diff --git a/releaser/releasenotes_writer.go b/releaser/releasenotes_writer.go index eee9501e5..fcbacd308 100644 --- a/releaser/releasenotes_writer.go +++ b/releaser/releasenotes_writer.go @@ -25,11 +25,10 @@ import ( "path/filepath" "strings" "text/template" - "time" ) const ( - issueLinkTemplate = "[#%d](https://github.com/gohugoio/hugo/issues/%d)" + issueLinkTemplate = "#%d" linkTemplate = "[%s](%s)" releaseNotesMarkdownTemplatePatchRelease = ` {{ if eq (len .All) 1 }} @@ -39,9 +38,9 @@ This is a bug-fix release with a couple of important fixes. {{ end }} {{ range .All }} {{- if .GitHubCommit -}} -* {{ .Subject }} {{ . | commitURL }} {{ . | authorURL }} {{ range .Issues }}{{ . | issue }}{{ end }} +* {{ .Subject }} {{ .Hash }} {{ . | authorURL }} {{ range .Issues }}{{ . | issue }} {{ end }} {{ else -}} -* {{ .Subject }} {{ range .Issues }}{{ . | issue }}{{ end }} +* {{ .Subject }} {{ range .Issues }}{{ . | issue }} {{ end }} {{ end -}} {{- end }} @@ -83,41 +82,17 @@ Hugo now has: ## Notes {{ template "change-section" . }} {{- end -}} -## Enhancements -{{ template "change-headers" .Enhancements -}} -## Fixes -{{ template "change-headers" .Fixes -}} - -{{ define "change-headers" }} -{{ $tmplChanges := index . "templateChanges" -}} -{{- $outChanges := index . "outChanges" -}} -{{- $coreChanges := index . "coreChanges" -}} -{{- $otherChanges := index . "otherChanges" -}} -{{- with $tmplChanges -}} -### Templates +{{ with .All }} +## Changes {{ template "change-section" . }} -{{- end -}} -{{- with $outChanges -}} -### Output -{{ template "change-section" . }} -{{- end -}} -{{- with $coreChanges -}} -### Core -{{ template "change-section" . }} -{{- end -}} -{{- with $otherChanges -}} -### Other -{{ template "change-section" . }} -{{- end -}} {{ end }} - {{ define "change-section" }} {{ range . }} {{- if .GitHubCommit -}} -* {{ .Subject }} {{ . | commitURL }} {{ . | authorURL }} {{ range .Issues }}{{ . | issue }}{{ end }} +* {{ .Subject }} {{ .Hash }} {{ . | authorURL }} {{ range .Issues }}{{ . | issue }} {{ end }} {{ else -}} -* {{ .Subject }} {{ range .Issues }}{{ . | issue }}{{ end }} +* {{ .Subject }} {{ range .Issues }}{{ . | issue }} {{ end }} {{ end -}} {{- end }} {{ end }} @@ -129,7 +104,7 @@ var templateFuncs = template.FuncMap{ return !strings.HasSuffix(c.Version, "0") }, "issue": func(id int) string { - return fmt.Sprintf(issueLinkTemplate, id, id) + return fmt.Sprintf(issueLinkTemplate, id) }, "commitURL": func(info gitInfo) string { if info.GitHubCommit.HTMLURL == "" { @@ -147,7 +122,7 @@ var templateFuncs = template.FuncMap{ func writeReleaseNotes(version string, infosMain, infosDocs gitInfos, to io.Writer) error { client := newGitHubAPI("hugo") - changes := gitInfosToChangeLog(infosMain, infosDocs) + changes := newChangeLog(infosMain, infosDocs) changes.Version = version repo, err := client.fetchRepo() if err == nil { @@ -265,57 +240,3 @@ func (r *ReleaseHandler) writeReleaseNotesToTemp(version string, isPatch bool, i return name, nil } - -func (r *ReleaseHandler) writeReleaseNotesToDocs(title, description, sourceFilename string) (string, error) { - targetFilename := "index.md" - bundleDir := strings.TrimSuffix(filepath.Base(sourceFilename), "-ready.md") - contentDir := hugoFilepath("docs/content/en/news/" + bundleDir) - targetFullFilename := filepath.Join(contentDir, targetFilename) - - if r.try { - fmt.Printf("Write release notes to /docs: Bundle %q Dir: %q\n", bundleDir, contentDir) - return targetFullFilename, nil - } - - if err := os.MkdirAll(contentDir, os.ModePerm); err != nil { - return "", nil - } - - b, err := ioutil.ReadFile(sourceFilename) - if err != nil { - return "", err - } - - f, err := os.Create(targetFullFilename) - if err != nil { - return "", err - } - defer f.Close() - - fmTail := "" - if !strings.HasSuffix(title, ".0") { - // Bug fix release - fmTail = ` -images: -- images/blog/hugo-bug-poster.png -` - } - - if _, err := f.WriteString(fmt.Sprintf(` ---- -date: %s -title: %q -description: %q -categories: ["Releases"]%s ---- - - `, time.Now().Format("2006-01-02"), title, description, fmTail)); err != nil { - return "", err - } - - if _, err := f.Write(b); err != nil { - return "", err - } - - return targetFullFilename, nil -} diff --git a/releaser/releasenotes_writer_test.go b/releaser/releasenotes_writer_test.go index bffcb1ccb..7dcd0ccaa 100644 --- a/releaser/releasenotes_writer_test.go +++ b/releaser/releasenotes_writer_test.go @@ -26,19 +26,21 @@ import ( ) func _TestReleaseNotesWriter(t *testing.T) { + skipIfNoToken(t) if os.Getenv("CI") != "" { // Travis has an ancient git with no --invert-grep: https://github.com/travis-ci/travis-ci/issues/6328 - t.Skip("Skip git test on CI to make Travis happy.") + t.Skip("Skip git test on CI to make Travis happy..") } + c := qt.New(t) var b bytes.Buffer - // TODO(bep) consider to query GitHub directly for the gitlog with author info, probably faster. - infos, err := getGitInfosBefore("HEAD", "v0.20", "hugo", "", false) + // TODO(bep) consider to query GitHub directly for the gitlog with author info, probably faster. + infos, err := getGitInfosBefore("HEAD", "v0.89.0", "hugo", "", false) c.Assert(err, qt.IsNil) - c.Assert(writeReleaseNotes("0.21", infos, infos, &b), qt.IsNil) + c.Assert(writeReleaseNotes("0.89.0", infos, infos, &b), qt.IsNil) fmt.Println(b.String()) } diff --git a/releaser/releaser.go b/releaser/releaser.go index 56d0cf1a2..e87836fd5 100644 --- a/releaser/releaser.go +++ b/releaser/releaser.go @@ -181,11 +181,6 @@ func (r *ReleaseHandler) Run() error { return nil } - // For docs, for now we assume that: - // The /docs subtree is up to date and ready to go. - // The hugoDocs/dev and hugoDocs/master must be merged manually after release. - // TODO(bep) improve this when we see how it works. - if err := r.bumpVersions(newVersion); err != nil { return err } @@ -194,27 +189,6 @@ func (r *ReleaseHandler) Run() error { return err } - releaseNotesFile := getReleaseNotesDocsTempFilename(version, true) - - title, description := version, version - if isPatch { - title = "Hugo " + version + ": A couple of Bug Fixes" - description = "This version fixes a couple of bugs introduced in " + mainVersion.String() + "." - } - - // Write the release notes to the docs site as well. - docFile, err := r.writeReleaseNotesToDocs(title, description, releaseNotesFile) - if err != nil { - return err - } - - if _, err := r.git("add", docFile); err != nil { - return err - } - if _, err := r.git("commit", "-m", fmt.Sprintf("%s Add release notes to /docs for release of %s\n\n[ci skip]", commitPrefix, newVersion)); err != nil { - return err - } - if _, err := r.git("tag", "-a", tag, "-m", fmt.Sprintf("%s %s [ci skip]", commitPrefix, newVersion)); err != nil { return err } @@ -225,6 +199,8 @@ func (r *ReleaseHandler) Run() error { } } + releaseNotesFile := getReleaseNotesDocsTempFilename(version, true) + if err := r.release(releaseNotesFile); err != nil { return err } |