ci: release automation from Conventional Commits
tools/release derives the next version from the commits since the last stable release and renders the changelog. `make release` tags it on main, CHANNEL=beta a numbered prerelease of the coming version; pushing the tag runs the release workflow, which publishes the release with its notes, Linux binaries and checksums. Images get channel tags: edge for main, beta for prereleases, latest, stable and X.Y for releases. Closes #33 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
1ad68e2e87
commit
68a7827475
8 files changed
+644
-5
No files matched your search
@@ -0,0 +1,112 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// commit is one Conventional Commit.
|
||||
type commit struct {
|
||||
Hash, Subject, Body string
|
||||
}
|
||||
|
||||
var subjectPattern = regexp.MustCompile(`^([a-z]+)(?:\(([^)]+)\))?(!)?: (.+)$`)
|
||||
|
||||
// parsed splits the subject into type, scope and description.
|
||||
func (c commit) parsed() (typ, scope, desc string, breaking bool) {
|
||||
m := subjectPattern.FindStringSubmatch(c.Subject)
|
||||
if m == nil {
|
||||
return "", "", c.Subject, false
|
||||
}
|
||||
return m[1], m[2], m[4], m[3] == "!" || c.breakingNote() != ""
|
||||
}
|
||||
|
||||
// breakingNote returns the BREAKING CHANGE footer.
|
||||
func (c commit) breakingNote() string {
|
||||
for _, prefix := range []string{"BREAKING CHANGE: ", "BREAKING-CHANGE: "} {
|
||||
if _, after, ok := strings.Cut(c.Body, prefix); ok {
|
||||
note, _, _ := strings.Cut(after, "\n\n")
|
||||
return strings.Join(strings.Fields(note), " ")
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (c commit) bump() bump {
|
||||
typ, _, _, breaking := c.parsed()
|
||||
switch {
|
||||
case breaking:
|
||||
return bumpMajor
|
||||
case typ == "feat":
|
||||
return bumpMinor
|
||||
case typ == "fix" || typ == "perf":
|
||||
return bumpPatch
|
||||
}
|
||||
return bumpNone
|
||||
}
|
||||
|
||||
var sections = []struct{ typ, title string }{
|
||||
{"feat", "Features"},
|
||||
{"fix", "Fixes"},
|
||||
{"perf", "Performance"},
|
||||
}
|
||||
|
||||
// notes renders the changelog of a release in Markdown. Changes outside
|
||||
// features, fixes and performance stay out, except breaking ones.
|
||||
func notes(v version, prev *version, commits []commit, repoURL string) string {
|
||||
var b strings.Builder
|
||||
line := func(c commit, desc, scope string) {
|
||||
if scope != "" {
|
||||
desc = "**" + scope + ":** " + desc
|
||||
}
|
||||
short := c.Hash[:min(len(c.Hash), 7)]
|
||||
if repoURL != "" {
|
||||
fmt.Fprintf(&b, "- %s ([%s](%s/commit/%s))\n", desc, short, repoURL, c.Hash)
|
||||
} else {
|
||||
fmt.Fprintf(&b, "- %s (%s)\n", desc, short)
|
||||
}
|
||||
}
|
||||
|
||||
var breaking []commit
|
||||
for _, c := range commits {
|
||||
if _, _, _, br := c.parsed(); br {
|
||||
breaking = append(breaking, c)
|
||||
}
|
||||
}
|
||||
if len(breaking) > 0 {
|
||||
b.WriteString("### Breaking changes\n\n")
|
||||
for _, c := range breaking {
|
||||
_, scope, desc, _ := c.parsed()
|
||||
if n := c.breakingNote(); n != "" {
|
||||
desc += ": " + n
|
||||
}
|
||||
line(c, desc, scope)
|
||||
}
|
||||
b.WriteString("\n")
|
||||
}
|
||||
for _, s := range sections {
|
||||
head := false
|
||||
for _, c := range commits {
|
||||
typ, scope, desc, _ := c.parsed()
|
||||
if typ != s.typ {
|
||||
continue
|
||||
}
|
||||
if !head {
|
||||
fmt.Fprintf(&b, "### %s\n\n", s.title)
|
||||
head = true
|
||||
}
|
||||
line(c, desc, scope)
|
||||
}
|
||||
if head {
|
||||
b.WriteString("\n")
|
||||
}
|
||||
}
|
||||
if b.Len() == 0 {
|
||||
b.WriteString("No user-facing changes.\n\n")
|
||||
}
|
||||
if prev != nil && repoURL != "" {
|
||||
fmt.Fprintf(&b, "**Full changes:** [%s...%s](%s/compare/%s...%s)\n", prev, v, repoURL, prev, v)
|
||||
}
|
||||
return b.String()
|
||||
}
|
||||
Reference in new issue
Block a user