Updates shows the playbook's new changelog entries, yours first
The changelog is where the playbook says what breaks and what to do; the commit list doesn't. Entries that name your homeserver or link an enabled component's doc page are marked and shown with their first paragraph. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4d902b7b95
commit
5f5910bd83
5 files changed
+158
-3
No files matched your search
@@ -212,8 +212,10 @@ or the [Telegram group](https://t.me/+6UwIu9F4gZQxNjM0).
|
||||
with how many accounts it has made, when it was last used and when it
|
||||
runs out. Make new ones limited to some uses or days, and revoke or
|
||||
restore them.
|
||||
- **Update preview:** the new playbook commits and the component
|
||||
versions they change, before installing anything.
|
||||
- **Update preview:** the playbook's new `CHANGELOG.md` entries, the
|
||||
new commits and the component versions they change, before installing
|
||||
anything. Entries about your homeserver or a component you've turned
|
||||
on come first, marked, with their first paragraph.
|
||||
- **Rollback:** every successful install records its playbook commit and
|
||||
answers (the last 10). Rolling back backs up the database, checks
|
||||
that commit out and reinstalls; the playbook stays held there until
|
||||
|
||||
@@ -118,6 +118,18 @@ func Changes(args []string) error {
|
||||
return nil
|
||||
}
|
||||
fmt.Println(head.Render(fmt.Sprintf("==> %d new commit(s), %s → %s", ch.Total, ch.From[:10], ch.To[:10])))
|
||||
for _, n := range ch.Notices {
|
||||
if len(n.Yours) == 0 {
|
||||
fmt.Printf(" · %s %s\n", muted.Render(n.Date), n.Title)
|
||||
continue
|
||||
}
|
||||
para, _, _ := strings.Cut(n.Body, "\n\n")
|
||||
fmt.Printf(" %s %s %s %s\n %s\n", warn.Render("!"), muted.Render(n.Date), n.Title,
|
||||
warn.Render("("+strings.Join(n.Yours, ", ")+")"), muted.Render(strings.Join(strings.Fields(para), " ")))
|
||||
}
|
||||
if len(ch.Notices) > 0 {
|
||||
fmt.Println()
|
||||
}
|
||||
for _, v := range ch.Versions {
|
||||
switch {
|
||||
case v.Old == "":
|
||||
|
||||
@@ -7,12 +7,14 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"interzone/internal/catalog"
|
||||
"interzone/internal/config"
|
||||
)
|
||||
|
||||
@@ -23,6 +25,14 @@ type Changes struct {
|
||||
Total int // commits; Commits holds the newest of them
|
||||
Commits []Commit
|
||||
Versions []VersionChange
|
||||
Notices []Notice // CHANGELOG.md entries the update adds, newest first
|
||||
}
|
||||
|
||||
// Notice is a CHANGELOG.md entry: the playbook's word on breaking changes
|
||||
// and what to do about them.
|
||||
type Notice struct {
|
||||
Date, Title, Body string
|
||||
Yours []string // what it mentions that this server runs
|
||||
}
|
||||
|
||||
type Commit struct {
|
||||
@@ -82,11 +92,12 @@ func PreviewUpdate(ctx context.Context, c *config.Config) (*Changes, error) {
|
||||
}
|
||||
}
|
||||
|
||||
files, _ := git("diff", "--name-only", ch.From, ch.To, "--", "requirements.yml", "roles/custom")
|
||||
show := func(rev, file string) string {
|
||||
out, _ := git("show", rev+":"+file)
|
||||
return out
|
||||
}
|
||||
ch.Notices = newNotices(show(ch.From, "CHANGELOG.md"), show(ch.To, "CHANGELOG.md"), c)
|
||||
files, _ := git("diff", "--name-only", ch.From, ch.To, "--", "requirements.yml", "roles/custom")
|
||||
for _, f := range strings.Split(files, "\n") {
|
||||
switch {
|
||||
case f == "requirements.yml":
|
||||
@@ -99,6 +110,72 @@ func PreviewUpdate(ctx context.Context, c *config.Config) (*Changes, error) {
|
||||
return ch, nil
|
||||
}
|
||||
|
||||
var mdLink = regexp.MustCompile(`\[([^\]]*)\]\([^)]*\)`)
|
||||
|
||||
// newNotices are the entries of the new changelog that the old one hasn't,
|
||||
// marked with what each mentions of this server: its homeserver in the
|
||||
// title, or an enabled component's doc page.
|
||||
func newNotices(old, cur string, c *config.Config) []Notice {
|
||||
if old == "" {
|
||||
return nil // no changelog before: everything would look new
|
||||
}
|
||||
seen := map[string]bool{}
|
||||
for _, l := range strings.Split(old, "\n") {
|
||||
if t, ok := strings.CutPrefix(l, "## "); ok {
|
||||
seen[strings.TrimSpace(t)] = true
|
||||
}
|
||||
}
|
||||
var out []Notice
|
||||
date := ""
|
||||
for _, l := range strings.Split(cur, "\n") {
|
||||
switch {
|
||||
case strings.HasPrefix(l, "# "):
|
||||
date = strings.TrimSpace(l[2:])
|
||||
case strings.HasPrefix(l, "## "):
|
||||
t := strings.TrimSpace(l[3:])
|
||||
if seen[t] {
|
||||
return markYours(out, c)
|
||||
}
|
||||
out = append(out, Notice{Date: date, Title: mdLink.ReplaceAllString(t, "$1")})
|
||||
case len(out) > 0:
|
||||
out[len(out)-1].Body += l + "\n"
|
||||
}
|
||||
}
|
||||
return markYours(out, c)
|
||||
}
|
||||
|
||||
// mentions are words that tie a notice to a component besides its doc
|
||||
// page: Element Call and Matrix RTC run LiveKit.
|
||||
var mentions = map[string][]string{"matrix-rtc": {"livekit"}, "element-call": {"livekit", "matrix rtc"}}
|
||||
|
||||
func markYours(ns []Notice, c *config.Config) []Notice {
|
||||
for i := range ns {
|
||||
n := &ns[i]
|
||||
n.Body = strings.TrimSpace(n.Body)
|
||||
text := strings.ToLower(n.Title + "\n" + n.Body)
|
||||
for _, h := range catalog.Homeservers {
|
||||
// by title: nearly every entry mentions Synapse in passing
|
||||
if h.ID == c.Homeserver && strings.Contains(strings.ToLower(n.Title), strings.ToLower(h.Name)) {
|
||||
n.Yours = append(n.Yours, h.Name)
|
||||
}
|
||||
}
|
||||
for _, comp := range catalog.Components {
|
||||
if !c.Enabled(comp) {
|
||||
continue
|
||||
}
|
||||
hit := comp.Doc != "" && strings.Contains(text, strings.ToLower(comp.Doc))
|
||||
for _, w := range mentions[comp.ID] {
|
||||
hit = hit || strings.Contains(text, w)
|
||||
}
|
||||
if hit {
|
||||
n.Yours = append(n.Yours, comp.Name)
|
||||
}
|
||||
}
|
||||
n.Body = mdLink.ReplaceAllString(n.Body, "$1")
|
||||
}
|
||||
return ns
|
||||
}
|
||||
|
||||
// roleVersions reads requirements.yml: role name → version.
|
||||
func roleVersions(text string) map[string]string {
|
||||
var reqs []struct {
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package deploy
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"interzone/internal/config"
|
||||
)
|
||||
|
||||
func TestNewNotices(t *testing.T) {
|
||||
old := "# 2026-09-18\n\n## LiveKit JWT Service 0.7.0\n\nOld news.\n"
|
||||
cur := "# 2026-10-19\n\n## `just start-all` restarts again\n\nEveryone.\n\n" +
|
||||
"# 2026-09-22\n\n## LiveKit's TURN over TLS works\n\nThis only affects you if you have [LiveKit Server](./docs/configuring-playbook-livekit-server.md).\n\n" +
|
||||
"## Postmoogle moved\n\nSee [the docs](docs/configuring-playbook-bridge-postmoogle.md); Synapse is unaffected.\n\n" + old
|
||||
c := config.Default()
|
||||
c.Homeserver = "synapse"
|
||||
c.Components = map[string]bool{"matrix-rtc": true}
|
||||
ns := newNotices(old, cur, c)
|
||||
if len(ns) != 3 {
|
||||
t.Fatalf("got %d notices: %+v", len(ns), ns)
|
||||
}
|
||||
if ns[0].Date != "2026-10-19" || ns[0].Title != "`just start-all` restarts again" || ns[0].Yours != nil {
|
||||
t.Errorf("first: %+v", ns[0])
|
||||
}
|
||||
if !slices.Contains(ns[1].Yours, "Matrix RTC stack") || ns[1].Body != "This only affects you if you have LiveKit Server." {
|
||||
t.Errorf("LiveKit notice: %+v", ns[1])
|
||||
}
|
||||
if ns[2].Yours != nil {
|
||||
t.Errorf("Postmoogle is off and Synapse only mentioned, yet: %+v", ns[2])
|
||||
}
|
||||
if newNotices("", cur, c) != nil {
|
||||
t.Errorf("no old changelog should give no notices")
|
||||
}
|
||||
}
|
||||
@@ -179,6 +179,9 @@ func (s *updatesScreen) content() string {
|
||||
}
|
||||
lines = append(lines, sTitle.Render(fmt.Sprintf("%d new playbook commit(s)", ch.Total))+
|
||||
sFaint.Render(fmt.Sprintf(" %s → %s", ch.From[:10], ch.To[:10])), "")
|
||||
if len(ch.Notices) > 0 {
|
||||
lines = append(append(lines, sectionHeading("From the playbook's changelog", 60), ""), noticeLines(ch.Notices)...)
|
||||
}
|
||||
if len(ch.Versions) > 0 {
|
||||
lines = append(lines, sectionHeading("Version changes", 60), "")
|
||||
nameW := 18
|
||||
@@ -208,6 +211,33 @@ func (s *updatesScreen) content() string {
|
||||
return strings.Join(lines, "\n")
|
||||
}
|
||||
|
||||
// noticeLines lists the changelog entries an update brings: the ones about
|
||||
// what this server runs first, with their first paragraph, then the rest
|
||||
// by title.
|
||||
func noticeLines(ns []deploy.Notice) []string {
|
||||
var yours, rest []string
|
||||
for _, n := range ns {
|
||||
head := sFaint.Render(n.Date) + " " + sTitle.Render(n.Title)
|
||||
if len(n.Yours) == 0 {
|
||||
rest = append(rest, " "+sFaint.Render("·")+" "+head)
|
||||
continue
|
||||
}
|
||||
para, _, _ := strings.Cut(n.Body, "\n\n")
|
||||
body := lipgloss.NewStyle().Width(68).Render(strings.Join(strings.Fields(para), " "))
|
||||
yours = append(yours, " "+sWarn.Render("!")+" "+head+sWarn.Render(" ("+strings.Join(n.Yours, ", ")+")"),
|
||||
" "+sMuted.Render(strings.ReplaceAll(body, "\n", "\n ")), "")
|
||||
}
|
||||
out := yours
|
||||
if len(yours) > 0 {
|
||||
out = append([]string{sWarn.Render("! These are about what your server runs; read them before updating."), ""}, out...)
|
||||
}
|
||||
if len(rest) > 0 {
|
||||
out = append(out, rest...)
|
||||
out = append(out, "")
|
||||
}
|
||||
return append(out, sFaint.Render(" The whole changelog: CHANGELOG.md in the playbook."), "")
|
||||
}
|
||||
|
||||
func (s *updatesScreen) view(w, h int) string {
|
||||
switch {
|
||||
case s.loading:
|
||||
|
||||
Reference in new issue
Block a user