releaser: Rework and simplify to use GitHub only for release notes
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 2 Dec 2021 21:08:52 +0000 (22:08 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 3 Dec 2021 16:02:20 +0000 (17:02 +0100)
releaser/git.go
releaser/releasenotes_writer.go
releaser/releasenotes_writer_test.go
releaser/releaser.go

index a03a48e99d95108dafd801a6a71e879e7722cf86..831a0bc04273ca0d50c7433c0f4815400fb5f605 100644 (file)
@@ -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
index eee9501e5fa185d5a72cecf46968b28201d4ce7d..fcbacd308d74fe89846ddb55ad03b6999db386ba 100644 (file)
@@ -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
-}
index bffcb1ccb6c29489005a6363f1093ba47251b15a..7dcd0ccaac6a4d8736259a07225523064b53a4c5 100644 (file)
@@ -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())
 }
index 56d0cf1a226fc3e1f16ddb017fd2adae3a888bc0..e87836fd5c035267f6b759cbec13268545bae2e6 100644 (file)
@@ -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
        }