feat(release): one release stream, one version, one page per version

CHANGELOG.archied.md and CHANGELOG.archie.md were two version streams that
drifted: a release that moved both components had two numbers, two pages and
two tags, and a reader had to visit two files to learn what shipped.

The merged history holds 65 versions from 64 archied and 34 archie sections --
33 that both components released, 31 only archied, one only archie -- so 98
published pages become 65. A version's date is the newest of its sections'
dates, and a component whose own date differs carries it on its label, because
the history has two dates and the merge must not invent one. `## [Unreleased]`
is not a release: it gets no page, and it stays at the top of the file.

A level-two heading is where the merge could silently drop a section, so the
merge is verified by content rather than by the generator: section counts per
source, the merged version set against the exact union, and every source `###`
title present both as a substring and, after stripping the component prefix, as
an identical heading. Counting `##` headings rather than releases overcounts by
one here, which is how the empty `[Unreleased]` block was caught.

- newsgen reads one file and writes `docs/news/<version>.md`, the index, the
  canonical `releases.json`, and `docs/news/redirects.json`. The redirect table
  is what keeps the retired `/news/<component>/<version>/` URLs alive; it is
  generated beside the pages so it cannot drift from them.
- release.sh takes one `--version`, keeps commit and tag (the Woodpecker
  pipeline that will own them does not exist yet), and exits 3 when the commit
  set justifies no release, so a pipeline can finish green without tagging.
- The consumers of the two files follow: the deploy workflow's tag gate and
  release-notes extraction, the zip contents, the update check's changelog
  links, the packaged-path note, the docs skill, and newsgen's tests.

The per-component detail survives as labelled sections inside each release, so
a reader still learns whether archied or the agent changed; what goes away is
the separate numbers and the separate pages.
This commit is contained in:
sam committed 2026-09-22 17:18:06 +10:00
1 parent 10b755468e
commit cd2ab7f2cb
134 files changed
+3189 -3241

No files matched your search

+22 -47
View File
@@ -8,30 +8,17 @@ import (
"strings"
)
// component is one independently versioned binary and the changelog that
// carries its release notes. key is the tag prefix and the output directory;
// name is how the component is written for a reader.
type component struct {
key string
name string
changelog string
}
// components is the fixed publishing order. Archied leads because it is the
// user-facing entry point; the order only breaks ties between releases that
// share a date.
var components = []component{
{key: "archied", name: "archied", changelog: "CHANGELOG.archied.md"},
{key: "archie", name: "archie-agent", changelog: "CHANGELOG.archie.md"},
}
// changelogPath is the one file the release stream lives in. The two
// per-component changelogs were merged into it; their history is a section of
// this file rather than a separate source.
const changelogPath = "CHANGELOG.md"
// release is one changelog section: the facts a host needs to render a version.
// The per-component detail is inside Body, as labelled level-three sections.
type release struct {
Component string `json:"component"`
Name string `json:"name"`
Version string `json:"version"`
Date string `json:"date"`
Body string `json:"body"`
Version string `json:"version"`
Date string `json:"date"`
Body string `json:"body"`
}
// releaseHeading matches a changelog release heading. The date is optional in
@@ -46,8 +33,10 @@ var inlineLink = regexp.MustCompile(`\]\(([^)]+)\)`)
// an in-page anchor. Everything else is relative to the changelog's directory.
var linkScheme = regexp.MustCompile(`^[a-zA-Z][a-zA-Z0-9+.-]*:`)
// parseChangelog reads the release sections out of one component's changelog.
func parseChangelog(c component, source string) ([]release, error) {
// parseChangelog reads the release sections out of the changelog. `Unreleased`
// is skipped, not dropped: it is the one place unfinished work is recorded and
// it carries no version to publish.
func parseChangelog(source string) ([]release, error) {
var releases []release
for _, section := range splitSections(source) {
if !strings.HasPrefix(section.heading, "## [") {
@@ -55,27 +44,25 @@ func parseChangelog(c component, source string) ([]release, error) {
}
match := releaseHeading.FindStringSubmatch(section.heading)
if match == nil {
return nil, fmt.Errorf("%s: %q is not a release heading; write `## [<version>] - <date>`", c.changelog, section.heading)
return nil, fmt.Errorf("%s: %q is not a release heading; write `## [<version>] - <date>`", changelogPath, section.heading)
}
version, date := match[1], match[2]
if version == "Unreleased" {
continue
}
if date == "" {
return nil, fmt.Errorf("%s: release %s has no date; write `## [<version>] - <date>`", c.changelog, version)
return nil, fmt.Errorf("%s: release %s has no date; write `## [<version>] - <date>`", changelogPath, version)
}
if section.body == "" {
return nil, fmt.Errorf("%s: release %s has no notes", c.changelog, version)
return nil, fmt.Errorf("%s: release %s has no notes", changelogPath, version)
}
if target, ok := relativeLink(section.body); ok {
return nil, fmt.Errorf("%s: release %s has a relative link %q; release-notes links must be absolute", c.changelog, version, target)
return nil, fmt.Errorf("%s: release %s has a relative link %q; release-notes links must be absolute", changelogPath, version, target)
}
releases = append(releases, release{
Component: c.key,
Name: c.name,
Version: version,
Date: date,
Body: section.body,
Version: version,
Date: date,
Body: section.body,
})
}
return releases, nil
@@ -145,31 +132,19 @@ func relativeLink(body string) (string, bool) {
return "", false
}
// sortReleases orders releases newest first, then by component, then by
// descending version. Every host renders this order, so the canonical artifact
// is also the ordering contract.
// sortReleases orders releases newest first, then by descending version. Every
// host renders this order, so the canonical artifact is also the ordering
// contract.
func sortReleases(releases []release) {
sort.SliceStable(releases, func(i, j int) bool {
a, b := releases[i], releases[j]
if a.Date != b.Date {
return a.Date > b.Date
}
if ai, bi := componentIndex(a.Component), componentIndex(b.Component); ai != bi {
return ai < bi
}
return compareVersions(a.Version, b.Version) > 0
})
}
func componentIndex(key string) int {
for i, c := range components {
if c.key == key {
return i
}
}
return len(components)
}
// compareVersions orders dotted versions by their numeric parts, so 1.9.10 is
// newer than 1.9.9. A version carrying a prerelease is older than the same
// version without one.
+16 -21
View File
@@ -5,11 +5,11 @@ import (
"testing"
)
const sampleChangelog = `# archied changelog
const sampleChangelog = `# Changelog
## [1.31.0] - 2026-09-22
### A heading
### archied — A heading
- one bullet
@@ -27,7 +27,7 @@ Not a release section.
`
func TestParseChangelogReadsReleaseSections(t *testing.T) {
got, err := parseChangelog(components[0], sampleChangelog)
got, err := parseChangelog(sampleChangelog)
if err != nil {
t.Fatalf("parseChangelog error = %v", err)
}
@@ -35,13 +35,10 @@ func TestParseChangelogReadsReleaseSections(t *testing.T) {
t.Fatalf("got %d releases, want 2: %+v", len(got), got)
}
first := got[0]
if first.Component != "archied" || first.Name != "archied" {
t.Fatalf("first release component/name = %q/%q, want archied/archied", first.Component, first.Name)
}
if first.Version != "1.31.0" || first.Date != "2026-09-22" {
t.Fatalf("first release version/date = %q/%q", first.Version, first.Date)
}
if first.Body != "### A heading\n\n- one bullet" {
if first.Body != "### archied — A heading\n\n- one bullet" {
t.Fatalf("first release body = %q", first.Body)
}
if got[1].Version != "1.30.0" || got[1].Body != "Just prose." {
@@ -50,7 +47,7 @@ func TestParseChangelogReadsReleaseSections(t *testing.T) {
}
func TestParseChangelogSkipsUnreleased(t *testing.T) {
got, err := parseChangelog(components[0], sampleChangelog)
got, err := parseChangelog(sampleChangelog)
if err != nil {
t.Fatalf("parseChangelog error = %v", err)
}
@@ -95,7 +92,7 @@ func TestParseChangelogRejectsMalformedInput(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, err := parseChangelog(components[0], tt.source)
_, err := parseChangelog(tt.source)
if err == nil {
t.Fatal("expected an error")
}
@@ -112,14 +109,14 @@ func TestParseChangelogAllowsAbsoluteLinks(t *testing.T) {
- [vulnerability](https://pkg.go.dev/vuln/GO-2026-6443), [anchor](#section),
[root](/absolute), [angle](<https://example.com>), [mail](mailto:a@b.c).
`
if _, err := parseChangelog(components[0], source); err != nil {
if _, err := parseChangelog(source); err != nil {
t.Fatalf("parseChangelog error = %v", err)
}
}
func TestParseChangelogKeepsFencedHeadingsInTheBody(t *testing.T) {
source := "## [1.2.0] - 2026-01-01\n\n```sh\n## not a heading\n```\n\n- after the fence\n"
got, err := parseChangelog(components[0], source)
got, err := parseChangelog(source)
if err != nil {
t.Fatalf("parseChangelog error = %v", err)
}
@@ -151,20 +148,18 @@ func TestCompareVersions(t *testing.T) {
}
}
func TestSortReleasesNewestFirstThenComponentThenVersion(t *testing.T) {
func TestSortReleasesNewestFirstThenVersion(t *testing.T) {
releases := []release{
{Component: "archie", Name: "archie-agent", Version: "1.31.0", Date: "2026-09-22"},
{Component: "archied", Name: "archied", Version: "1.9.9", Date: "2026-09-22"},
{Component: "archied", Name: "archied", Version: "1.30.0", Date: "2026-09-20"},
{Component: "archied", Name: "archied", Version: "1.9.10", Date: "2026-09-22"},
{Component: "archied", Name: "archied", Version: "1.31.0", Date: "2026-09-22"},
{Version: "1.9.9", Date: "2026-09-22"},
{Version: "1.30.0", Date: "2026-09-20"},
{Version: "1.9.10", Date: "2026-09-22"},
{Version: "1.31.0", Date: "2026-09-22"},
}
sortReleases(releases)
want := []string{"archied/1.31.0", "archied/1.9.10", "archied/1.9.9", "archie/1.31.0", "archied/1.30.0"}
want := []string{"1.31.0", "1.9.10", "1.9.9", "1.30.0"}
for i, w := range want {
got := releases[i].Component + "/" + releases[i].Version
if got != w {
t.Fatalf("position %d = %s, want %s (all: %+v)", i, got, w, releases)
if releases[i].Version != w {
t.Fatalf("position %d = %s, want %s (all: %+v)", i, releases[i].Version, w, releases)
}
}
}
+55 -48
View File
@@ -1,17 +1,16 @@
// Command newsgen derives every published release fact from the component
// changelogs.
// Command newsgen derives every published release fact from CHANGELOG.md.
//
// CHANGELOG.archied.md and CHANGELOG.archie.md are the release process's frozen
// notes: tools/release.sh --prepare writes a section, the maintainer edits it,
// and --tag refuses to tag a version without its section. Tags are deliberately
// not a source, because CI and deployment check out shallow and a site build has
// no tags to read.
// CHANGELOG.md is the release process's frozen notes: tools/release.sh
// --prepare writes a section, the maintainer edits it, and --tag refuses to tag
// a version without its section. Tags are deliberately not a source, because CI
// and deployment check out shallow and a site build has no tags to read.
//
// Output is generated and committed:
//
// docs/data/generated/releases.json the canonical, host-neutral fact set
// docs/news/index.md the news page
// docs/news/<component>/<version>.md one page per release
// docs/news/releases.json the canonical, host-neutral fact set
// docs/news/redirects.json the retired per-component URLs, mapped to pages
// docs/news/index.md the news page
// docs/news/<version>.md one page per release
//
// `newsgen check` reproduces the output in memory and fails when the committed
// files differ, which keeps a changelog edit from landing without its pages.
@@ -29,6 +28,7 @@ import (
"log"
"os"
"path/filepath"
"regexp"
"sort"
"strings"
)
@@ -83,19 +83,15 @@ func parseOptions(args []string) (options, error) {
return options{mode: selected, repoRoot: *repoRoot}, nil
}
// load parses every component changelog and returns the releases newest first.
// load parses the changelog and returns the releases newest first.
func load(repoRoot string) ([]release, error) {
releases := []release{}
for _, c := range components {
source, err := os.ReadFile(filepath.Join(repoRoot, c.changelog))
if err != nil {
return nil, fmt.Errorf("read %s: %w", c.changelog, err)
}
parsed, err := parseChangelog(c, string(source))
if err != nil {
return nil, err
}
releases = append(releases, parsed...)
source, err := os.ReadFile(filepath.Join(repoRoot, changelogPath))
if err != nil {
return nil, fmt.Errorf("read %s: %w", changelogPath, err)
}
releases, err := parseChangelog(string(source))
if err != nil {
return nil, err
}
sortReleases(releases)
return releases, nil
@@ -156,7 +152,7 @@ func check(repoRoot string) error {
return fmt.Errorf("read %s: %w", path, err)
}
if !bytes.Equal(current, expected) {
problems = append(problems, path+" does not match the changelogs")
problems = append(problems, path+" does not match the changelog")
}
}
for _, path := range unownedPages(repoRoot, files) {
@@ -167,37 +163,48 @@ func check(repoRoot string) error {
return fmt.Errorf("release notes are stale:\n %s\n fix with `task news`, then commit the result",
strings.Join(problems, "\n "))
}
fmt.Printf("newsgen: %d release notes match the changelogs\n", len(releases))
fmt.Printf("newsgen: %d release notes match the changelog\n", len(releases))
return nil
}
// unownedPages lists files inside a generated component directory that this
// tool does not produce. The news directory's own root is not a generated
// directory, so a hand-written announcement there is left alone.
// releasePageName matches the basename of a generated version page, so a page
// left behind for a release the changelog no longer carries is reported.
var releasePageName = regexp.MustCompile(`^[0-9]+\.[0-9]+`)
// unownedPages lists files under docs/news that this tool does not produce. A
// page from the retired per-component layout (a file in a subdirectory) and a
// stale version page are both unowned; anything else is a hand-written news
// item, and the news directory's root is where those live.
func unownedPages(repoRoot string, files map[string][]byte) []string {
var unowned []string
for _, c := range components {
dir := filepath.Join(repoRoot, newsDir, c.key)
err := filepath.WalkDir(dir, func(path string, entry fs.DirEntry, err error) error {
if err != nil {
return err
}
if entry.IsDir() {
return nil
}
relative, err := filepath.Rel(repoRoot, path)
if err != nil {
return err
}
slash := filepath.ToSlash(relative)
if _, generated := files[slash]; !generated {
unowned = append(unowned, slash)
}
return nil
})
if err != nil && !errors.Is(err, fs.ErrNotExist) {
unowned = append(unowned, fmt.Sprintf("%s is unreadable: %v", c.key, err))
root := filepath.Join(repoRoot, newsDir)
err := filepath.WalkDir(root, func(path string, entry fs.DirEntry, err error) error {
if err != nil {
return err
}
if entry.IsDir() {
return nil
}
relative, err := filepath.Rel(repoRoot, path)
if err != nil {
return err
}
slash := filepath.ToSlash(relative)
if _, generated := files[slash]; generated {
return nil
}
if strings.Contains(slash[len(newsDir)+1:], "/") || looksLikeReleasePage(filepath.Base(path)) {
unowned = append(unowned, slash)
}
return nil
})
if err != nil && !errors.Is(err, fs.ErrNotExist) {
unowned = append(unowned, fmt.Sprintf("%s is unreadable: %v", newsDir, err))
}
return unowned
}
func looksLikeReleasePage(name string) bool {
base, ok := strings.CutSuffix(name, ".md")
return ok && releasePageName.MatchString(base)
}
+53 -38
View File
@@ -7,29 +7,19 @@ import (
"testing"
)
const archiedFixture = `# archied changelog
const changelogFixture = `# Changelog
## [1.31.0] - 2026-09-22
### archied — Gateway
- gateway bullet
`
const archieFixture = `# archie-agent changelog
## [1.31.0] - 2026-09-22
- runtime bullet
`
func writeChangelogs(t *testing.T, root, archied, archie string) {
func writeChangelog(t *testing.T, root, body string) {
t.Helper()
for name, body := range map[string]string{
"CHANGELOG.archied.md": archied,
"CHANGELOG.archie.md": archie,
} {
if err := os.WriteFile(filepath.Join(root, name), []byte(body), 0o644); err != nil {
t.Fatalf("write %s: %v", name, err)
}
if err := os.WriteFile(filepath.Join(root, changelogPath), []byte(body), 0o644); err != nil {
t.Fatalf("write %s: %v", changelogPath, err)
}
}
@@ -44,7 +34,7 @@ func readFile(t *testing.T, root, name string) []byte {
func TestWriteThenCheckIsClean(t *testing.T) {
root := t.TempDir()
writeChangelogs(t, root, archiedFixture, archieFixture)
writeChangelog(t, root, changelogFixture)
if err := write(root); err != nil {
t.Fatalf("write error = %v", err)
@@ -56,7 +46,7 @@ func TestWriteThenCheckIsClean(t *testing.T) {
func TestWriteIsIdempotent(t *testing.T) {
root := t.TempDir()
writeChangelogs(t, root, archiedFixture, archieFixture)
writeChangelog(t, root, changelogFixture)
if err := write(root); err != nil {
t.Fatalf("first write error = %v", err)
@@ -72,48 +62,72 @@ func TestWriteIsIdempotent(t *testing.T) {
func TestCheckReportsAStaleChangelog(t *testing.T) {
root := t.TempDir()
writeChangelogs(t, root, archiedFixture, archieFixture)
writeChangelog(t, root, changelogFixture)
if err := write(root); err != nil {
t.Fatalf("write error = %v", err)
}
writeChangelogs(t, root, archiedFixture+"\n## [1.32.0] - 2026-09-23\n\n- newer bullet\n", archieFixture)
writeChangelog(t, root, changelogFixture+"\n## [1.32.0] - 2026-09-23\n\n- newer bullet\n")
err := check(root)
if err == nil {
t.Fatal("check accepted a committed tree that lags the changelog")
}
for _, want := range []string{"task news", "docs/news/archied/1.32.0.md"} {
for _, want := range []string{"task news", "docs/news/1.32.0.md"} {
if !strings.Contains(err.Error(), want) {
t.Fatalf("error = %q, want it to mention %q", err, want)
}
}
}
func TestCheckReportsFilesItDoesNotOwn(t *testing.T) {
func TestCheckReportsAStaleVersionPage(t *testing.T) {
root := t.TempDir()
writeChangelogs(t, root, archiedFixture, archieFixture)
writeChangelog(t, root, changelogFixture)
if err := write(root); err != nil {
t.Fatalf("write error = %v", err)
}
handwritten := filepath.Join(root, "docs", "news", "archied", "handwritten.md")
if err := os.WriteFile(handwritten, []byte("mine\n"), 0o644); err != nil {
t.Fatalf("write handwritten page: %v", err)
stale := filepath.Join(root, "docs", "news", "9.9.9.md")
if err := os.WriteFile(stale, []byte("gone from the changelog\n"), 0o644); err != nil {
t.Fatalf("write stale page: %v", err)
}
err := check(root)
if err == nil {
t.Fatal("check ignored a file in a generated directory")
t.Fatal("check ignored a page for a version the changelog does not carry")
}
if !strings.Contains(err.Error(), "handwritten.md") || !strings.Contains(err.Error(), "not generated") {
t.Fatalf("error = %q, want it to name the unmanaged page", err)
if !strings.Contains(err.Error(), "9.9.9.md") || !strings.Contains(err.Error(), "not generated") {
t.Fatalf("error = %q, want it to name the stale page", err)
}
}
func TestCheckReportsTheRetiredComponentLayout(t *testing.T) {
root := t.TempDir()
writeChangelog(t, root, changelogFixture)
if err := write(root); err != nil {
t.Fatalf("write error = %v", err)
}
retired := filepath.Join(root, "docs", "news", "archied", "1.31.0.md")
if err := os.MkdirAll(filepath.Dir(retired), 0o755); err != nil {
t.Fatalf("create retired directory: %v", err)
}
if err := os.WriteFile(retired, []byte("old layout\n"), 0o644); err != nil {
t.Fatalf("write retired page: %v", err)
}
err := check(root)
if err == nil {
t.Fatal("check ignored a page left in the retired per-component layout")
}
if !strings.Contains(err.Error(), "archied/1.31.0.md") {
t.Fatalf("error = %q, want it to name the retired page", err)
}
}
func TestWriteLeavesOtherNewsFilesAlone(t *testing.T) {
root := t.TempDir()
writeChangelogs(t, root, archiedFixture, archieFixture)
writeChangelog(t, root, changelogFixture)
if err := write(root); err != nil {
t.Fatalf("write error = %v", err)
}
@@ -133,21 +147,22 @@ func TestWriteLeavesOtherNewsFilesAlone(t *testing.T) {
}
}
func TestRealChangelogsParse(t *testing.T) {
func TestRealChangelogParses(t *testing.T) {
releases, err := load(filepath.Join("..", ".."))
if err != nil {
t.Fatalf("load real changelogs: %v", err)
t.Fatalf("load the real changelog: %v", err)
}
seen := map[string]int{}
if len(releases) == 0 {
t.Fatal("the real changelog produced no releases")
}
seen := map[string]bool{}
for _, r := range releases {
seen[r.Component]++
if r.Version == "" || r.Date == "" || r.Body == "" {
t.Fatalf("incomplete release: %+v", r)
}
}
for _, c := range components {
if seen[c.key] == 0 {
t.Fatalf("%s produced no releases", c.changelog)
if seen[r.Version] {
t.Fatalf("version %s appears twice in the merged history", r.Version)
}
seen[r.Version] = true
}
}
+41 -8
View File
@@ -12,9 +12,21 @@ import (
// owns end-to-end, so it cannot collide with another generator's output.
const releasesJSONPath = "docs/news/releases.json"
// redirectsJSONPath is the redirect table. The per-component pages were retired,
// so every `/news/<component>/<version>/` URL published before the merge is
// mapped to the unified page for that version. It is generated beside the pages
// for the same reason they are: a hand-kept list would drift from them.
const redirectsJSONPath = "docs/news/redirects.json"
// newsDir is where the MkDocs adapter writes the news index and its pages.
const newsDir = "docs/news"
// legacyComponentDirs are the URL namespaces the per-component pages used. Both
// are mapped for every version rather than only the component that released it,
// so a published URL resolves whether or not that component ever carried that
// version, and the table is derived from the version set instead of a list.
var legacyComponentDirs = []string{"archied", "archie"}
// render returns every generated file keyed by repo-relative path. It is pure:
// the same releases always produce the same bytes, so the write path can skip a
// file that is already current.
@@ -26,12 +38,17 @@ func render(releases []release) (map[string][]byte, error) {
if err != nil {
return nil, err
}
redirects, err := encodeRedirects(releases)
if err != nil {
return nil, err
}
files := map[string][]byte{
releasesJSONPath: canonical,
redirectsJSONPath: redirects,
newsDir + "/index.md": renderIndex(releases),
}
for _, r := range releases {
files[fmt.Sprintf("%s/%s/%s.md", newsDir, r.Component, r.Version)] = renderRelease(r)
files[fmt.Sprintf("%s/%s.md", newsDir, r.Version)] = renderRelease(r)
}
return files, nil
}
@@ -40,12 +57,28 @@ func render(releases []release) (map[string][]byte, error) {
// the artifact stays readable to a reviewer and to a non-Go consumer: the
// changelogs write `->` and `<memory>`, not `\u003e` and `\u003cmemory\u003e`.
func encodeCanonical(releases []release) ([]byte, error) {
return encodeJSON(releasesJSONPath, releases)
}
// encodeRedirects writes the old-URL to new-URL table. encoding/json orders map
// keys, so the artifact is deterministic.
func encodeRedirects(releases []release) ([]byte, error) {
table := map[string]string{}
for _, r := range releases {
for _, component := range legacyComponentDirs {
table[fmt.Sprintf("/news/%s/%s/", component, r.Version)] = fmt.Sprintf("/news/%s/", r.Version)
}
}
return encodeJSON(redirectsJSONPath, table)
}
func encodeJSON(path string, value any) ([]byte, error) {
var buf bytes.Buffer
encoder := json.NewEncoder(&buf)
encoder.SetEscapeHTML(false)
encoder.SetIndent("", " ")
if err := encoder.Encode(releases); err != nil {
return nil, fmt.Errorf("encode %s: %w", releasesJSONPath, err)
if err := encoder.Encode(value); err != nil {
return nil, fmt.Errorf("encode %s: %w", path, err)
}
return buf.Bytes(), nil
}
@@ -54,24 +87,24 @@ func encodeCanonical(releases []release) ([]byte, error) {
func renderIndex(releases []release) []byte {
var b strings.Builder
b.WriteString("# News\n\n")
b.WriteString("Release notes for archied and archie-agent, newest first.\n")
b.WriteString("Release notes, newest first.\n")
lastDate := ""
for _, r := range releases {
if r.Date != lastDate {
fmt.Fprintf(&b, "\n## %s\n\n", r.Date)
lastDate = r.Date
}
fmt.Fprintf(&b, "- [%s %s](%s/%s.md)\n", r.Name, r.Version, r.Component, r.Version)
fmt.Fprintf(&b, "- [%s](%s.md)\n", r.Version, r.Version)
}
return []byte(b.String())
}
// renderRelease is one version's page: the facts, and the changelog body
// verbatim.
// verbatim, which carries that release's per-component sections.
func renderRelease(r release) []byte {
var b strings.Builder
fmt.Fprintf(&b, "# %s %s\n\n", r.Name, r.Version)
fmt.Fprintf(&b, "Released %s. [All news](../index.md)\n\n", r.Date)
fmt.Fprintf(&b, "# %s\n\n", r.Version)
fmt.Fprintf(&b, "Released %s. [All news](index.md)\n\n", r.Date)
b.WriteString(r.Body)
b.WriteString("\n")
return []byte(b.String())
+44 -16
View File
@@ -9,9 +9,8 @@ import (
func sampleReleases() []release {
return []release{
{Component: "archied", Name: "archied", Version: "1.31.0", Date: "2026-09-22", Body: "### Gateway\n\n- a bullet"},
{Component: "archie", Name: "archie-agent", Version: "1.31.0", Date: "2026-09-22", Body: "- a runtime bullet"},
{Component: "archied", Name: "archied", Version: "1.30.0", Date: "2026-09-20", Body: "Prose."},
{Version: "1.31.0", Date: "2026-09-22", Body: "### archied — Gateway\n\n- a bullet\n\n### archie-agent\n\n- a runtime bullet"},
{Version: "1.30.0", Date: "2026-09-20", Body: "Prose."},
}
}
@@ -35,7 +34,7 @@ func TestRenderEmitsTheCanonicalJSON(t *testing.T) {
func TestRenderJSONKeepsHTMLCharactersReadable(t *testing.T) {
releases := []release{{
Component: "archied", Name: "archied", Version: "1.0.0", Date: "2026-01-01",
Version: "1.0.0", Date: "2026-01-01",
Body: "a -> b and <memory>",
}}
files, err := render(releases)
@@ -50,16 +49,17 @@ func TestRenderJSONKeepsHTMLCharactersReadable(t *testing.T) {
}
}
func TestRenderWritesOnePagePerComponentVersion(t *testing.T) {
func TestRenderWritesOnePagePerVersion(t *testing.T) {
files, err := render(sampleReleases())
if err != nil {
t.Fatalf("render error = %v", err)
}
for _, path := range []string{
"docs/news/index.md",
"docs/news/archied/1.31.0.md",
"docs/news/archie/1.31.0.md",
"docs/news/archied/1.30.0.md",
"docs/news/1.31.0.md",
"docs/news/1.30.0.md",
"docs/news/releases.json",
"docs/news/redirects.json",
} {
if _, ok := files[path]; !ok {
t.Fatalf("render did not produce %s (files: %v)", path, keys(files))
@@ -70,6 +70,26 @@ func TestRenderWritesOnePagePerComponentVersion(t *testing.T) {
}
}
func TestRenderRedirectsEveryRetiredComponentURL(t *testing.T) {
files, err := render(sampleReleases())
if err != nil {
t.Fatalf("render error = %v", err)
}
var table map[string]string
if err := json.Unmarshal(files[redirectsJSONPath], &table); err != nil {
t.Fatalf("redirect table does not decode: %v", err)
}
want := map[string]string{
"/news/archied/1.31.0/": "/news/1.31.0/",
"/news/archie/1.31.0/": "/news/1.31.0/",
"/news/archied/1.30.0/": "/news/1.30.0/",
"/news/archie/1.30.0/": "/news/1.30.0/",
}
if !reflect.DeepEqual(table, want) {
t.Fatalf("redirect table = %v, want %v", table, want)
}
}
func TestRenderIndexGroupsByDate(t *testing.T) {
files, err := render(sampleReleases())
if err != nil {
@@ -77,16 +97,15 @@ func TestRenderIndexGroupsByDate(t *testing.T) {
}
want := `# News
Release notes for archied and archie-agent, newest first.
Release notes, newest first.
## 2026-09-22
- [archied 1.31.0](archied/1.31.0.md)
- [archie-agent 1.31.0](archie/1.31.0.md)
- [1.31.0](1.31.0.md)
## 2026-09-20
- [archied 1.30.0](archied/1.30.0.md)
- [1.30.0](1.30.0.md)
`
if got := string(files["docs/news/index.md"]); got != want {
t.Fatalf("index markdown =\n%s\nwant\n%s", got, want)
@@ -98,13 +117,19 @@ func TestRenderReleasePageKeepsTheBodyVerbatim(t *testing.T) {
if err != nil {
t.Fatalf("render error = %v", err)
}
want := `# archie-agent 1.31.0
want := `# 1.31.0
Released 2026-09-22. [All news](../index.md)
Released 2026-09-22. [All news](index.md)
### archied — Gateway
- a bullet
### archie-agent
- a runtime bullet
`
if got := string(files["docs/news/archie/1.31.0.md"]); got != want {
if got := string(files["docs/news/1.31.0.md"]); got != want {
t.Fatalf("release page =\n%s\nwant\n%s", got, want)
}
}
@@ -131,7 +156,10 @@ func TestRenderHandlesNoReleases(t *testing.T) {
if got := string(files[releasesJSONPath]); got != "[]\n" {
t.Fatalf("empty canonical JSON = %q, want %q", got, "[]\n")
}
if got := string(files["docs/news/index.md"]); got != "# News\n\nRelease notes for archied and archie-agent, newest first.\n" {
if got := string(files[redirectsJSONPath]); got != "{}\n" {
t.Fatalf("empty redirect table = %q, want %q", got, "{}\n")
}
if got := string(files["docs/news/index.md"]); got != "# News\n\nRelease notes, newest first.\n" {
t.Fatalf("empty index = %q", got)
}
}
+109 -131
View File
@@ -3,26 +3,25 @@
# they are frozen into a tag -- the same review window release-please gives
# you with its release PR.
#
# tools/release.sh --gateway 1.2.0 --runtime 1.2.0 --dry-run # preview
# tools/release.sh --gateway 1.2.0 --runtime 1.2.0 --prepare # write, then edit
# tools/release.sh --gateway 1.2.0 --runtime 1.2.0 --tag # commit + tag
# tools/release.sh --version 1.2.0 --dry-run # preview
# tools/release.sh --version 1.2.0 --prepare # write, then edit
# tools/release.sh --version 1.2.0 --tag # commit + tag
#
# archied and archie-agent are independently versioned (see CHANGELOG.md),
# so each gets its own version, tag and changelog. Pass "skip" for a
# component that is not moving this release.
# There is one release stream: CHANGELOG.md carries every release section,
# one generated page per version, and one tag names the release. A release is
# one version covering whatever changed; per-component detail is a labelled
# section inside it, not a separate number.
#
# Which commits land in which changelog is decided by the binary's actual
# package closure (go list -deps), not by guessing from the commit subject:
# a change to a package archied does not import cannot appear in archied's
# changelog. Commits touching neither closure (docs, CI, deployment) are
# left out of both.
# Exit codes: 0 released (or previewed/prepared); 1 failure; 3 nothing to
# release -- a commit set that justifies no version is a result, not an error,
# so a pipeline can finish green without tagging.
set -euo pipefail
cd "$(dirname "$0")/.."
NOTHING_TO_RELEASE=3
MODE=""
GATEWAY_VERSION=""
RUNTIME_VERSION=""
VERSION=""
die() {
echo "release: $*" >&2
@@ -31,8 +30,7 @@ die() {
while [ $# -gt 0 ]; do
case "$1" in
--gateway) GATEWAY_VERSION="${2:-}"; shift 2 ;;
--runtime) RUNTIME_VERSION="${2:-}"; shift 2 ;;
--version) VERSION="${2:-}"; shift 2 ;;
--dry-run) MODE="dry-run"; shift ;;
--prepare) MODE="prepare"; shift ;;
--tag) MODE="tag"; shift ;;
@@ -40,8 +38,7 @@ while [ $# -gt 0 ]; do
esac
done
[ -n "$GATEWAY_VERSION" ] || die "--gateway <version|skip> is required"
[ -n "$RUNTIME_VERSION" ] || die "--runtime <version|skip> is required"
[ -n "$VERSION" ] || die "--version <version> is required"
[ -n "$MODE" ] || die "one of --dry-run, --prepare or --tag is required"
if [ "$MODE" != "dry-run" ]; then
@@ -60,36 +57,6 @@ component_dirs() {
sed "s|^$PWD/||"
}
# section <tag-prefix> <cmd-path> <extra-path>... -- changelog body for the
# commits since <tag-prefix>'s last tag that touched this component.
section() {
local prefix="$1" cmd="$2"
shift 2
local last range dirs
last="$(git tag --list "$prefix/v*" | sort -V | tail -1)"
range="HEAD"
if [ -n "$last" ]; then
range="$last..HEAD"
fi
dirs="$(component_dirs "$cmd")"$'\n'"$(printf '%s\n' "$@")"
local sha subject files
while read -r sha; do
[ -n "$sha" ] || continue
subject="$(git log -1 --pretty=%s "$sha")"
# Conventional commits only; release commits are not news.
case "$subject" in
feat:* | feat\(*|fix:* | fix\(*|perf:* | perf\(*|refactor:* | refactor\(*) ;;
*) continue ;;
esac
files="$(git show --pretty=format: --name-only "$sha")"
if matches "$files" "$dirs"; then
echo "- $subject"
fi
done < <(git log --no-merges --pretty=%H --reverse "$range")
}
# matches <changed-files> <dirs> -- true when any changed file lives in one
# of the component's directories.
matches() {
@@ -107,71 +74,95 @@ matches() {
return 1
}
# prepend <changelog> <version> <body> -- insert a dated section directly
# under the file's title.
# The host bundle IS the archied artifact: the distribution zip is named and
# versioned by the release, and every process it ships carries that version.
# The paths below are named rather than whole directories, so a packaging-only
# change is attributed to archied deliberately and not every CI or script edit.
archied_dirs() {
component_dirs ./cmd/archied
printf '%s\n' "cmd/archied" "Dockerfile.archied" "cmd/archie-ui" "internal/app/archieui" \
"Taskfile.yml" ".github/workflows/deploy.yml" "install.sh" \
"scripts/archie-update-install" "scripts/archie-update-check" \
"scripts/archie-update-watchdog" "deployments/INSTRUCTIONS.md"
}
# The UI Service ships with the archied release on purpose (archie-ui shares
# internal/webui with archied), hence archied_dirs' extra paths above.
runtime_dirs() {
component_dirs ./cmd/archie-agent
printf '%s\n' "cmd/archie-agent" "Dockerfile"
}
# changelog_body -- labelled per-component sections for every releasable commit
# since the last release. Empty output means nothing to release: a commit set
# that justifies no version produces no body, and the caller reports that
# rather than inventing one.
changelog_body() {
local last range archied runtime
last="$(git describe --tags --abbrev=0 2>/dev/null || true)"
range="HEAD"
if [ -n "$last" ]; then
range="$last..HEAD"
fi
archied="$(archied_dirs)"
runtime="$(runtime_dirs)"
local sha subject files in_archied="" in_runtime=""
while read -r sha; do
[ -n "$sha" ] || continue
subject="$(git log -1 --pretty=%s "$sha")"
# Conventional commits only; release commits are not news.
case "$subject" in
feat:* | feat\(*|fix:* | fix\(*|perf:* | perf\(*|refactor:* | refactor\(*) ;;
*) continue ;;
esac
files="$(git show --pretty=format: --name-only "$sha")"
if matches "$files" "$archied"; then
in_archied="$in_archied- $subject"$'\n'
fi
if matches "$files" "$runtime"; then
in_runtime="$in_runtime- $subject"$'\n'
fi
done < <(git log --no-merges --pretty=%H --reverse "$range")
if [ -n "$in_archied" ]; then
printf '### archied\n\n%s\n' "$in_archied"
fi
if [ -n "$in_runtime" ]; then
printf '### archie-agent\n\n%s\n' "$in_runtime"
fi
}
# prepend <version> <body-file> -- insert the new section after the title and
# any [Unreleased] block, which stays at the top, and above every release.
prepend() {
local file="$1" version="$2" body="$3" tmp
local version="$1" bodyfile="$2" tmp line
line="$(grep -n '^## \[' CHANGELOG.md | grep -v '## \[Unreleased\]' | head -1 | cut -d: -f1)"
if [ -z "$line" ]; then
line="$(($(wc -l <CHANGELOG.md) + 1))"
fi
tmp="$(mktemp)"
{
head -1 "$file"
echo
head -n "$((line - 1))" CHANGELOG.md
echo "## [$version] - $(date +%F)"
echo
echo "$body"
tail -n +2 "$file"
cat "$bodyfile"
echo
tail -n "+$line" CHANGELOG.md
} >"$tmp"
# Collapse the blank-line run left where the old body started.
awk 'BEGIN{blank=0} /^$/{blank++; if(blank>1) next} !/^$/{blank=0} {print}' "$tmp" >"$file"
rm -f "$tmp"
mv "$tmp" CHANGELOG.md
}
release_component() {
local name="$1" version="$2" prefix="$3" changelog="$4" cmd="$5"
shift 5
if [ "$version" = "skip" ]; then
echo "==> $name: skipped"
return
fi
local body
body="$(section "$prefix" "$cmd" "$@")"
if [ -z "$body" ]; then
body="- chore: no user-facing changes"
fi
echo "==> $name $version ($prefix/v$version)"
echo "$body" | sed 's/^/ /'
if [ "$MODE" = "prepare" ]; then
prepend "$changelog" "$version" "$body"
fi
}
body="$(changelog_body)"
# The host bundle IS the archied artifact: the distribution zip is named and
# versioned by the archied tag, and every process it ships carries that same
# version. So the inputs that decide what a host install contains belong in
# archied's closure -- the build task, the packaging workflow, the installer,
# the updater scripts it ships, and the instructions packed into the zip.
# Without them a change to packaging or the installer closes over no
# component at all, so the standing rule says "skip both" and the fix cannot
# be released by the mechanism it repairs (archie-core-12rp). Each path is
# named rather than its whole directory, so a packaging-only change is
# attributed to archied deliberately and not every CI or script edit is.
release_component "archied" "$GATEWAY_VERSION" "archied" \
"CHANGELOG.archied.md" "./cmd/archied" "cmd/archied" "Dockerfile.archied" \
"cmd/archie-ui" "internal/app/archieui" \
"Taskfile.yml" ".github/workflows/deploy.yml" "install.sh" \
"scripts/archie-update-install" "scripts/archie-update-check" \
"scripts/archie-update-watchdog" "deployments/INSTRUCTIONS.md"
if [ -z "$body" ]; then
last="$(git describe --tags --abbrev=0 2>/dev/null || echo 'the beginning')"
echo "nothing to release: no releasable commits since $last" >&2
exit "$NOTHING_TO_RELEASE"
fi
# The UI Service ships with the archied release on purpose: archie-ui shares
# internal/webui (the dashboard HTTP layer and the embedded SPA assets) with
# archied, so the two are versioned together -- an archied/vX.Y.Z tag carries
# the dashboard and the daemon that publishes its configuration snapshot.
# The two lines above extend archied's component closure with archie-ui's
# own packages, so a commit touching only archieui cannot fall between
# changelogs; it would otherwise land in neither (go list -deps from
# ./cmd/archied does not include internal/app/archieui).
release_component "archie-agent" "$RUNTIME_VERSION" "archie" \
"CHANGELOG.archie.md" "./cmd/archie-agent" "cmd/archie-agent" "Dockerfile"
echo "==> release $VERSION"
echo "$body" | sed 's/^/ /'
if [ "$MODE" = "dry-run" ]; then
echo
@@ -179,50 +170,37 @@ if [ "$MODE" = "dry-run" ]; then
exit 0
fi
bodyfile="$(mktemp)"
printf '%s\n' "$body" >"$bodyfile"
if [ "$MODE" = "prepare" ]; then
prepend "$VERSION" "$bodyfile"
rm -f "$bodyfile"
echo
echo "changelogs updated and left uncommitted. Edit them -- generated notes"
echo "are a starting point, not the release -- then freeze them with:"
echo "CHANGELOG.md updated and left uncommitted. Edit it -- generated notes"
echo "are a starting point, not the release -- then freeze it with:"
echo
echo " tools/release.sh --gateway $GATEWAY_VERSION --runtime $RUNTIME_VERSION --tag"
echo " tools/release.sh --version $VERSION --tag"
exit 0
fi
# --tag: the changelog must already describe this release.
[ "$GATEWAY_VERSION" = "skip" ] || grep -q "^## \\[$GATEWAY_VERSION\\]" CHANGELOG.archied.md ||
die "CHANGELOG.archied.md has no [$GATEWAY_VERSION] section; run --prepare first"
[ "$RUNTIME_VERSION" = "skip" ] || grep -q "^## \\[$RUNTIME_VERSION\\]" CHANGELOG.archie.md ||
die "CHANGELOG.archie.md has no [$RUNTIME_VERSION] section; run --prepare first"
grep -q "^## \\[$VERSION\\]" CHANGELOG.md ||
die "CHANGELOG.md has no [$VERSION] section; run --prepare first"
# The published release notes are derived from the changelogs, so regenerate
# The published release notes are derived from the changelog, so regenerate
# them after the maintainer's edit and ship them in the same commit as the
# sections they describe. newsgen skips a file whose bytes already match, so a
# section they describe. newsgen skips a file whose bytes already match, so a
# re-run leaves the tree clean.
go -C tools run -mod=readonly ./newsgen --repo-root ..
# Plain `[ cond ] && cmd` would abort the script under set -e whenever cond
# is false, i.e. whenever a component is skipped.
msg="chore(release):"
if [ "$GATEWAY_VERSION" != "skip" ]; then
msg="$msg archied v$GATEWAY_VERSION"
fi
if [ "$RUNTIME_VERSION" != "skip" ]; then
msg="$msg archie v$RUNTIME_VERSION"
fi
git add CHANGELOG.archied.md CHANGELOG.archie.md docs/news
git commit -m "$msg"
if [ "$GATEWAY_VERSION" != "skip" ]; then
git tag -a "archied/v$GATEWAY_VERSION" -m "archied v$GATEWAY_VERSION"
fi
if [ "$RUNTIME_VERSION" != "skip" ]; then
git tag -a "archie/v$RUNTIME_VERSION" -m "archie-agent v$RUNTIME_VERSION"
fi
git add CHANGELOG.md docs/news
git commit -m "chore(release): v$VERSION"
git tag -a "v$VERSION" -m "v$VERSION"
echo
echo "tagged. push with:"
echo " git push origin main --follow-tags"
echo
echo "The deploy workflow reads the tags pointing at HEAD, so pushing the"
echo "commit without its tags builds images stamped 'dev'."
echo "commit without its tag builds images stamped 'dev'."