Skip to content

Commit

Permalink
Add release notes generation
Browse files Browse the repository at this point in the history
  • Loading branch information
dippynark committed Jan 9, 2024
1 parent 816833a commit fef5c3b
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 2 deletions.
5 changes: 3 additions & 2 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ https://github.com/kubernetes-sigs/controller-runtime/blob/main/RELEASE.md

1. Create a new release branch from main: `git checkout -b release-<MAJOR.MINOR>`
2. Push the new branch to the remote repository: ` git push --set-upstream origin release-<MAJOR.MINOR>`
3. Generate the release notes: `go run sigs.k8s.io/kubebuilder-release-tools/notes --project hsbc/cost-manager`
4. Create a new release in GitHub from the release branch, pasting the generated release notes
3. Fetch all tags from the remote: `git fetch --all --tags`
4. Generate the release notes from the previous tag: `go run ./hack/notes --from vMAJOR.MINOR.PATCH`
5. Create a new release in GitHub from the release branch, pasting the generated release notes
108 changes: 108 additions & 0 deletions hack/notes/notes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package main

import (
"flag"
"fmt"
"os"
"os/exec"
"strings"
)

/*
This tool generates release notes from the commits between two Git references
*/

var (
warnings = ":warning: Breaking Changes"
features = ":sparkles: New Features"
bugs = ":bug: Bug Fixes"
documentation = ":book: Documentation"
others = ":seedling: Others"
unknown = ":question: Sort these by hand"

outputOrder = []string{
warnings,
features,
bugs,
documentation,
others,
unknown,
}
)

func main() {
from := flag.String("from", "", "Include commits starting from this Git reference")
to := flag.String("to", "", "Include commits up to and including this Git reference. Defaults to HEAD")
flag.Parse()

err := run(*from, *to)
if err != nil {
os.Exit(1)
}
}

func run(from, to string) error {
if from == "" {
return fmt.Errorf("Git reference to start from must be specified")
}
if to == "" {
to = "HEAD"
}

cmd := exec.Command("git", "rev-list", fmt.Sprintf("%s..%s", from, to), "--pretty=format:%B")
out, err := cmd.CombinedOutput()
if err != nil {
return err
}

commits := map[string][]string{}
for _, output := range outputOrder {
commits[output] = []string{}
}
outLines := strings.Split(string(out), "\n")
for i, line := range outLines {
// If we have found a commit then we pick the next line
if !strings.HasPrefix(line, "commit ") {
continue
}
title := outLines[i+1]
var key string
switch {
case strings.HasPrefix(title, "⚠️"):
key = warnings
title = strings.TrimPrefix(title, "⚠️")
case strings.HasPrefix(title, "✨"):
key = features
title = strings.TrimPrefix(title, "✨")
case strings.HasPrefix(title, "🐛"):
key = bugs
title = strings.TrimPrefix(title, "🐛")
case strings.HasPrefix(title, "📖"):
key = documentation
title = strings.TrimPrefix(title, "📖")
case strings.HasPrefix(title, "🌱"):
key = others
title = strings.TrimPrefix(title, "🌱")
default:
key = unknown
}
title = strings.TrimSpace(title)
commits[key] = append(commits[key], title)
}

fmt.Printf("## Changes since [%s](https://github.com/hsbc/cost-manager/releases/%s)\n\n", from, from)
for _, key := range outputOrder {
commits := commits[key]
if len(commits) == 0 {
continue
}

fmt.Printf("### %s\n\n", key)
for _, commit := range commits {
fmt.Printf("- %s\n", commit)
}
fmt.Println()
}

return nil
}

0 comments on commit fef5c3b

Please sign in to comment.